diff --git a/.github/security-audit-requirements.txt b/.github/security-audit-requirements.txt index a9f5822580..5546508cf0 100644 --- a/.github/security-audit-requirements.txt +++ b/.github/security-audit-requirements.txt @@ -279,7 +279,3 @@ typer==0.27.0 \ --hash=sha256:629bd12ea5d13a17148125d9a264f949eb171fb3f120f9b04d85873cab054fa5 \ --hash=sha256:6f4b27631e47f077871b7dc30e933ec0131c1390fbe0e387ea5574b5bac9ccf1 # via agentic-sdlc-specify-cli (pyproject.toml) -typing-extensions==4.16.0 ; python_full_version < '3.13' \ - --hash=sha256:481caa481374e813c1b176ada14e97f1f67a4539ce9cfeb3f350d78d6370c2e8 \ - --hash=sha256:dc983d19a509c94dba722ee6abd33940f7c05a89e243c47e907eb4db6f1a43e5 - # via anyio diff --git a/AGENTS.md b/AGENTS.md index 03ccd56331..7ab56a8edc 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -284,7 +284,22 @@ cd my-project && specify integration uninstall - Reduces the chance of bugs when adding new agents - Tool checking "just works" without additional mappings -#### 7. Update Devcontainer files (Optional) +### 6. Optional overrides + +The base classes handle most work automatically. Override only when the agent deviates from standard patterns: + +| Override | When to use | Example | +|---|---|---| +| `command_filename(template_name)` | Custom file naming or extension | Copilot → `speckit.{name}.agent.md` | +| `options()` | Integration-specific CLI flags via `--integration-options` | Codex → `--skills` flag, Copilot → `--commands` flag | +| `setup()` | Custom install logic (companion files, settings merge) | Copilot → `speckit-/SKILL.md` (default) or `.agent.md` + `.prompt.md` + `.vscode/settings.json` (`--commands`) | +| `teardown()` | Custom uninstall logic | Rarely needed; base handles manifest-tracked files | + +**Example — Copilot (fully custom `setup`):** + +Copilot extends `IntegrationBase` directly because it supports two layouts. It scaffolds `speckit-/SKILL.md` under `.github/skills/` by default using composition with an internal `_CopilotSkillsHelper`. Its `--commands` mode creates `.agent.md` commands, companion `.prompt.md` files, and merges `.vscode/settings.json`. See `src/specify_cli/integrations/copilot/__init__.py` for the full implementation. + +### 7. Update Devcontainer files (Optional) For agents that have VS Code extensions or require CLI installation, update the devcontainer configuration files: @@ -499,36 +514,28 @@ Some agents require custom processing beyond the standard template transformatio ### Copilot Integration -GitHub Copilot has unique requirements: +GitHub Copilot uses skills by default, scaffolded as +`speckit-/SKILL.md` under `.github/skills/`. -- Commands use `.agent.md` extension (not `.md`) -- Each command gets a companion `.prompt.md` file in `.github/prompts/` -- Installs `.vscode/settings.json` with prompt file recommendations -- Context file lives at `.github/copilot-instructions.md` - -Implementation: Extends `IntegrationBase` with custom `setup()` method that: - -1. Processes templates with `process_template()` -2. Generates companion `.prompt.md` files -3. Merges VS Code settings +**Commands mode (`--commands`):** Copilot also supports a commands-based layout +via `--integration-options="--commands"`. When enabled: -**Skills mode (`--skills`):** Copilot also supports an alternative skills-based layout -via `--integration-options="--skills"`. When enabled: +- Commands use `.agent.md` extension under `.github/agents/` +- Each command gets a companion `.prompt.md` file in `.github/prompts/` +- `.vscode/settings.json` is merged with prompt file recommendations +- `build_command_invocation()` returns bare args for `--agent` dispatch -- Commands are scaffolded as `speckit-/SKILL.md` under `.github/skills/` -- No companion `.prompt.md` files are generated -- No `.vscode/settings.json` merge -- `post_process_skill_content()` injects a `mode: speckit.` frontmatter field -- `build_command_invocation()` returns `/speckit-` instead of bare args +In the default skills mode, no companion prompts or VS Code settings merge are +created, and `build_command_invocation()` returns `/speckit-`. The two modes are mutually exclusive — a project uses one or the other: ```bash -# Default mode: .agent.md agents + .prompt.md companions + settings merge +# Default skills mode: speckit-/SKILL.md under .github/skills/ specify init my-project --integration copilot -# Skills mode: speckit-/SKILL.md under .github/skills/ -specify init my-project --integration copilot --integration-options="--skills" +# Commands mode: .agent.md agents + .prompt.md companions + settings merge +specify init my-project --integration copilot --integration-options="--commands" ``` ### Forge Integration @@ -593,6 +600,11 @@ When an issue exists, include its number immediately after the prefix — this i Disclosure is **continuous**, not a one-time event. A single AI-disclosure paragraph in the PR body does **not** cover the commits and replies you add during review rounds. Each of the following must independently attest to agent authorship. +### Opening pull requests + +- Before opening a pull request, check whether the account that will file it already has three open pull requests in this repository. +- If so, alert the user that additional submissions may receive lower review priority and ask for explicit permission to proceed. Do not assume consent. + ### Commits - **Every commit you author must carry an `Assisted-by:` trailer** identifying the agent and whether it acted autonomously or under direct human supervision, for example: diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b2697ae06..be6520da12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,108 @@ All notable changes to the Specify CLI and templates are documented here. +# [0.15.2+adlc2] - 2026-08-05 + +### Added + +- **Upstream merge (13 commits, post-0.15.2)**: Synced with upstream + `github/spec-kit` main (`ab468c4d..03d71b33`). No new upstream release tag; + fork suffix incremented (`0.15.2+adlc1` → `0.15.2+adlc2`). New upstream + features adopted: + - `feat(copilot): default integration to skills` (#3976) — Copilot now + defaults to the skills layout (`speckit-/SKILL.md` under + `.github/skills/`); the commands layout (`.agent.md` + `.prompt.md` + + `.vscode/settings.json`) is opt-in via `--integration-options="--commands"`. + Fork adapted: `is_skills_mode()` checks both `spec-`/`speckit-` prefixes + (fork skills use `spec-*` when presets are active); + `build_command_invocation()` canonicalizes bare command names before alias + resolution; `resolve_command_alias` + `run_and_tee` + `_get_command_prefix()` + customizations re-applied onto upstream's rewritten module. + - `feat(events): context injection for opencode and JSON-envelope agent hooks` + (#3934, authored by fork maintainer upstream) — first-class context + injection for opencode session_start/user_prompt_submit via TS plugin, and + JSON-envelope wrapping for Gemini/Tabnine/Qwen/Devin/Copilot/Cursor hooks. + Auto-merged clean. +- Community catalog: TDD extension (#3982), Charter v0.5.1 (#3983), Archive + v1.1.0 (#3981). Note: fork has its own bundled `tdd` extension (separate + from the community catalog entry). + +### Fixed + +- Upstream fixes adopted (all auto-merged clean): non-UTF-8 preset registry + (#3955), non-UTF-8 `config.toml` on hook install/teardown (#3963), + unreadable staged backup treated as conflict (#3962), non-string + `requires.speckit_version` rejected (#3980), reinstall rejected when kept + config unreadable (#3960), `None` returned for unparseable script command + (#3957), migration hardening (validate target options before uninstall + in `_migrate_commands.py`). +- Fork fix: `build_command_invocation()` in copilot skills mode now + canonicalizes bare command names (e.g. `"plan"`) to `speckit.plan` before + alias resolution, so the invocation produces `/{prefix}-plan` instead of + `/plan` (which wouldn't match any installed skill). Also applied to + `_invoke_cli` for consistency in the non-streaming path. + +### Changed + +- 5 conflicts resolved: `AGENTS.md` (adopted upstream's new "Optional + overrides" section + "Opening pull requests" PR-prioritization subsection; + preserved fork header/SPECKIT markers), `copilot/__init__.py` (re-applied 4 + fork customizations onto upstream's #3976 rewrite + made `is_skills_mode()` + prefix-aware), `test_cli.py` (adapted skills-default assertions to fork + naming), `test_integration_copilot.py` (adapted `build_command_invocation` + tests to fork alias-aware naming), `test_integration_subcommand.py` + (adapted copilot switch/upgrade tests to fork naming). +- All semantic hotspots auto-merged cleanly: `events.py`, `extensions/__init__.py`, + `presets/__init__.py`, `base.py`, `_migrate_commands.py`, + `integration_runtime.py`. No `templates/` changes upstream → no preset + command porting needed. Ruff clean (`ruff@0.15.0`). + +# [0.15.2+adlc1] - 2026-08-04 + +### Added + +- **Upstream merge (0.15.1 → 0.15.2)**: Adopted upstream `github/spec-kit` + release `0.15.2` plus 3 post-release fixes. Package version base reset to + upstream `0.15.2` with fork counter reset (`0.15.1+adlc1` → `0.15.2+adlc1`). + Merged 14 commits since the last merge base `d1e86f63`. New upstream features: + - `feat(extensions): scaffold config templates on extension add/enable` + (#2000) — extensions declaring `provides.config` now auto-deploy their + config templates into `.specify/` on `extension add`/`enable`, preserving + existing files. Fork's bundled extensions (agent-context, git, …) declare + only `provides.commands`, so scaffolding is inert today; the + `agent-context` extension keeps its own `.template` + script self-seed + mechanism. + - `feat: allow overriding default init integration via + SPECKIT_INTEGRATION_DEFAULT` (#3952) — env-var picker for non-interactive + `specify init`, the workflow `init` step, and bundle init. + - `Add adrkit extension to community catalog` (#3947). +- **New upstream hardening**: `fix(presets): restore core skills instead of + deleting them on preset remove` (#3929, with `restore_from_bundled_core` + flag + extension-restore priority), `fix(manifests): reject non-string + metadata instead of crashing on it` (#3943), `fix: narrow bare except + Exception in invoke separator resolution` (#3856), `fix(workflows): keep + the init step's documented ignore_agent_tools default on an explicit null` + (#3889), `fix(workflows): reject mismatched run state IDs` (#3899), + `fix: cap stdin read at 1 MiB to prevent DoS` (#3857, `MAX_STDIN_BYTES` in + `event.py`), non-UTF-8 tolerance for events/presets/extension manifests and + event overrides (#3900, #3896, #3895, #3897), `fix(presets): validate + required manifest mappings` (#3898). + +### Changed + +- **No conflict-heavy work this round**: the merge auto-resolved every + semantic hotspot (`__init__.py`, `agents.py`, `extensions/__init__.py`, + `extensions/_commands.py`, `presets/__init__.py`, `commands/init.py`, + `commands/bundle/__init__.py`, `events.py`, `event.py`, `workflows/engine.py`, + `workflows/steps/init/__init__.py`, `_agent_config.py`) without manual + intervention. Only `pyproject.toml` required manual conflict resolution to + preserve fork package identity and reset the version. Fork modules + (`_init_fork`, `_core_fork`, `_assets_fork`, `_base_fork`, `_workflows_fork`, + `extensions_fork`) untouched. No `templates/` changes upstream this round → + no preset command porting needed. +- **Lint**: Ruff clean across `src/` and `tests/` with the pinned + `ruff@0.15.0`. + # [0.15.1+adlc1] - 2026-08-02 ### Added @@ -4153,6 +4255,31 @@ This release migrates fork-specific customizations to a preset system to reduce The following entries are from the upstream spec-kit project and are included for reference. +## [0.15.2] - 2026-08-03 + +### Changed + +- fix(presets): restore core skills instead of deleting them on preset remove (#3929) +- fix(manifests): reject non-string metadata instead of crashing on it (#3943) +- fix: narrow bare except Exception in invoke separator resolution (#3856) +- fix(workflows): keep the init step's documented ignore_agent_tools default on an explicit null (#3889) +- fix(kimi): preserve non-UTF-8 user skills (#3895) +- fix(presets): tolerate non-UTF-8 legacy commands (#3896) +- feat: allow overriding default init integration via SPECKIT_INTEGRATION_DEFAULT (#3952) +- Add adrkit extension to community catalog (#3947) +- feat(extensions): scaffold config templates on extension add/enable (#2000) +- fix(events): skip non-UTF-8 extension manifests (#3900) +- fix(workflows): fail a gate whose on_reject is not abort/skip/retry (#3888) +- fix(presets): validate required manifest mappings (#3898) +- fix: eliminate TOCTOU race in zip packaging (#3855) +- fix(workflows): fail a fan-in step whose output is not a mapping (#3887) +- fix(workflows): refetch non-UTF-8 catalog caches (#3901) +- fix(bundler): wrap local catalog decode failures (#3902) +- Add `--extension` flag to `specify init` for opting into extensions at init time (#3914) +- fix: bound response reads in extension catalog and download (#3775) +- fix(workflows): reject a retry gate whose verdict enum forbids the reset value (#3912) +- chore: release 0.15.1, begin 0.15.2.dev0 development (#3913) + ## [0.15.1] - 2026-07-31 ### Changed diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8dcc6c1533..3d1f2f229c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -55,6 +55,8 @@ Here are a few things you can do that will increase the likelihood of your pull - Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html). - Test your changes with the Spec-Driven Development workflow to ensure compatibility. +Accounts with three open pull requests may continue submitting changes, but additional submissions may be placed behind contributions from other authors in the review queue. Coding agents should disclose this possibility and obtain the filer's confirmation before opening another pull request. + ### Branch naming We recommend naming branches as `/-`, where `` is the issue or PR number (whichever comes first) and `` is one of: diff --git a/FORK.md b/FORK.md index 02a0e1cc5a..78a91f047b 100644 --- a/FORK.md +++ b/FORK.md @@ -72,6 +72,8 @@ When a fork release changes only bundled extension behavior, keep the CLI versio | Version | Date | Base Upstream | Changes | |---------|------|---------------|---------| +| 0.15.2+adlc2 | 2026-08-05 | 0.15.2 (`03d71b33`) | Upstream merge (13 commits, post-0.15.2, no new release tag). New upstream features: `feat(copilot): default integration to skills` (#3976 — Copilot defaults to skills layout, `--commands` opts back to `.agent.md`+`.prompt.md`; fork adapted `is_skills_mode()` to check both `spec-`/`speckit-` prefixes, re-applied 4 fork customizations onto upstream's rewritten module, fixed `build_command_invocation()` bare-name canonicalization); `feat(events): context injection for opencode and JSON-envelope agent hooks` (#3934, authored by fork maintainer upstream — auto-merged clean). Upstream fixes: non-UTF-8 preset registry (#3955), non-UTF-8 config.toml on hook install/teardown (#3963), unreadable staged backup as conflict (#3962), non-string requires.speckit_version (#3980), reinstall when kept config unreadable (#3960), None for unparseable script command (#3957), migration target-options validation. Community catalog: TDD extension (#3982 — fork has its own bundled tdd), Charter v0.5.1 (#3983), Archive v1.1.0 (#3981). **5 conflicts resolved**: `AGENTS.md` (adopted upstream's "Optional overrides" section + "Opening pull requests" PR-prioritization; preserved fork header/SPECKIT markers), `copilot/__init__.py` (re-applied fork customizations + prefix-aware `is_skills_mode()`), `test_cli.py` (skills-default assertions adapted to fork naming), `test_integration_copilot.py` (alias-aware `build_command_invocation` test assertions), `test_integration_subcommand.py` (copilot switch/upgrade tests adapted). All semantic hotspots (`events.py`, `extensions/__init__.py`, `presets/__init__.py`, `base.py`, `_migrate_commands.py`, `integration_runtime.py`) auto-merged cleanly; fork modules untouched. No `templates/` changes → no preset porting. Ruff clean (`ruff@0.15.0`). 1375+ tests pass across merge-affected files. | +| 0.15.2+adlc1 | 2026-08-04 | 0.15.2 (`ab468c4d`) | Upstream merge (14 commits since merge base `d1e86f63`, includes the 0.15.2 release + 3 post-release fixes: #3899, #3857, #3897). New upstream features: extension config-template scaffolding on `extension add`/`enable` (#2000, `provides.config` → `.specify/` — inert for fork's bundled extensions today which only declare `provides.commands`); `SPECKIT_INTEGRATION_DEFAULT` env-var picker for `specify init` / workflow init step / bundle init (#3952); adrkit community catalog entry (#3947). New upstream hardening: restore core skills (not delete) on preset remove via `restore_from_bundled_core` with extension-restore priority (#3929); reject non-string manifest metadata (#3943); narrow bare `except Exception` in invoke-separator resolution (#3856); workflow `ignore_agent_tools` explicit-null default (#3889); reject mismatched workflow run state IDs (#3899); cap stdin read at 1 MiB to prevent DoS (#3857, `MAX_STDIN_BYTES` in `event.py`); non-UTF-8 tolerance for events/presets/extension manifests/event overrides (#3900/#3896/#3895/#3897); validate required preset manifest mappings (#3898). **1 conflict resolved**: `pyproject.toml` (kept fork name/description, version → `0.15.2+adlc1`). All semantic hotspots (`__init__.py`, `agents.py`, `extensions/__init__.py`, `extensions/_commands.py`, `presets/__init__.py`, `commands/init.py`, `commands/bundle/__init__.py`, `events.py`, `event.py`, `workflows/engine.py`, `workflows/steps/init/__init__.py`, `_agent_config.py`) auto-merged cleanly; fork modules untouched. No `templates/` changes upstream → no preset command porting needed. Ruff clean (`ruff@0.15.0`). Tests deferred to CI. | | 0.15.1+adlc1 | 2026-08-02 | 0.15.1 (`7f40c829`) | Upstream merge (0.14.4 → 0.15.1) with fork version base reset to `0.15.1`. Adopted upstream `0.15.0`/`0.15.1` fixes: tar archive installs (#3874), opt-in `constitution-sync` preset (#3873), TOCTOU unlink races (#3819), `verdict_input` gate binding (#3725), workflow step-metadata escaping (#3863), non-object workflow cache rejection (#3860), non-UTF-8 manifest/VS Code settings normalization (#3862/#3833), .NET-safe PowerShell init-dir trim (#3872), Rich markup escaping in `workflow resolve` (#3879), bundle-update-force-mislead fix via `refresh()` on `DefaultPrimitiveInstaller` (#3452). Wheel preset `force-include` paths remapped to `specify_cli/core_pack/presets/` for upstream `0.15.1` `_locate_bundled_preset`. Fork `_cmd_prefix()` returns `"spec"` (upstream `"speckit"`); `EXTENSION_ALIAS_PATTERN_ENABLED` skips primary command registration when aliases exist; `SHARED_INFRA_FILES = {".specify/events.py"}` excluded from disjoint manifest checks; manifest path Windows normalization. PowerShell feature scripts hardened (`-Number [string]` + Int64 parse, empty `-Number` stripping, `Get-NextBranchNumber` double-increment fix, `[long]::MaxValue` bounds, dual-stream persist hints) in core and git-extension twins. Test suite synced to upstream `0.14.4` (`test_authentication` gitlab→bitbucket provider, `test_integration_catalog` `_auth_http.open_url` mock) and #2948 upgrade semantics adopted. Ruff clean across `src/` and `tests/`. git extension 1.8.0 → 1.8.1. | | 0.14.4+adlc1 | 2026-07-30 | 0.14.4 (`f04a36a6`) | Upstream merge (232 commits, 13 releases 0.12.16–0.14.4). **`_hooks_fork.py` deleted** — replaced by upstream `events.py` (PR #3704, authored by fork maintainer). The upstream rework renames `runtime_hooks:` → `events:`, uses snake_case canonical names (`session_start`, `pre_tool_use`, …), folds adapters into integration class attributes (`CANONICAL_TO_NATIVE`/`events_config_file`/`events_format`), adds `specify event run` dispatcher. All 8 event-capable integrations (claude/codex/cursor-agent/devin/gemini/opencode/qwen/tabnine) now use upstream class attrs instead of fork `--hooks`. agent-context extension 1.2.0→1.3.0 (migrated `runtime_hooks: SessionStart` → `events: session_start` + `scripts:` frontmatter). `resolve_command_refs` signature extended with `prefix` param (upstream invocation-style: `/`,`$`,`/skill:`) alongside fork's `project_root` (preset alias resolution). `build_command_invocation` keeps fork convention (always `/` prefix, `COMMAND_PREFIX`). Extension update flow: fork's bundled path preserved alongside upstream's improved download path (bounded zip reads, atomic transaction, manifest validation). Preset system: upstream's single-active registration (#2948) + `register_enabled_presets_for_agent` adopted; fork's `_cleanup_replaced_commands` (replaces: feature) + `inject_model_invocation_flag` preserved. Upstream security: bounded HTTP reads (`_download_security.py`), Rich markup escaping, zip-bomb protection, TOCTOU fixes. New features: workflow overlays, `assess` extension, conventional commits, `build_python_invocation`/`select_script_variant`, `is_skills_mode()`. 42 conflicts resolved. 173 events/base tests pass; ~60 test mock updates deferred (download-security mocks). | | 0.12.15+adlc9 | 2026-07-17 | 0.12.15 (`ad601e5d`) | Bug fixes in team-boot and team-discover model-invocation commands: (1) team-boot Step 2 used glob to find constitution — `{TEAM_AI_DIRECTIVES}` was treated as a search target, not a resolved value; added explicit definition after Step 1 and direct-read instruction in Step 2. (2) team-discover Step 2 had no plain-message fallback — expected `{REPO_ROOT}/specs/${SPECIFY_FEATURE}/context.md` which doesn't exist when invoked as a skill from team-boot; added fallback to extract feature context from user's message. (3) team-discover mode detection missing skill-invocation case — all 4 rules depended on `$ARGUMENTS`/env vars/hook context; added rule 5: skill invocation defaults to no-write mode with inline output. (4) team-discover Step 4 didn't surface external skills — `.skills.json` `external` map entries never matched against feature context; expanded matching to cover both `default` and `external` lists with category-based matching. (5) team-discover Step 1 `{TEAM_AI_DIRECTIVES}` undefined — same bare-variable pattern as team-boot; added clarifying note. team-ai-directives extension 4.3.2 → 4.3.3. | diff --git a/docs/community/extensions.md b/docs/community/extensions.md index 0556164e8f..44f7e16717 100644 --- a/docs/community/extensions.md +++ b/docs/community/extensions.md @@ -25,6 +25,7 @@ The following community-contributed extensions are available in [`catalog.commun | Extension | Purpose | Category | Effect | URL | |-----------|---------|----------|--------|-----| +| adrkit — decision memory for spec-driven development | Pulls the decisions governing this work into agent context, checks produced plans against them, and drafts an ADR from a plan artifact | `process` | Read+Write | [adrkit](https://github.com/mbeacom/adrkit) | | Agent Assign | Assign specialized Claude Code agents to spec-kit tasks for targeted execution | `process` | Read+Write | [spec-kit-agent-assign](https://github.com/xymelon/spec-kit-agent-assign) | | Agent Governance | Generate agent-platform repository governance files from Spec Kit metadata | `process` | Read+Write | [spec-kit-agent-governance](https://github.com/bigsmartben/spec-kit-agent-governance) | | AI-Driven Engineering (AIDE) | A structured 7-step workflow for building new projects from scratch with AI assistants — from vision through implementation | `process` | Read+Write | [aide](https://github.com/mnriem/spec-kit-extensions/tree/main/aide) | @@ -152,6 +153,7 @@ The following community-contributed extensions are available in [`catalog.commun | Superpowers Implementation Bridge | Thin orchestrator between Spec Kit (design) and Superpowers (implementation). Cross-agent. | `process` | Read+Write | [speckit-superpowers-bridge](https://github.com/lihan3238/speckit-superpowers-bridge) | | Superspec | Bridges spec-kit with obra/superpowers (brainstorming, TDD, subagent, code-review) into a unified, resumable workflow with graceful degradation and session progress tracking | `process` | Read+Write | [superspec](https://github.com/WangX0111/superspec) | | Tasks to GitHub Project | Publish and synchronize Spec Kit tasks as cards on a GitHub Project (v2) kanban board, with priority and status sync between spec.md/tasks.md and the board. | `integration` | Read+Write | [spec-kit-tasks-to-project](https://github.com/mancioshell/spec-kit-tasks-to-project) | +| TDD Extension | Drives spec-kit implementation with tests: a language-agnostic red-green-refactor loop with a per-feature test list, recorded red and green evidence, and mutation-checked test strength. | `process` | Read+Write | [spec-kit-tdd](https://github.com/d0whc3r/spec-kit-tdd) | | Team Assign | Assign tasks.md items to human engineers, split into subtasks, and generate a per-engineer workboard | `process` | Read+Write | [spec-kit-team-assign](https://github.com/tarunkumarbhati/spec-kit-team-assign) | | Test Coverage Drift Control | Generate incremental coverage drift reports and planned remediation tasks after implementation | `code` | Read+Write | [spec-kit-test-coverage-drift-control](https://github.com/benizzio/spec-kit-test-coverage-drift-control) | | Time Machine | Retroactively apply the full SDD workflow to existing codebases — analyse, spec, and ship feature-by-feature | `process` | Read+Write | [spec-kit-time-machine](https://github.com/teeyo/spec-kit-time-machine) | diff --git a/docs/reference/core.md b/docs/reference/core.md index fad62fc36b..3318264b4f 100644 --- a/docs/reference/core.md +++ b/docs/reference/core.md @@ -25,7 +25,7 @@ Creates a new Spec Kit project with the necessary directory structure, templates Use `` to create a new directory, or `--here` (or `.`) to initialize in the current directory. If the directory already has files, use `--force` to merge without confirmation. -When `--integration` is omitted, interactive terminals prompt you to choose an integration. Non-interactive sessions, such as CI or piped runs, default to GitHub Copilot; pass `--integration ` to choose a different integration explicitly. +When `--integration` is omitted, interactive terminals prompt you to choose an integration. Non-interactive sessions, such as CI or piped runs, default to GitHub Copilot; pass `--integration ` to choose a different integration explicitly, or set `SPECKIT_INTEGRATION_DEFAULT` to change the fallback (see [Environment Variables](#environment-variables)). ### Examples @@ -50,6 +50,7 @@ specify init my-project --integration copilot --preset compliance | Variable | Description | | ----------------- | ------------------------------------------------------------------------ | +| `SPECKIT_INTEGRATION_DEFAULT` | Override the fallback integration used by `specify init` when `--integration` is omitted (interactive prompt default and non-interactive fallback). Set it to any registered integration key (e.g. `gemini`, `claude`). An unrecognized value is ignored with a warning and the built-in default (`copilot`) is used. An explicit `--integration ` always takes precedence. | | `SPECIFY_INIT_DIR` | Target a member project from outside its directory (e.g. a monorepo root) without `cd`, for non-interactive / CI use. Set it to the **project root** — the directory *containing* `.specify/` (relative paths resolve against the current directory). The path must exist and contain `.specify/`, otherwise the command errors and does **not** fall back to the current directory. Resolved once in the core root helper (`get_repo_root` in Bash, `Get-RepoRoot` in PowerShell), so it is honored by the core feature scripts (`/speckit.plan`, `/speckit.tasks`, …) and the Git extension's feature-branch creation, which inherit it. The `specify` CLI applies the **same** validation rules to every project-scoped subcommand (`specify integration …`, `specify extension …`, `specify workflow …`, `specify preset …`, and the rest that operate on a `.specify/` project), so those can target a member project too. When unset, Bash/PowerShell helpers keep their existing upward search; the `specify` CLI keeps its project-scoped resolver cwd-only unless a command explicitly defines broader detection (for example, bundle commands). | | `SPECIFY_FEATURE_DIRECTORY` | Override the active feature directory *within* the resolved project (takes precedence over `.specify/feature.json`). Relative paths resolve under the project root. Combine with `SPECIFY_INIT_DIR` to pick both the project and the feature non-interactively. | | `SPECIFY_FEATURE` | Override feature detection for non-Git repositories. Set to the feature directory name (e.g., `001-photo-albums`) to work on a specific feature when not using Git branches. Must be set in the context of the agent prior to using `/speckit.plan` or follow-up commands. | diff --git a/docs/reference/integrations.md b/docs/reference/integrations.md index a12337316b..808d0cf752 100644 --- a/docs/reference/integrations.md +++ b/docs/reference/integrations.md @@ -20,7 +20,7 @@ The Specify CLI supports a wide range of AI coding agents. When you run `specify | [Firebender](https://firebender.com/) | `firebender` | IDE-based agent for Android Studio / IntelliJ | | [Forge](https://forgecode.dev/) | `forge` | | | [Gemini CLI](https://github.com/google-gemini/gemini-cli) | `gemini` | | -| [GitHub Copilot](https://code.visualstudio.com/) | `copilot` | Defaults to legacy markdown mode: `.agent.md` command files under `.github/agents/`, companion `.prompt.md` files under `.github/prompts/`, and a `.vscode/settings.json` merge. Pass `--integration-options="--skills"` to scaffold skills as `speckit-/SKILL.md` under `.github/skills/` instead. Legacy markdown mode is deprecated and will stop being the default in a future release. | +| [GitHub Copilot](https://code.visualstudio.com/) | `copilot` | Skills-based by default; installs `speckit-/SKILL.md` under `.github/skills/`. Pass `--integration-options="--commands"` to use the supported commands layout: `.agent.md` files under `.github/agents/`, companion `.prompt.md` files under `.github/prompts/`, and a `.vscode/settings.json` merge. | | [Goose](https://goose-docs.ai/) | `goose` | Uses YAML recipe format in `.goose/recipes/` | | [Grok Build](https://docs.x.ai/build/overview) | `grok` | Skills-based integration; installs skills into `.grok/skills` and invokes them as `/speckit-` | | [Hermes](https://github.com/NousResearch/hermes-agent) | `hermes` | Skills-based integration; installs skills globally into `~/.hermes/skills/` | @@ -234,7 +234,8 @@ Some integrations accept additional options via `--integration-options`: | ----------- | ------------------- | -------------------------------------------------------------- | | `generic` | `--commands-dir` | Required. Directory for command files | | `kimi` | `--migrate-legacy` | Migrate legacy `.kimi/skills/` installs to `.kimi-code/skills/` (including dotted→hyphenated skill naming, e.g. `speckit.xxx` → `speckit-xxx`) | -| `copilot` | `--skills` | Scaffold commands as agent skills (`speckit-/SKILL.md` under `.github/skills/`, invoked as `/speckit-`) instead of the default legacy markdown mode (`.github/agents/*.agent.md` plus `.github/prompts/*.prompt.md` and a `.vscode/settings.json` merge). Without this flag, install warns that legacy markdown mode is deprecated. | +| `copilot` | `--commands` | Scaffold `.github/agents/*.agent.md` commands with `.github/prompts/*.prompt.md` companions and merge `.vscode/settings.json` instead of using the default skills layout. | +| `copilot` | `--skills` | Force the default skills layout, overriding an existing commands layout during an explicit migration. | Example: diff --git a/extensions/catalog.community.json b/extensions/catalog.community.json index 6353356cd9..9657122cc7 100644 --- a/extensions/catalog.community.json +++ b/extensions/catalog.community.json @@ -1,8 +1,43 @@ { "schema_version": "1.0", - "updated_at": "2026-07-29T00:00:00Z", + "updated_at": "2026-08-04T00:00:00Z", "catalog_url": "https://raw.githubusercontent.com/github/spec-kit/main/extensions/catalog.community.json", "extensions": { + "adrkit": { + "name": "adrkit — decision memory for spec-driven development", + "id": "adrkit", + "description": "Pulls the decisions governing this work into agent context, checks produced plans against them, and drafts an ADR from a plan artifact.", + "author": "Mark Beacom (@mbeacom)", + "version": "0.1.2", + "download_url": "https://github.com/mbeacom/adrkit/releases/download/spec-kit-v0.1.2/adrkit.zip", + "repository": "https://github.com/mbeacom/adrkit", + "homepage": "https://adrkit.dev", + "documentation": "https://github.com/mbeacom/adrkit/blob/main/packages/adapters/spec-kit/README.md", + "changelog": "https://github.com/mbeacom/adrkit/blob/main/CHANGELOG.md", + "license": "Apache-2.0", + "category": "process", + "effect": "read-write", + "requires": { + "speckit_version": ">=0.13.0,<0.16.0", + "tools": [{ "name": "adr", "version": ">=0.3.0", "required": true }] + }, + "provides": { + "commands": 3, + "hooks": 1 + }, + "tags": [ + "adr", + "governance", + "decision-records", + "architecture", + "compliance" + ], + "verified": false, + "downloads": 0, + "stars": 0, + "created_at": "2026-08-03T00:00:00Z", + "updated_at": "2026-08-03T00:00:00Z" + }, "aide": { "name": "AI-Driven Engineering (AIDE)", "id": "aide", @@ -327,8 +362,8 @@ "id": "archive", "description": "Archive merged features into main project memory, resolving gaps and conflicts.", "author": "Stanislav Deviatov", - "version": "1.0.0", - "download_url": "https://github.com/stn1slv/spec-kit-archive/archive/refs/tags/v1.0.0.zip", + "version": "1.1.0", + "download_url": "https://github.com/stn1slv/spec-kit-archive/archive/refs/tags/v1.1.0.zip", "repository": "https://github.com/stn1slv/spec-kit-archive", "homepage": "https://github.com/stn1slv/spec-kit-archive", "documentation": "https://github.com/stn1slv/spec-kit-archive/blob/main/README.md", @@ -353,7 +388,7 @@ "downloads": 0, "stars": 0, "created_at": "2026-03-14T00:00:00Z", - "updated_at": "2026-03-14T00:00:00Z" + "updated_at": "2026-08-04T00:00:00Z" }, "azure-devops": { "name": "Azure DevOps Integration", @@ -776,8 +811,8 @@ "id": "charter", "description": "Compose modular project constitutions from shared fragment registries. Centralize governance rules, select per-project fragments, track upstream changes, and keep multi-project setups consistent.", "author": "Fyloss", - "version": "0.3.1", - "download_url": "https://github.com/Fyloss/spec-kit-charter/archive/refs/tags/v0.3.1.zip", + "version": "0.5.1", + "download_url": "https://github.com/Fyloss/spec-kit-charter/archive/refs/tags/v0.5.1.zip", "repository": "https://github.com/Fyloss/spec-kit-charter", "homepage": "https://github.com/Fyloss/spec-kit-charter", "documentation": "https://github.com/Fyloss/spec-kit-charter/tree/master/docs", @@ -786,7 +821,8 @@ "category": "process", "effect": "read-write", "requires": { - "speckit_version": ">=0.11.9" + "speckit_version": ">=0.11.9", + "tools": [{ "name": "git", "required": false }] }, "provides": { "commands": 5, @@ -803,7 +839,7 @@ "downloads": 0, "stars": 0, "created_at": "2026-07-06T00:00:00Z", - "updated_at": "2026-07-06T00:00:00Z" + "updated_at": "2026-08-04T00:00:00Z" }, "ci-guard": { "name": "CI Guard", @@ -4453,6 +4489,47 @@ "created_at": "2026-06-22T00:00:00Z", "updated_at": "2026-06-22T00:00:00Z" }, + "tdd": { + "name": "TDD Extension", + "id": "tdd", + "description": "Drives spec-kit implementation with tests: a language-agnostic red-green-refactor loop with a per-feature test list, recorded red and green evidence, and mutation-checked test strength.", + "author": "d0whc3r", + "version": "1.1.2", + "download_url": "https://github.com/d0whc3r/spec-kit-tdd/releases/download/v1.1.2/tdd-1.1.2.zip", + "repository": "https://github.com/d0whc3r/spec-kit-tdd", + "homepage": "https://d0whc3r.github.io/spec-kit-tdd/", + "documentation": "https://github.com/d0whc3r/spec-kit-tdd/wiki", + "changelog": "https://github.com/d0whc3r/spec-kit-tdd/blob/main/CHANGELOG.md", + "license": "MIT", + "category": "process", + "effect": "read-write", + "requires": { + "speckit_version": ">=0.11.9" + }, + "provides": { + "commands": 4, + "hooks": 3 + }, + "tags": [ + "acceptance-tests", + "mutation-testing", + "property-based-testing", + "quality", + "red-green-refactor", + "spec-kit", + "spec-kit-extension", + "tdd", + "test-driven-development", + "test-first", + "testing", + "unit-tests" + ], + "verified": false, + "downloads": 0, + "stars": 0, + "created_at": "2026-08-04T00:00:00Z", + "updated_at": "2026-08-04T00:00:00Z" + }, "team-assign": { "name": "Team Assign", "id": "team-assign", diff --git a/newsletters/2026-April.md b/newsletters/2026-April.md index 913dedaf23..76f54de745 100644 --- a/newsletters/2026-April.md +++ b/newsletters/2026-April.md @@ -4,7 +4,7 @@ This edition covers Spec Kit activity in April 2026. Seventeen releases shipped | **Spec Kit Core (Apr 2026)** | **Community & Content** | **SDD Ecosystem & Next** | | --- | --- | --- | -| Seventeen releases shipped with major features: integration plugin architecture, workflow engine, preset composition, integration catalog, bundled lean preset, documentation site, and academic citation support. Three new agents added (Forgecode, Goose, Devin for Terminal). The repo grew from ~82k to **92,038 stars**. [\[github.com\]](https://github.com/github/spec-kit/releases) | Thoughtworks Technology Radar placed Spec Kit in the "Assess" ring. Community catalog grew from 26 to **83 extensions** and from 2 to **12 presets**. 12 substantive external articles published. XB Software documented a real legacy project. Fabián Silva shipped the Caramelo VS Code extension. | Matt Rickard argued for "smaller specs, harder checks." Will Torber's three-framework comparison recommended OpenSpec for most teams. The "Spec Layer" debate emerged: specs as constraint surfaces for AI agents. Spec Kit leads in breadth and portability; competitors differentiate on drift detection and orchestration depth. | +| Seventeen releases shipped with major features: integration plugin architecture, workflow engine, preset composition, integration catalog, bundled lean preset, documentation site, and academic citation support. Three new agents added (Forgecode, Goose, Devin for Terminal). The repo grew from ~82k to **92,038 stars**. [\[github.com\]](https://github.com/github/spec-kit/releases) | Thoughtworks Technology Radar placed Spec Kit in the "Assess" ring. Community catalog grew from 26 to **83 extensions** and from 2 to **12 presets**. External coverage continued across developer blogs and industry press. XB Software documented a real legacy project. Fabián Silva shipped the Caramelo VS Code extension. | Matt Rickard argued for "smaller specs, harder checks." Will Torber's three-framework comparison recommended OpenSpec for most teams. The "Spec Layer" debate emerged: specs as constraint surfaces for AI agents. Spec Kit leads in breadth and portability; competitors differentiate on drift detection and orchestration depth. | *** @@ -94,7 +94,7 @@ On **April 15**, the **Thoughtworks Technology Radar Volume 34** placed GitHub S ### Developer Articles and Blog Posts -April produced 12 substantive external articles (plus one excluded as AI-generated SEO spam). +April produced a steady stream of external articles. **Matt Rickard** published *"The Spec Layer: Why Spec-Driven Development (SDD) Works"* on April 1. His thesis: specs reduce execution freedom for AI agents, functioning as constraint surfaces. He compared Spec Kit, Kiro, OpenSpec, Tessl, Intent, and Symphony, and advocated for **"smaller specs, harder checks, less guessing."** [\[blog.matt-rickard.com\]](https://blog.matt-rickard.com/p/the-spec-layer) diff --git a/newsletters/2026-July.md b/newsletters/2026-July.md new file mode 100644 index 0000000000..412ff648ae --- /dev/null +++ b/newsletters/2026-July.md @@ -0,0 +1,152 @@ +# Spec Kit - July 2026 Newsletter + +This edition covers Spec Kit activity in July 2026 — a month of hardening and expanding the envelope. Twenty-eight releases shipped (v0.12.3 through v0.15.1), crossing three minor bumps and delivering three headline capabilities: the **`assess` "Idea Assessment Pipeline" extension**, which pushes spec-driven development *upstream* of the spec to answer "should we even build this?"; the new **`py` (Python) script type** and the broad shell→Python port that underpins it; and a **first-class agent-native runtime events layer** for integrations. Beneath the features, the month's dominant engineering theme was a sustained **security-hardening wave** — bounded HTTP reads, strict redirect validation, TOCTOU-race elimination, and defensive validation across the workflow engine. Externally, coverage broadened structurally: mainstream tech press (heise online) covered the v0.13 `assess` release in two languages, and a **companion-tooling ecosystem** bloomed around the project — spec↔code drift detectors, model-sizing advisors, and testing-gap tools all built *on top of* Spec Kit. A summary is in the table below, followed by details. + +| **Spec Kit Core (Jul 2026)** | **Community & Content** | **SDD Ecosystem & Next** | +| --- | --- | --- | +| Twenty-eight releases shipped (v0.12.3–v0.15.1), crossing v0.13, v0.14, and v0.15. Headline features: the `assess` **Idea Assessment Pipeline** extension (capture→evidence→refine→design→go/clarify/kill), the new **`py` script type** plus a shell→Python port of the core scripts, git extension, and agent-context updater, and an **agent-native runtime events layer** for integrations. Three agents joined (Grok Build, Factory Droid CLI, Alquimia AI), the label-driven **bug-fix/bug-test** automation completed the triage pipeline, and a heavy **security-hardening** wave landed. The repo grew from ~117,400 to **124,655 stars**. [\[github.com\]](https://github.com/github/spec-kit/releases) | The community extension catalog grew from 125 to **144 entries**; presets reached **29**, community workflows **2**, bundles **1**. **heise online** covered the v0.13 `assess` release in English and German. Coverage shifted toward comparisons, companion tooling, and "who verifies the spec?" critiques. **~258 contributors** now listed. | A **companion-tooling ecosystem** emerged — artgraph (deterministic spec↔code drift), SpecJudge (model right-sizing), GAUNTLEX (security-testing gap), and custom skills like `speckit-next` and `prefill`. Comparisons increasingly pit Spec Kit against Kiro; balanced reviews keep flagging documentation proliferation and cognitive load, precisely the gaps the `assess` upstream step and the drift/companion ecosystem are built to close. | + +*** + +> **Hardening the Foundation, Expanding the Envelope.** If June was defined by external validation, July was defined by internal consolidation and reach. No single release carried the weight of `converge` or `bundle`, but the month moved the project in two directions at once. It reached *upstream* — the new `assess` pipeline lets a team evaluate an idea (capture evidence, refine, design, then go/clarify/kill) *before* a spec exists, extending SDD past the spec into the decision to build. And it reached *down to the metal* — a new `py` script type and a systematic port of the core scripts, git extension, and agent-context updater from shell to Python, alongside a security-hardening wave that bounded every HTTP read, validated every redirect hop, eliminated file-race conditions, and taught the workflow engine to fail loudly instead of crashing on malformed input. Meanwhile the ecosystem answered the project's most-cited critique — "who verifies the spec, and who reads all this documentation?" — not with complaints but with *code*: a wave of companion tools built directly on Spec Kit artifacts. None of this happens without the community — the contributors, extension and preset authors, bundle builders, agent-integration maintainers, and practitioners writing in more than 20 languages. Thank you. + +## Spec Kit Project Updates + +### Releases Overview + +**v0.12.3–v0.12.18** (July 1–17) was the month's longest patch run and carried two features amid heavy hardening. The **`py` script type** landed (#3285), adding Python interpreter resolution alongside the existing `sh`/`ps` options, and the **label-driven bug-fix (#3258) and bug-test (#3239) agentic workflows** completed the `bug-assess → bug-test → bug-fix` triage pipeline. The systematic shell→Python port began here: the **`update-agent-context` script** (#3387), the **git extension scripts** (#3400), and a **`check-prerequisites` proof-of-concept** (#3302) were all ported. **PyPI was documented as a first-class second install route** (#3516). New agents arrived — **Grok Build** (#3535) as a skills-based integration — while **Roo Code was retired** as a shut-down product (#3212). The rest was a broad defensive-validation sweep across the workflow engine (case-insensitive gate reject, quote-aware interpolation, host-less catalog-URL rejection, and dozens of "fail loudly on malformed input" guards). [\[github.com\]](https://github.com/github/spec-kit/releases) + +**v0.13.0–v0.13.4** (July 17–22) delivered the month's headline feature: the **`assess` Idea Assessment Pipeline extension** (#3568), a pre-spec evaluation flow. The release also completed the Python port of the three core scripts — **`create-new-feature`, `setup-plan`, and `setup-tasks`** (#3386) — and added **Azure DevOps `az`-CLI token acquisition** hardening (#3527), **community bundle submission automation** (#3553), and the standalone **`WorkflowResolver`** refactor (#3557). **Factory Droid CLI** joined as an integration (#3587), **Bob was updated to a skills-based layout for Bob 2.0** (#3415), the **`pipeline` workflow** was added to the community catalog (#3338), and the **spec-of-specs feature-breakdown** approach was documented for handling complex features (#3648). [\[github.com\]](https://github.com/github/spec-kit/releases) + +**v0.14.0–v0.14.4** (July 23–29) crossed a minor with a **security-hardening focus**: **bounded HTTP reads and strict redirect enforcement** (#3140, #3671), **secured extension/preset archive downloads** (#3141), and the **removal of the `shell` parameter from `run_command`** (#3716). The **git extension gained configurable Conventional Commit support** (#3413), the wheel now **bundles `scripts/python`** so `--script py` works from a clean install (#3665), and **Alquimia AI** joined as the month's third new agent (#2734). Documentation added a **Simplified Chinese README translation** (#3740), and the constitution stopped **propagating guidance into templates** (#3790). A long run of bundler, preset, and integration validation fixes rounded out the cluster. [\[github.com\]](https://github.com/github/spec-kit/releases) + +**v0.15.0–v0.15.1** (July 30–31) closed the month with a **first-class agent-native runtime events layer for integrations** (#3704) — the release's headline — plus a continued security pass: **TOCTOU-race elimination in file-unlink calls** (#3811, #3815, #3819), **UTF-8 encoding on registry file opens** (#3810, #3816), and **hardening of the extension URL-download cache against symlink/junction races** (#3869). Workflows gained the ability to **bind a gate verdict to a workflow input via `verdict_input`** (#3725), an opt-in **`constitution-sync` preset** shipped (#3873), the **`yolo` workflow** was added to the community catalog (#3864), and installs gained **tar-archive support** (#3874). [\[github.com\]](https://github.com/github/spec-kit/releases) + +### The Idea Assessment Pipeline: `assess` + +July's headline feature was the **`assess` extension** (#3568), an *idea-assessment pipeline* that ships as an opt-in extension and extends spec-driven development one step further upstream than it has ever reached. Where the core lifecycle begins at `/speckit.specify` — assuming the decision to build has already been made — `assess` addresses the question that comes *before* the spec: **should this idea be built at all, and is it understood well enough to specify?** + +The pipeline runs a staged flow — **capture → evidence → refine → design → decision** — that takes a raw idea, gathers supporting evidence, refines it into something concrete, sketches a design, and terminates in an explicit **go / clarify / kill** verdict. A `go` feeds a well-formed problem into the existing `/speckit.specify` step; a `clarify` routes back for more information; a `kill` stops work before a line of spec is written. Its input is just an idea — pasted text, a URL, a ticket, or a codebase pointer — so the pipeline works **equally well on an empty, freshly-initialized project or on an existing codebase** (#3732); a team can evaluate a green idea before any scaffolding exists, or assess a change against a repo that already has one. + +The feature drew the month's most prominent mainstream-press coverage: **heise online** ran *"From Idea to Spec: The New Feature in Spec Kit 0.13"* in both English and German, framing `assess` as the notable addition of the 0.13 line alongside the Azure DevOps CLI support and the bundler/preset validation fixes. Coming from a major European technology outlet rather than a developer blog, it was a signal that Spec Kit's release cadence is now tracked as mainstream tooling news. [\[heise.de\]](https://www.heise.de/en/news/From-Idea-to-Spec-The-New-Feature-in-Spec-Kit-0-13-11371866.html) + +### The Python Migration: the `py` Script Type + +Spec Kit's second July theme was quieter but structurally important: the project began migrating its shell scripts to **Python**. The new **`py` script type** (#3285) joins `sh` (bash) and `ps` (PowerShell) as a third option at `specify init`, backed by Python-interpreter resolution that skips broken stubs (including the Windows Store `python3` alias, #3385). The `py` type is the project's answer to the perennial bash/PowerShell parity tax — every script fix previously had to be written twice and kept in sync, a recurring source of the Windows-parity bugs that filled prior months' changelogs. + +Behind the new type, a systematic port landed piece by piece across the month: the **`update-agent-context`** updater (#3387), the **git extension scripts** (#3400), a **`check-prerequisites`** proof-of-concept (#3302), and finally the three core scripts — **`create-new-feature`, `setup-plan`, and `setup-tasks`** (#3386). The wheel was updated to bundle `scripts/python` so `--script py` works from a clean PyPI install (#3665), and the installation docs and init option table were updated to document the new type and the sh/ps migration plan (#3284, #3640). The end state is a single, cross-platform script implementation that removes an entire class of parity bugs. [\[github.com\]](https://github.com/github/spec-kit/releases) + +### Agent-Native Runtime Events + +The v0.15.0 headline was a **first-class agent-native runtime events layer for integrations** (#3704). It bridges Spec Kit to the host agent's own lifecycle via a set of canonical, snake_case event names — `session_start`, `pre_tool_use`, `post_tool_use`, `user_prompt_submit`, `stop`, and `session_end`. A lightweight, zero-dependency **Event Dispatcher** (`.specify/events.py`) is scaffolded during `specify init`, and per-integration **Event Adapters** translate each canonical event into the agent's *native* hook configuration — `.github/hooks/speckit.json` (bash/PowerShell variants) for **Copilot CLI**, `.claude/settings.json` for Claude Code, `.cursor/hooks.json` for Cursor, `.codex/config.toml` for Codex, a TypeScript plugin for opencode, and native settings merges for Gemini, Qwen, Devin, and Tabnine — so extension authors declare `events:` in `extension.yml` once and never learn agent-specific names. Resolution is a four-tier stack (CLI `--events false` → user `.specify/integration-events.yml` override → extension-declared events → built-in defaults), and multiple extensions declaring the same event all run. The change accompanied a broader integration-refinement run: agents that use an always-slash invocation (Droid, Forge, Cline) now render hyphenated `/speckit-` commands correctly (#3688, #3642, #3622), native skill-invocation prefixes are preserved (#3663), and several agents (kiro-cli, Lingma, Pi, omp) were declared multi-install-safe. The through-line is that integrations are increasingly *native* to each agent rather than a lowest-common-denominator overlay. [\[github.com\]](https://github.com/github/spec-kit/releases) + +### The Security-Hardening Wave + +The dominant engineering theme across all twenty-eight releases was **security and robustness**. The work fell into three bands. **Bounded I/O:** every catalog, download, and bundle HTTP response is now read under a byte cap with strict redirect validation on every hop (#3140, #3671, #3763, #3141), closing a class of unbounded-read / DoS exposure. **Race elimination:** TOCTOU races in file-unlink and state-file handling were removed (#3811, #3815, #3819), the extension URL-download cache was hardened against symlink and junction races (#3869), and registry file opens were pinned to UTF-8 (#3810, #3816). **Injection and input hardening:** the `shell` parameter was removed from `run_command` (#3716), user-supplied catalog metadata is escaped in every discovery/list/`init` output path (#3772, #3773, #3774, #3806, #3826, #3863), and catalog URLs are re-validated *after* redirects to preserve HTTPS/host guarantees (#3523, #3524). + +Running alongside this was a systematic **"fail loudly, don't crash"** campaign across the workflow engine and catalog loaders: dozens of PRs replaced raw `ValueError`/`OverflowError`/crash paths with clean validation errors on malformed input — non-string commands, prompts, integrations, and models; non-list branches and `wait_for` entries; `priority: .inf` and boolean priorities; non-mapping manifest blocks; and superscript-digit gate prompts. The entire month's hardening arrived as prevention rather than response. [\[github.com\]](https://github.com/github/spec-kit/releases) + +### The Workflow Engine & Bundles Mature + +Beyond hardening, the **workflow engine** kept gaining capability. Steps can now read their **workflow source directory** (#3469), the shell and prompt steps got **configurable, validated timeouts** (#3404, #3847, #3768), a **gate verdict can bind to a workflow input** via `verdict_input` (#3725), and the **`WorkflowResolver`** was extracted as a standalone component (#3557). Two community workflows reached the catalog — the guided **`pipeline`** (#3338, which chains into the core `/speckit.converge`) and **`yolo`** (#3864) — bringing the standalone-workflow count to two. + +The **bundle subsystem** introduced in June matured through a long tail of correctness work — reproducible builds via canonical POSIX arcnames (#3658), literal UTF-8 manifest dumps (#3660), strict rejection of malformed `requires`/`provides`/`integration`/`catalogs` blocks, and a clean `BundlerError` on malformed download URLs (#3586). **Community bundle submission automation** landed (#3553) and the **SicarioSpec Security & Governance Bundle** became a cataloged community bundle (#3636), making bundles a live community-submittable artifact type in practice. [\[github.com\]](https://github.com/github/spec-kit/releases) + +### Agent Integrations + +The agent portfolio grew net **+3 to 37 integrations**. Three joined — **Grok Build** (#3535), **Factory Droid CLI** (#3587, closing the 300+-day #822), and **Alquimia AI** (#2734) — while **Roo Code** was retired as a shut-down product (#3212). **Bob** was migrated to a skills-based layout for Bob 2.0 (#3415), **Kilocode** now installs commands under `.kilo/commands` (#3672), and a broad correctness pass fixed hyphenated-command rendering and dispatch for the always-slash agents (Droid, Forge, Cline) and preserved native skill-invocation prefixes (#3663). The pattern continues from June — pruning dead products while making the surviving integrations more native to each agent. [\[github.com\]](https://github.com/github/spec-kit/releases) + +### The Extension & Preset Ecosystem + +The community extension catalog grew from 125 to **144 entries** during July — nineteen net additions. Community presets grew from 23 to **29**, community workflows reached **2**, and the first community **bundle** (SicarioSpec) was cataloged. + +Notable new extensions by category: + +- **Verification, drift & evidence**: Test Coverage Drift Control, PatchWarden Evidence Pack, Quality Gates (Enforcement Layer), Verify Review Ship, Intent Reconciliation +- **Requirements & intake**: EARS Requirements Syntax, the `assess` Idea Assessment Pipeline, Spec-Kit BDD, Charter +- **External trackers & round-trip**: Linear Weave, Multi-Repo Branch Sync, ContextForge MCP +- **Design & docs**: Spec Kit Figma, Figma Starter, Blueprint Index — Living Architecture Map, LLM Wiki, Dotdog +- **Knowledge & orchestration**: OKF Knowledge Bundle Generator, Orchestration Task Context Management, Spec Kit Memory + +The catalog also showed strong maintenance activity: **DocGuard — CDD Enforcement** advanced through several releases (to v0.33.0), **Verify Review Ship** and **Quality Gates (Enforcement Layer)** iterated rapidly, and **Architecture Guard**, **Golden Demo**, **Coding Standards Drift Control**, **Ripple**, and the **Ralph Loop** all shipped updates. The preset side was the month's busiest: a large **governance-preset** family expanded and iterated — the **Autonomous Run Governance** and **Parallel Autonomous Run Governance** presets, a full **Intake** governance suite (Authoring, Review, Sequencing), **Test-First Governance**, and coordinated version bumps across the A11Y, Agent-Parity, Cross-Platform, iSAQB-Architecture, Architecture, and Security governance presets. [\[github.com\]](https://github.github.io/spec-kit/community/extensions.html) + +### Documentation & Docs Site + +July's documentation work paired the new features with a landing-page refresh. The **spec-of-specs feature-breakdown** approach was documented for handling complex features (#3648), the **`py` (Python) script type** was documented in the installation guide and init option table (#3284, #3625, #3640), and the **`__SPECKIT_COMMAND`** token for portable cross-command references was documented (#3503). The landing page was reframed to weave the **harness/SDLC framing** and modernize the install and positioning story (#3565, #3567), ecosystem stats were refreshed (#3561), and **`extensions.yml` hook configuration** was documented (#3563). Upgrade guidance clarified that project-file upgrades flow through `integration upgrade` / `extension update` (#3326) and that Claude Code files live in `.claude/skills` (#3708). [\[github.com\]](https://github.com/github/spec-kit/releases) + +## Community & Content + +### Press and Industry Coverage + +July's coverage shifted from "what is SDD" explainers toward tool comparisons, companion tooling, and pointed "who verifies the spec?" critiques. No first-party Microsoft or GitHub post appeared in July; the nearest remained June's Microsoft Developer Blog piece. + +**heise online** (Wolf Hosbach, July 21) was the month's most prominent mainstream-press coverage, publishing *"From Idea to Spec: The New Feature in Spec Kit 0.13"* in both English and German — news coverage of the `assess` Idea Assessment Pipeline, the Azure DevOps CLI support, and the 0.13 validation fixes. Mainstream European tech press now tracks Spec Kit's minor releases as tooling news. [\[heise.de\]](https://www.heise.de/en/news/From-Idea-to-Spec-The-New-Feature-in-Spec-Kit-0-13-11371866.html) + +**Towards AI** (Rost Glukhov, July 12) compared **GitHub Spec Kit vs Kiro vs Claude Code** on SDD workflow rather than model capability, part of a July-long current of "which SDD tool?" comparisons that increasingly pit Spec Kit specifically against Kiro. [\[pub.towardsai.net\]](https://pub.towardsai.net/github-spec-kit-vs-kiro-vs-claude-code-sdd-workflows-a9e7fab3e545) + +**ranjankumar.in** (Ranjan Kumar, July 13) argued that four SDD frameworks — BMAD, Spec Kit, Kiro, and Superpowers — converge on the same structural "invariants," engaging Spec Kit's actual internals (`workflows.md`, run-state `state.json`) rather than treating it as a black box. [\[ranjankumar.in\]](https://ranjankumar.in/spec-driven-development-invariants-not-frameworks) + +Release-trackers continued their factual coverage of the 0.13–0.15 run, and **Level Up Coding** (JingJing "Chris" Bao) published a three-part practitioner series on Spec Kit's presets, extensions, and pipeline/workflow features as the path beyond linear slash-commands. [\[levelup.gitconnected.com\]](https://levelup.gitconnected.com/from-linear-commands-to-automated-pipelines-how-spec-kit-orchestrates-nonlinear-ai-development-55ca03c5617b) + +### The Companion-Tooling Ecosystem + +July's most telling signal was not an article but a pattern: independent developers responded to Spec Kit's most-cited critiques by **building tools on top of it**. The recurring complaint — documentation proliferation and "who verifies the generated spec?" — turned into code. + +- **artgraph** (mori-shin, July 20) — a deterministic, hash-based spec↔code drift-detection CLI with an `artgraph integrate speckit` hook, built specifically to give Spec Kit's LLM-prompt-based verification a deterministic backstop. [\[zenn.dev\]](https://zenn.dev/mrmtsntr/articles/artgraph-spec-code-drift) +- **SpecJudge** (Joaquín Ruiz, July 21) — a companion CLI that reads Spec Kit's constitution/spec/tasks artifacts to recommend a *right-sized* model for the project. [\[dev.to\]](https://dev.to/jokiruiz/specjudge-which-ai-model-is-right-sized-for-your-project-ask-your-specs-2edp) +- **GAUNTLEX** (Sanjoy Ghosh, July 16) — named Spec Kit a leading SDD tool while arguing SDD leaves a security-testing gap, and shipped a tool to fill it. [\[hashnode.dev\]](https://sanjoy1234.hashnode.dev/the-testing-gap-nobody-s-talking-about-in-spec-driven-development) +- **Custom skills** — [`speckit-next`](https://qiita.com/htcd/items/ec76f2b7194be3297b93) (htcd, July 31), a skill that recommends the next command because the names and order are hard to remember, and [`prefill`](https://velog.io/@k3nta/ai-adoption-journey-1-tools) (k3nta, July 1), a skill that patches `clarify`'s blind spots. + +Together these are the clearest evidence yet that Spec Kit has become a *platform* — its artifacts are stable enough, and its gaps well-enough understood, that a third-party tooling layer is forming around it. [\[zenn.dev\]](https://zenn.dev/mrmtsntr/articles/artgraph-spec-code-drift) + +### Developer Articles and Blog Posts + +July's articles skewed heavily multilingual — strong hands-on series in Japanese, Chinese, and Korean — with a clear thread of honest, use-it-in-anger critique. + +Notable articles: + +- **ta_kawano** (note.com, July 28–31) published a consolidated four-part **Kiro vs Spec Kit** head-to-head, completing a 108-task / 301-test build with Spec Kit where Kiro ran out of credit, praising measurable Success Criteria and auto-listed edge cases while flagging ~15,000 lines of generated documentation — and reframing Spec Kit as a requirements-elicitation tool. [\[note.com\]](https://note.com/takawano/n/ncb552ee37331) +- **magebyte / 码哥字节** (SegmentFault, July 26) built a Go REST API through the five-step workflow, covered the three spec-persistence models and the extension/preset system, and claimed ~80% less AI "hallucination" rework. [\[segmentfault.com\]](https://segmentfault.com/a/1190000048082146) +- **Nil Seri** (Medium, July 16) published a brownfield guide adding Spec Kit to an existing Spring Boot / Maven project with Jira and Confluence integration — "from Jira ticket to verified code." [\[medium.com\]](https://medium.com/@senoritadeveloper/using-spec-kit-in-an-existing-spring-boot-maven-project-from-jira-ticket-to-verified-code-4e6da99b5d19) +- **kitroc7134** (Qiita, July 4) tested `/speckit.converge` with deliberate fault-injection on a FastAPI Todo API — detect drift → append convergence tasks → re-implement — validating June's convergence loop in the field. [\[qiita.com\]](https://qiita.com/kitroc7134/items/117d4839f259bc403626) +- **yutakaosada** (Zenn, July 25) — a Microsoft-MVP .NETラボ talk that uses Spec Kit but candidly flags AI-credit consumption, over-production of docs, and single-source-of-truth collapse, comparing it with Copilot Plan mode. [\[zenn.dev\]](https://zenn.dev/yutakaosada/articles/70e01981647159) + +Additional coverage appeared on TechWealthBuzz, Hashnode, TabNews-adjacent outlets, CSDN and 腾讯云 (Chinese), Naver/velog/Tistory (Korean), and Qiita/note (Japanese) — including several "is it too heavy?" and documentation-proliferation critiques, and a [Korean instructor's piece](https://blog.naver.com/gaussian88/224363268926) citing Spec Kit's star growth from ~90k in May to ~120k in July. [\[note.com\]](https://note.com/takawano/n/ncb552ee37331) + +### Community Growth by the Numbers + +| Metric | Start of July | End of July | Change | +| --- | --- | --- | --- | +| GitHub stars | 117,423 | 124,655 | +7,232 (+6%) | +| Forks | 10,382 | 11,125 | +743 | +| Contributors | 245 | ~258 | +~13 | +| Releases (total) | 177 | 205 | +28 (v0.12.3–v0.15.1) | +| Community extensions | 125 | 144 | +19 | +| Community presets | 23 | 29 | +6 | +| Community workflows | 1 | 2 | +1 | +| Community bundles | 1 | 1 | steady | +| Agent integrations | 34 | 37 | +3 (net) | +| Discussions (open) | 457 | ~467 | +~10 | + +## SDD Ecosystem & Industry Trends + +### From Tool to Platform + +July's clearest ecosystem signal was structural: the conversation moved from "how do I use Spec Kit?" to "what do I build *around* it?" The companion tools — artgraph for deterministic drift, SpecJudge for model sizing, GAUNTLEX for the testing gap, and a growing set of custom agent skills — treat Spec Kit's artifacts (constitution, spec, tasks, run-state) as a stable substrate to build against. The public community catalog reinforces the point: the loudest theme across the 144 cataloged extensions is verification and quality (review, validate, drift, sync, verify, audit), and core SDD verbs are increasingly *re-expressed* by extensions rather than merely overridden — evidence of demand for composable, overridable core commands. [\[github.com\]](https://github.github.io/spec-kit/community/extensions.html) + +### Competitive Landscape + +The "which SDD tool?" comparison remained the dominant content genre, but July's framing narrowed: where June's surveys ran a seven-tool field, July's most substantive pieces increasingly went head-to-head **Spec Kit vs Kiro** (ta_kawano, [faruryo](https://qiita.com/faruryo/items/87a14728299e89f80ff4), Towards AI). The recurring verdict held — Spec Kit is the heaviest and most flexible option, strong on measurable Success Criteria, requirements elicitation, and greenfield decomposition, while its documentation proliferation and cognitive load are the consistent trade-off. The convergence-invariants analyses (ranjankumar.in) went further, arguing the frameworks are converging on the same structural primitives, which shifts the competitive question from "which tool" to "which ecosystem and governance model." On that axis, Spec Kit's widening catalog, agent-neutrality, and now a forming companion-tooling layer are its differentiators. [\[note.com\]](https://note.com/takawano/n/ncb552ee37331) + +## Roadmap + +Areas under discussion or in progress for future development: + +- **Upstream of the spec** — the `assess` Idea Assessment Pipeline extends SDD before the spec exists. Expect the capture→evidence→refine→design→decision flow to deepen, and the boundary between idea assessment and `/speckit.specify` to be a key area to refine as the pipeline sees real use. [\[heise.de\]](https://www.heise.de/en/news/From-Idea-to-Spec-The-New-Feature-in-Spec-Kit-0-13-11371866.html) +- **The Python migration** — the `py` script type and the port of the core scripts, git extension, and agent-context updater establish Python as the path out of the bash/PowerShell parity tax. Completing the port and making `py` a well-trodden default (rather than sh/ps) is the payoff: an entire class of Windows-parity bugs disappears. [\[github.com\]](https://github.com/github/spec-kit/releases) +- **Agent-native runtime events** — the first-class events layer lets integrations wire Spec Kit into each agent's own runtime through canonical event names and per-agent adapters. The layer is **actively evolving** — early signals point to opencode context injection and JSON-envelope agent hooks. Expect more agents to gain event adapters and extension authors to lean on the declarative `events:` surface as the integration layer shifts from lowest-common-denominator overlay to genuinely native behavior. [\[github.com\]](https://github.com/github/spec-kit/releases) +- **Copilot skills as the default** — July shipped a warning ahead of the skills-default rollout, and the signals now point to the **default flip being in progress** — moving `specify init --integration copilot` to the skills-based layout and making the default init integration overridable via an environment variable, with the markdown-command layout becoming the legacy path. [\[github.com\]](https://github.com/github/spec-kit/releases) +- **A Copilot-native surface** — the first-party [`github/spec-kit-copilot`](https://github.com/github/spec-kit-copilot) repo (a listed community friend) wraps the `specify` CLI as a **Copilot skills plugin** (nine skills across setup, init, extensions, presets, bundles, workflows, and self-upgrade) for the Copilot CLI and App, aligned to CLI v0.15.0. The emerging direction is a **visual, Copilot-driven surface** — early work explores canvas dashboards for the Spec-Driven Development flow, a Bug Fix Pipeline, and `assess` — turning the CLI's flows into an interactive layer. [\[github.com\]](https://github.com/github/spec-kit-copilot) +- **The companion-tooling layer** — artgraph, SpecJudge, GAUNTLEX, and custom skills signal a third-party ecosystem forming on Spec Kit artifacts. The open question is whether the project absorbs these patterns (as it did drift → `converge`) or leaves them to the ecosystem; the verification/drift demand in the extension catalog suggests continued upstream pull. [\[github.com\]](https://github.com/github/spec-kit/releases) +- **Security and robustness as a standing discipline** — July's hardening wave (bounded reads, strict redirects, TOCTOU elimination, fail-loudly validation) shifted from feature to routine, and the signals point to it **continuing as an ongoing campaign** — a stdin read cap to close a DoS path and a broader atomicity push (atomic temp-file writes, subprocess timeouts, structured logging, and narrowed exception handlers). Sustaining the no-unbounded-read invariant as the surface (bundles, workflows, catalogs, events) grows is the ongoing work. [\[github.com\]](https://github.com/github/spec-kit/releases) +- **Experience simplification** — documentation proliferation and cognitive load remain the single most-cited concern across July's balanced reviews (ta_kawano, yutakaosada, and multiple Japanese/Korean pieces). The `assess` upstream gate, the lean/TinySpec presets, `/speckit.converge`, and the forming companion-tooling layer all provide answers; surfacing them to new users is the persistent opportunity. [\[note.com\]](https://note.com/takawano/n/ncb552ee37331) diff --git a/newsletters/2026-June.md b/newsletters/2026-June.md index 4693a83afe..acf58e408d 100644 --- a/newsletters/2026-June.md +++ b/newsletters/2026-June.md @@ -1,14 +1,14 @@ # Spec Kit - June 2026 Newsletter -This edition covers Spec Kit activity in June 2026 — a month of maturation and mainstream validation. Twenty-five releases shipped (v0.9.0 through v0.12.2), spanning four minor bumps and delivering two headline capabilities: the **`/speckit.converge` command**, which closes the loop between a spec and the code that implements it, and the new **`specify bundle` subsystem**, a role-based distribution layer that composes extensions, presets, workflows, and steps into a single installable unit. The workflow engine became programmable, the git extension went opt-in as the first real breaking change, and the ecosystem crossed **120+ community extensions**. Externally, June was the highest-volume press month on record — Microsoft's own Developer Blog published a first-party spec-driven development post, an enterprise reported 2–4× velocity gains, and 75 substantive articles appeared across 25+ languages. A summary is in the table below, followed by details. +This edition covers Spec Kit activity in June 2026 — a month of maturation and mainstream validation. Twenty-five releases shipped (v0.9.0 through v0.12.2), spanning four minor bumps and delivering two headline capabilities: the **`/speckit.converge` command**, which closes the loop between a spec and the code that implements it, and the new **`specify bundle` subsystem**, a role-based distribution layer that composes extensions, presets, workflows, and steps into a single installable unit. The workflow engine became programmable, the git extension went opt-in as the first real breaking change, and the ecosystem crossed **120+ community extensions**. Externally, June brought broad validation — Microsoft's own Developer Blog published a first-party spec-driven development post, an enterprise reported 2–4× velocity gains, and coverage spanned dozens of languages. A summary is in the table below, followed by details. | **Spec Kit Core (Jun 2026)** | **Community & Content** | **SDD Ecosystem & Next** | | --- | --- | --- | -| Twenty-five releases shipped (v0.9.0–v0.12.2) with key features: the `/speckit.converge` convergence loop, the `specify bundle` role-based packaging subsystem, a programmable workflow engine (step catalog, JSON output, `from_json`), the git extension becoming opt-in (`--no-git` removed), and six new agents (Cline, rovodev, Zed, Firebender, ZCode, omp). The repo grew from ~107k to **~116,500 stars**. [\[github.com\]](https://github.com/github/spec-kit/releases) | The community extension catalog grew from 105 to **124 entries**; presets reached **23**. Microsoft's Developer Blog published a first-party SDD post naming Spec Kit as the operationalizing toolkit. June was the highest-volume press month yet — **75 substantive articles** across 25+ languages. **245 contributors** now listed. | An enterprise (SNCF Connect & Tech) reported **2–4× velocity** from SDD. Analysts and comparisons increasingly name Spec Kit "the category anchor" and agent-neutral default. Competitors differentiate on brownfield and drift; balanced reviews continue to flag review-overload and ceremony for small tasks. | +| Twenty-five releases shipped (v0.9.0–v0.12.2) with key features: the `/speckit.converge` convergence loop, the `specify bundle` role-based packaging subsystem, a programmable workflow engine (step catalog, JSON output, `from_json`), the git extension becoming opt-in (`--no-git` removed), and six new agents (Cline, rovodev, Zed, Firebender, ZCode, omp). The repo grew from ~107k to **~116,500 stars**. [\[github.com\]](https://github.com/github/spec-kit/releases) | The community extension catalog grew from 105 to **124 entries**; presets reached **23**. Microsoft's Developer Blog published a first-party SDD post naming Spec Kit as the operationalizing toolkit. Press coverage spanned dozens of languages. **245 contributors** now listed. | An enterprise (SNCF Connect & Tech) reported **2–4× velocity** from SDD. Analysts and comparisons increasingly name Spec Kit "the category anchor" and agent-neutral default. Competitors differentiate on brownfield and drift; balanced reviews continue to flag review-overload and ceremony for small tasks. | *** -> **Spec-Driven Development, Institutionalized.** If May was defined by milestone 100s, June was defined by validation from outside the project. Microsoft's own Developer Blog published a first-party post presenting spec-driven development and positioning Spec Kit as the toolkit that operationalizes it. An enterprise — SNCF Connect & Tech — went on the record with **2–4× velocity gains** from adopting SDD. A record **75 substantive articles** appeared in more than 25 languages, and the recurring verdict across independent comparisons was that Spec Kit is "the category anchor" and the agent-neutral default. Meanwhile the core matured from v0.9 to v0.12: the workflow engine became genuinely programmable, the first real breaking change shipped, and the new convergence loop and bundle subsystem gave the project answers to its two most-cited gaps — drift and distribution. None of this happens without the community — the contributors, extension and preset authors, bundle builders, and practitioners writing in a dozen languages. Thank you. +> **Spec-Driven Development, Institutionalized.** If May was defined by milestone 100s, June was defined by validation from outside the project. Microsoft's own Developer Blog published a first-party post presenting spec-driven development and positioning Spec Kit as the toolkit that operationalizes it. An enterprise — SNCF Connect & Tech — went on the record with **2–4× velocity gains** from adopting SDD. Coverage appeared in dozens of languages, and the recurring verdict across independent comparisons was that Spec Kit is "the category anchor" and the agent-neutral default. Meanwhile the core matured from v0.9 to v0.12: the workflow engine became genuinely programmable, the first real breaking change shipped, and the new convergence loop and bundle subsystem gave the project answers to its two most-cited gaps — drift and distribution. None of this happens without the community — the contributors, extension and preset authors, bundle builders, and practitioners writing in a dozen languages. Thank you. ## Spec Kit Project Updates @@ -84,7 +84,7 @@ On **June 10**, the **Microsoft Developer Blog** published *"Spec-Driven Develop ### Press and Industry Coverage -June was the **highest-volume coverage month on record — 75 substantive articles** across more than 25 languages. +June's press coverage spanned dozens of languages and platforms. **Xebia / XPRT Magazine #21** (Hidde de Smet & Emanuele Bartolesi, June 17) published a 32-minute full six-command walkthrough covering both greenfield and brownfield, honest about markdown-review overhead and where spec quality becomes the bottleneck. [\[xebia.com\]](https://xebia.com/blog/building-software-with-spec-kit/) @@ -102,7 +102,7 @@ June was the **highest-volume coverage month on record — 75 substantive articl ### Developer Articles and Blog Posts -June's 75 articles skewed heavily multilingual, with deep hands-on series in Chinese, Japanese, and Korean, and a strong current of "which tool should I choose?" comparisons. +June's coverage skewed heavily multilingual, with deep hands-on series in Chinese, Japanese, and Korean, and a strong current of "which tool should I choose?" comparisons. Notable English-language articles: @@ -137,7 +137,7 @@ Coverage also appeared on TabNews (Portuguese), Habr and CSDN, note.com, Substac ### The Category Consolidates -Across June's record article volume, a consistent framing emerged: spec-driven development is now an established category, and Spec Kit is its reference implementation. SSOJet called it "the category anchor," Design News and multiple comparison pieces called it the agent-neutral default, and ToolTwist's CxO guide named it the "safe default for scaling teams." The Microsoft Developer Blog post and the SNCF enterprise interview extended that framing beyond the developer press into institutional and enterprise contexts. [\[ssojet.com\]](https://ssojet.com/blog/best-spec-driven-development-tools) +Across June's broad article coverage, a consistent framing emerged: spec-driven development is now an established category, and Spec Kit is its reference implementation. SSOJet called it "the category anchor," Design News and multiple comparison pieces called it the agent-neutral default, and ToolTwist's CxO guide named it the "safe default for scaling teams." The Microsoft Developer Blog post and the SNCF enterprise interview extended that framing beyond the developer press into institutional and enterprise contexts. [\[ssojet.com\]](https://ssojet.com/blog/best-spec-driven-development-tools) ### Competitive Landscape diff --git a/newsletters/2026-May.md b/newsletters/2026-May.md index 6e3e44f07c..a9c5d55ec0 100644 --- a/newsletters/2026-May.md +++ b/newsletters/2026-May.md @@ -4,7 +4,7 @@ This edition covers Spec Kit activity in May 2026 — a month defined by three m | **Spec Kit Core (May 2026)** | **Community & Content** | **SDD Ecosystem & Next** | | --- | --- | --- | -| Fourteen releases shipped with key features: multi-install for concurrent agent integrations, constitution governance in implement, authentication provider registry, Hermes and Lingma agents, and a `__init__.py` decomposition series. The repo grew from ~92k to **106,951 stars**, crossing **100K** on May 21. [\[github.com\]](https://github.com/github/spec-kit/releases) | The community extension catalog crossed **100 entries** (now 105). Open Source Friday livestream drove a press wave: Visual Studio Magazine, DevOps.com, MarkTechPost, HackerNoon, and 25+ more articles — now tracked across multiple languages following an expanded discovery methodology. **217 contributors** now listed. | MarkTechPost called Spec Kit "the most community-adopted open-source option" for SDD. The Futurum Group's Mitch Ashley framed specs as "the unit of governance across agents and contributors." Truong Phung published a 61-min production playbook referencing Spec Kit. Competitors grew but differentiate on orchestration; Spec Kit leads in portability and community. | +| Fourteen releases shipped with key features: multi-install for concurrent agent integrations, constitution governance in implement, authentication provider registry, Hermes and Lingma agents, and a `__init__.py` decomposition series. The repo grew from ~92k to **106,951 stars**, crossing **100K** on May 21. [\[github.com\]](https://github.com/github/spec-kit/releases) | The community extension catalog crossed **100 entries** (now 105). Open Source Friday livestream drove a press wave: Visual Studio Magazine, DevOps.com, MarkTechPost, HackerNoon, and many more across multiple languages. **217 contributors** now listed. | MarkTechPost called Spec Kit "the most community-adopted open-source option" for SDD. The Futurum Group's Mitch Ashley framed specs as "the unit of governance across agents and contributors." Truong Phung published a 61-min production playbook referencing Spec Kit. Competitors grew but differentiate on orchestration; Spec Kit leads in portability and community. | *** @@ -76,7 +76,7 @@ May produced the broadest press coverage to date, with publications from the mai ### Developer Articles and Blog Posts -May produced a wave of independent coverage — well beyond any previous month. Starting this month, article discovery was expanded beyond English-centric search engines to include language-appropriate engines for 25+ languages, so the broader coverage partly reflects wider discovery rather than a sudden spike. +May produced a wave of independent coverage across many languages. Notable non-English coverage: diff --git a/pyproject.toml b/pyproject.toml index 0bed0e417f..cc03998617 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "agentic-sdlc-specify-cli" -version = "0.15.1+adlc1" +version = "0.15.2+adlc2" description = "Specify CLI (tikalk fork). Agentic SDLC toolkit for Spec-Driven Development with pre-installed extensions and AI integrations." readme = "README.md" requires-python = ">=3.11" diff --git a/src/specify_cli/__init__.py b/src/specify_cli/__init__.py index 6a955c7e2c..8fdb6baeab 100644 --- a/src/specify_cli/__init__.py +++ b/src/specify_cli/__init__.py @@ -78,7 +78,9 @@ from ._agent_config import ( AGENT_CONFIG as AGENT_CONFIG, DEFAULT_INIT_INTEGRATION as DEFAULT_INIT_INTEGRATION, + DEFAULT_INIT_INTEGRATION_ENV_VAR as DEFAULT_INIT_INTEGRATION_ENV_VAR, SCRIPT_TYPE_CHOICES as SCRIPT_TYPE_CHOICES, + resolve_default_init_integration as resolve_default_init_integration, ) from ._init_options import ( INIT_OPTIONS_FILE as INIT_OPTIONS_FILE, diff --git a/src/specify_cli/_agent_config.py b/src/specify_cli/_agent_config.py index 3befc19643..0f82824271 100644 --- a/src/specify_cli/_agent_config.py +++ b/src/specify_cli/_agent_config.py @@ -1,6 +1,8 @@ """Agent configuration constants derived from the integration registry.""" from __future__ import annotations +import os +import sys from typing import Any @@ -17,6 +19,36 @@ def _build_agent_config() -> dict[str, dict[str, Any]]: DEFAULT_INIT_INTEGRATION = "copilot" +#: Environment variable used to override the fallback integration that +#: ``specify init`` selects in non-interactive sessions. Follows the existing +#: ``SPECKIT_INTEGRATION_*`` namespace (see ``SPECKIT_INTEGRATION__EXECUTABLE`` +#: and ``SPECKIT_INTEGRATION_CATALOG_URL``). +DEFAULT_INIT_INTEGRATION_ENV_VAR = "SPECKIT_INTEGRATION_DEFAULT" + + +def resolve_default_init_integration() -> str: + """Return the default init integration, honoring an env-var override. + + Reads :data:`DEFAULT_INIT_INTEGRATION_ENV_VAR` + (``SPECKIT_INTEGRATION_DEFAULT``). When it names a registered integration + key, that key is returned; otherwise the hardcoded + :data:`DEFAULT_INIT_INTEGRATION` (``"copilot"``) is used. An invalid value + emits a warning to stderr rather than silently falling back, so operators + can tell a typo from an intentional default. + """ + override = (os.environ.get(DEFAULT_INIT_INTEGRATION_ENV_VAR) or "").strip() + if not override: + return DEFAULT_INIT_INTEGRATION + if override in AGENT_CONFIG: + return override + print( + f"Warning: {DEFAULT_INIT_INTEGRATION_ENV_VAR}='{override}' is not a " + f"recognized integration; falling back to '{DEFAULT_INIT_INTEGRATION}'. " + f"Choose from: {', '.join(sorted(AGENT_CONFIG.keys()))}.", + file=sys.stderr, + ) + return DEFAULT_INIT_INTEGRATION + SCRIPT_TYPE_CHOICES: dict[str, str] = { "sh": "POSIX Shell (bash/zsh)", "ps": "PowerShell", diff --git a/src/specify_cli/agents.py b/src/specify_cli/agents.py index 0e27d2df6b..6b06269467 100644 --- a/src/specify_cli/agents.py +++ b/src/specify_cli/agents.py @@ -708,7 +708,7 @@ def register_commands( _integ = get_integration(agent_name) if _integ is not None: _sep = _integ.invoke_separator_for_mode(registrar_writes_skills) - except Exception: + except (ImportError, ValueError, KeyError): pass _prefix = get_invocation_prefix(agent_name, registrar_writes_skills) diff --git a/src/specify_cli/commands/bundle/__init__.py b/src/specify_cli/commands/bundle/__init__.py index 2cf3c3d5ad..7bfb1b3556 100644 --- a/src/specify_cli/commands/bundle/__init__.py +++ b/src/specify_cli/commands/bundle/__init__.py @@ -154,13 +154,13 @@ def _run_init(integration: str, *, script_type: str, offline: bool = False) -> N def _resolve_init_integration(override: str | None, manifest) -> str: """Precedence (FR-013): explicit override → bundle-declared → default.""" - from ..._agent_config import DEFAULT_INIT_INTEGRATION + from ..._agent_config import resolve_default_init_integration if override: return override if manifest is not None and manifest.integration is not None: return manifest.integration.id - return DEFAULT_INIT_INTEGRATION + return resolve_default_init_integration() # ===== Consume ===== diff --git a/src/specify_cli/commands/event.py b/src/specify_cli/commands/event.py index 764fde7f6b..d1576c2c70 100644 --- a/src/specify_cli/commands/event.py +++ b/src/specify_cli/commands/event.py @@ -24,8 +24,19 @@ def event_run( """Resolve and run an event-driven command script with stdin payload.""" from ..events import resolve_and_run_event_command - # Read payload from stdin if available - payload = sys.stdin.read() if not sys.stdin.isatty() else "{}" + # Read payload from stdin if available (capped at 1 MiB to prevent DoS). + MAX_STDIN_BYTES = 1 * 1024 * 1024 + if not sys.stdin.isatty(): + raw = sys.stdin.read(MAX_STDIN_BYTES) + if not sys.stdin.eof: + raise typer.Exit( + code=1, + message="stdin payload exceeds 1 MiB limit; " + "truncate or pipe a smaller payload", + ) + payload = raw + else: + payload = "{}" # Run the event command project_root = Path.cwd() # The agent runs events from project root diff --git a/src/specify_cli/commands/init.py b/src/specify_cli/commands/init.py index 3ede377296..c04b803c86 100644 --- a/src/specify_cli/commands/init.py +++ b/src/specify_cli/commands/init.py @@ -14,8 +14,8 @@ from .._agent_config import ( AGENT_CONFIG, - DEFAULT_INIT_INTEGRATION, SCRIPT_TYPE_CHOICES, + resolve_default_init_integration, ) from .._assets import ( _locate_bundled_workflow, @@ -444,12 +444,13 @@ def init( "Template files will be merged with existing content " "and may overwrite existing files. Do you want to continue?" ) - except (typer.Abort, EOFError): + except (typer.Abort, EOFError, OSError): # typer.confirm raises Abort for BOTH an interactive Ctrl+C # and an EOF on closed/empty stdin. Distinguish them: a real # TTY cancellation is a normal exit (0, "cancelled"), while a # missing-input EOF (non-interactive) becomes an actionable - # error pointing at --force. + # error pointing at --force. OSError (e.g. BrokenPipeError) + # is treated the same as EOF — stdin is unusable. if _stdin_is_interactive(): console.print("[yellow]Operation cancelled[/yellow]") raise typer.Exit(0) from None @@ -498,17 +499,18 @@ def init( raise typer.Exit(1) selected_ai = integration elif not _stdin_is_interactive(): + default_integration = resolve_default_init_integration() console.print( - f"[dim]Non-interactive session detected: defaulting to '{DEFAULT_INIT_INTEGRATION}'. " + f"[dim]Non-interactive session detected: defaulting to '{default_integration}'. " "Use --integration to choose a different agent.[/dim]" ) - selected_ai = DEFAULT_INIT_INTEGRATION + selected_ai = default_integration else: ai_choices = {key: config["name"] for key, config in AGENT_CONFIG.items()} selected_ai = select_with_arrows( ai_choices, "Choose your coding agent integration:", - DEFAULT_INIT_INTEGRATION, + resolve_default_init_integration(), ) if not integration: diff --git a/src/specify_cli/events.py b/src/specify_cli/events.py index 98e49aee36..96405a7391 100644 --- a/src/specify_cli/events.py +++ b/src/specify_cli/events.py @@ -251,7 +251,7 @@ def _resolve_argv(template_path, project_root, ext_id): return [str(script_abs), *rest] -def _run_inline(command_name, payload, project_root, timeout): +def _run_inline(command_name, payload, project_root, timeout, envelope="plain", native_event=""): """Resolve and run the event command with stdlib only (no specify_cli).""" template_path, ext_id = _find_command_template(command_name, project_root) if not template_path: @@ -269,7 +269,7 @@ def _run_inline(command_name, payload, project_root, timeout): cwd=str(project_root), ) if result.stdout: - sys.stdout.write(result.stdout) + _emit(result.stdout, envelope, native_event) if result.returncode != 0: if result.stderr: sys.stderr.write(result.stderr) @@ -283,6 +283,46 @@ def _run_inline(command_name, payload, project_root, timeout): return 2 +def _emit(output, envelope, native_event=""): + """Write handler output to stdout in the agent's context-injection shape. + + Not every agent injects a hook's plain-text stdout as model context: + Gemini/Tabnine/Qwen/Devin are JSON-only protocols (plain text becomes + user-facing noise, never context), Copilot discards non-JSON stdout, and + Cursor parses stdout as JSON. The native hook command passes the envelope + as the dispatcher's 5th argument (see events_context_envelope on the + integration classes), and the native event name as the 6th argument so + hookSpecificOutput can include hookEventName: + + hookSpecificOutput → {"hookSpecificOutput": {"hookEventName": ..., "additionalContext": ...}} + additionalContext → {"additionalContext": ...} (top-level, Copilot) + additional_context → {"additional_context": ...} (top-level, Cursor) + suppress → emit nothing (strict-JSON agents on events whose + output can't be used) + plain (default) → passthrough (Claude/Codex inject plain stdout) + + Empty output emits nothing under any envelope (an empty additionalContext + is useless noise). + """ + if not output: + return + if envelope == "suppress": + return + if envelope == "hookSpecificOutput": + payload = {"additionalContext": output} + if native_event: + payload["hookEventName"] = native_event + sys.stdout.write(json.dumps({"hookSpecificOutput": payload}) + "\\n") + return + if envelope == "additionalContext": + sys.stdout.write(json.dumps({"additionalContext": output}) + "\\n") + return + if envelope == "additional_context": + sys.stdout.write(json.dumps({"additional_context": output}) + "\\n") + return + sys.stdout.write(output) + + def main(): if len(sys.argv) < 3: sys.exit(0) @@ -297,6 +337,16 @@ def main(): timeout = int(sys.argv[3]) except (TypeError, ValueError): timeout = 120 + # Optional 5th arg: context-injection envelope for stdout (C13): plain + # (default), hookSpecificOutput, additionalContext, additional_context, + # or suppress. Unknown values fall back to plain passthrough. + envelope = sys.argv[4] if len(sys.argv) >= 5 else "plain" + if envelope not in ("plain", "hookSpecificOutput", "additionalContext", "additional_context", "suppress"): + envelope = "plain" + # Optional 6th arg: native event name for hookSpecificOutput's + # hookEventName field (required by Qwen's hooks spec; included by + # Gemini/Tabnine/Devin which derive from the same protocol). + native_event = sys.argv[5] if len(sys.argv) >= 6 else "" payload = sys.stdin.read() if not sys.stdin.isatty() else "{}" project_root = Path(__file__).parent.parent.resolve() @@ -307,14 +357,14 @@ def main(): from specify_cli.events import resolve_and_run_event_command sys.exit( resolve_and_run_event_command( - command_name, _event_name, payload, project_root, timeout=timeout + command_name, _event_name, payload, project_root, timeout=timeout, envelope=envelope, native_event=native_event ) ) - except ImportError: + except (ImportError, TypeError): pass # Fallback: self-contained stdlib resolver (one-time/temporary installs). - sys.exit(_run_inline(command_name, payload, project_root, timeout)) + sys.exit(_run_inline(command_name, payload, project_root, timeout, envelope, native_event)) if __name__ == "__main__": @@ -362,17 +412,21 @@ def main(): ) as string; }} -function runEvent(command: string, event: string, input: any, output: any, timeoutSec: number): void {{ - if (!DISPATCHER) return; +function runEvent(command: string, event: string, input: any, output: any, timeoutSec: number): string {{ + if (!DISPATCHER) return ''; try {{ // execFileSync with an argv array invokes the interpreter directly — no // shell — so command/event strings with metacharacters can't break out // of the dispatcher argument (C9). The dispatcher arg is seconds; the // execFileSync timeout is ms with a buffer so the outer cap fires after - // the dispatcher's inner subprocess (S3). - execFileSync(INTERPRETER, [DISPATCHER, command, event, String(timeoutSec)], {{ + // the dispatcher's inner subprocess (S3). stdout is captured and + // returned so context-injection hooks (experimental.chat.system.transform, + // chat.message) can push it into their outputs; stderr stays inherited so + // dispatcher errors remain visible (C11). + return execFileSync(INTERPRETER, [DISPATCHER, command, event, String(timeoutSec)], {{ input: JSON.stringify({{ input, output }}), - stdio: ['pipe', 'inherit', 'inherit'], + stdio: ['pipe', 'pipe', 'inherit'], + encoding: 'utf-8', timeout: (timeoutSec + {buffer}) * 1000, }}); }} catch (e) {{ @@ -382,6 +436,12 @@ def main(): }} }} +// Cache session_start handler output per sessionID so non-idempotent +// handlers (setup, telemetry, file-mutating scripts) run once per session +// instead of on every LLM request (experimental.chat.system.transform +// fires per LLM turn). Evicted on session.deleted. +const sessionStartCache = new Map(); + {event_entries} export default (async ({{ client, project, directory, $ }}) => {{ @@ -524,7 +584,13 @@ def _resolve_event_command_argv( else: base = project_root / ".specify" - tokens = shlex.split(script_cmd, posix=(os.name != "nt")) + try: + tokens = shlex.split(script_cmd, posix=(os.name != "nt")) + except ValueError: + # Mirror the generated dispatcher's _resolve_argv: a scripts: value + # shlex cannot tokenize (e.g. an unclosed quote) declares no runnable + # script, so degrade to "no argv" instead of raising. + return None if not tokens: return None script_abs = base / tokens[0] @@ -585,12 +651,26 @@ def resolve_and_run_event_command( project_root: Path, *, timeout: int = 120, + envelope: str = "plain", + native_event: str = "", ) -> int: """Core entry point to resolve and execute an event-driven command. *timeout* is the per-handler timeout in seconds, passed through from the native hook config via the dispatcher (S4) so a handler configured above the previous fixed 120s cap can run for its full duration. + + *envelope* selects how the handler's stdout is emitted for the agent's + context-injection protocol (C13): ``plain`` passthrough (Claude/Codex + inject plain stdout), ``hookSpecificOutput``/``additionalContext``/ + ``additional_context`` JSON wrappers (Gemini/Tabnine/Qwen/Devin, Copilot, + Cursor respectively), or ``suppress`` (strict-JSON agents on events whose + output can't be used). + + *native_event* is the agent's native hookEventName (e.g. ``"SessionStart"``), + required inside ``hookSpecificOutput`` by Qwen's hooks spec (and included + by the Claude Code hooks spec Gemini/Tabnine/Devin derive from). Only + used when *envelope* is ``hookSpecificOutput``. """ template_path, ext_id = _find_command_template(command_name, project_root) if not template_path: @@ -610,7 +690,7 @@ def resolve_and_run_event_command( cwd=str(project_root), ) if result.stdout: - sys.stdout.write(result.stdout) + _emit_event_stdout(result.stdout, envelope, native_event) if result.returncode != 0: if result.stderr: sys.stderr.write(result.stderr) @@ -624,6 +704,35 @@ def resolve_and_run_event_command( return 2 +def _emit_event_stdout(output: str, envelope: str, native_event: str = "") -> None: + """Write handler stdout in the agent's context-injection shape (C13). + + Mirrors the ``_emit`` helper inside the generated dispatcher template; + keep both in sync. Empty output emits nothing under any envelope. + + *native_event* is the agent's native hookEventName, required inside + ``hookSpecificOutput`` by Qwen's hooks spec (and included by the + Claude Code hooks spec Gemini/Tabnine/Devin derive from). + """ + if not output: + return + if envelope == "suppress": + return + if envelope == "hookSpecificOutput": + payload = {"additionalContext": output} + if native_event: + payload["hookEventName"] = native_event + sys.stdout.write(json.dumps({"hookSpecificOutput": payload}) + "\n") + return + if envelope == "additionalContext": + sys.stdout.write(json.dumps({"additionalContext": output}) + "\n") + return + if envelope == "additional_context": + sys.stdout.write(json.dumps({"additional_context": output}) + "\n") + return + sys.stdout.write(output) + + # -- Sourcing events map (CLI/Orchestration domain) ------------------------- # Resolved events map: each canonical event name maps to an *ordered list* of @@ -737,8 +846,10 @@ def resolve_events( if override_file.exists(): try: override = yaml.safe_load(override_file.read_text(encoding="utf-8")) or {} - except yaml.YAMLError: - logger.warning("Could not parse %s; ignoring override", override_file) + except (OSError, UnicodeError, yaml.YAMLError): + logger.warning( + "Could not read or parse %s; ignoring override", override_file + ) override = {} integrations = override.get("integrations", {}) if isinstance(override, dict) else {} if isinstance(integrations, dict) and integration_key in integrations: @@ -895,7 +1006,7 @@ def collect_extension_events(project_root: Path) -> ResolvedEvents: continue try: data = yaml.safe_load(ext_yml.read_text(encoding="utf-8")) or {} - except yaml.YAMLError: + except (UnicodeDecodeError, yaml.YAMLError): continue if not isinstance(data, dict): continue @@ -1016,7 +1127,17 @@ def _dispatcher_command( When *timeout_seconds* is given, the resolved timeout (in the integration's native unit) is appended as a 4th argument so the dispatcher and inner runner honor the per-handler timeout instead of a fixed 120s cap - that would kill a handler configured for longer (S4). + that would kill a handler configured for longer (S4). When omitted, a + default of 60s is emitted so the positional argument order + (command event timeout envelope native_event) stays aligned — otherwise + the envelope would land in the timeout slot and the dispatcher would + silently fall back to plain stdout. + + When the integration declares a context-injection envelope for this + canonical event (``events_context_envelope``, C13), the envelope token is + appended as a 5th argument so the dispatcher wraps stdout in the JSON + shape the agent's hook protocol requires. Plain-passthrough agents + (Claude/Codex) declare no envelope and get no extra argument. """ if target_os == "host": interpreter = _resolve_interpreter(project_root) @@ -1036,16 +1157,44 @@ def _dispatcher_command( # operator. Prefix & for the explicit windows target only. prefix = "& " if target_os == "windows" else "" base = f"{prefix}{q_interp} {dispatcher} {q_command} {q_event}" - if timeout_seconds is not None: - # R2: the dispatcher interprets this argument as seconds, so pass the - # raw seconds — NOT _native_timeout(...) (which converts to ms for - # Gemini/Qwen/Tabnine and would yield 60000 seconds). The buffer is - # applied to the native hook timeout field (in the adapter formatters) - # so the agent's outer cap fires after the inner subprocess timeout. - base += f" {_shell_quote(str(int(timeout_seconds)), target_os)}" + # Always emit the timeout (4th positional arg) so the dispatcher's argv + # parsing stays aligned when an envelope (5th) or native_event (6th) + # follows. Without it the envelope would land in the timeout slot and + # the dispatcher would fall back to plain stdout (R3). + resolved_timeout = 60 if timeout_seconds is None else int(timeout_seconds) + # R2: the dispatcher interprets this argument as seconds, so pass the + # raw seconds — NOT _native_timeout(...) (which converts to ms for + # Gemini/Qwen/Tabnine and would yield 60000 seconds). The buffer is + # applied to the native hook timeout field (in the adapter formatters) + # so the agent's outer cap fires after the inner subprocess timeout. + base += f" {_shell_quote(str(resolved_timeout), target_os)}" + envelope = _context_envelope_for(integration, event_name) + if envelope: + base += f" {_shell_quote(envelope, target_os)}" + # hookSpecificOutput requires the native hookEventName inside the + # envelope (Qwen's hooks spec marks it mandatory; the Claude Code + # hooks spec that Gemini/Tabnine/Devin derive from includes it). + # Append the native event name as a 6th dispatcher argument so the + # dispatcher can populate hookEventName in the JSON output. + if envelope == "hookSpecificOutput": + native_event = getattr(integration, "CANONICAL_TO_NATIVE", {}).get(event_name, "") + if native_event: + base += f" {_shell_quote(native_event, target_os)}" return base +def _context_envelope_for(integration: IntegrationBase, canonical_event: str) -> str | None: + """Resolve the context-injection envelope for an integration + event (C13). + + The event key wins; ``"*"`` is the fallback. Returns ``None`` when the + integration declares no envelope for the event (plain stdout passthrough). + """ + mapping = getattr(integration, "events_context_envelope", None) or {} + if canonical_event in mapping: + return mapping[canonical_event] + return mapping.get("*") + + def install_integration_events( integration: IntegrationBase, project_root: Path, @@ -1193,11 +1342,12 @@ def install_integration_events( lines.append(f'timeout = {_native_timeout(integration, cfg.get("timeout", 60) + EVENT_TIMEOUT_BUFFER)}') lines.append('speckit_marker = true') lines.append('') - _merge_toml_fragment(config_path, "\n".join(lines)) - rel = str(config_path.relative_to(project_root)) - if rel not in manifest.files: - manifest.record_existing(rel) - created.append(config_path) + # S5: only track when the merge wrote (skips on unreadable file). + if _merge_toml_fragment(config_path, "\n".join(lines)): + rel = str(config_path.relative_to(project_root)) + if rel not in manifest.files: + manifest.record_existing(rel) + created.append(config_path) elif fmt == "json-flat": # Cursor hooks.json custom merge. Flat command-string entries, one @@ -1588,6 +1738,14 @@ def _build_opencode_plugin( an argv array (C9). Both the ``input`` and ``output`` callback arguments are forwarded to ``runEvent`` (C7) so pre_tool_use can inspect tool arguments and post_tool_use can inspect the result. + + Context-injection natives get dedicated hook bodies: for + ``experimental.chat.system.transform`` the handlers' concatenated stdout + is pushed into ``output.system`` (system-prompt injection, re-applied per + LLM request so the context survives compaction); for ``chat.message`` it + is pushed as a synthetic text part on the user message (C11). Other + natives keep their side-effect behavior (tool.execute.* args mutation; + session.* lifecycle events via the generic ``event`` hook). """ event_entries: list[str] = [] plugin_returns: list[str] = [] @@ -1602,11 +1760,16 @@ def _build_opencode_plugin( ev_lit = json.dumps(ev) native_lit = json.dumps(native) + is_injection = native in ("experimental.chat.system.transform", "chat.message") + # Build the body: one runEvent() call per handler wrapped in try/catch, # forwarding both input and output (C7). An optional tool-name matcher # guard applies to tool.execute.* hooks. All handlers execute before - # any aggregate error is thrown. + # any aggregate error is thrown. Injection hooks additionally collect + # each handler's stdout and return the concatenation. body_lines: list[str] = [" const errors: string[] = [];"] + if is_injection: + body_lines.append(" const contexts: string[] = [];") for cfg in handlers: command = str(cfg.get("command", "")) command_lit = json.dumps(command) @@ -1628,6 +1791,10 @@ def _build_opencode_plugin( body_lines.append( f" try {{ runEvent({command_lit}, {ev_lit}, input, output, {timeout_sec}); }} catch (e) {{ errors.push((e as Error).message); }}" ) + elif is_injection: + body_lines.append( + f" try {{ const ctx = runEvent({command_lit}, {ev_lit}, input, output, {timeout_sec}); if (ctx) contexts.push(ctx); }} catch (e) {{ errors.push((e as Error).message); }}" + ) else: body_lines.append( f" try {{ runEvent({command_lit}, {ev_lit}, input, output, {timeout_sec}); }} catch (e) {{ errors.push((e as Error).message); }}" @@ -1646,14 +1813,65 @@ def _build_opencode_plugin( f" _{ev}(input, output);\n" f" }}," ) + elif native == "experimental.chat.system.transform": + body_lines.append(' return contexts.join("\\n\\n");') + event_entries.append( + f"function _{ev}(input: any, output: any): string {{\n" + + "\n".join(body_lines) + "\n" + " }" + ) + # OpenCode fires experimental.chat.system.transform for non-session + # operations (e.g. agent generation) with no sessionID. Guard so + # canonical session_start handlers only run when a session is + # present, preventing their output from being injected into + # internal prompts. Cache the handler output per sessionID so + # non-idempotent handlers (setup, telemetry, file-mutating + # scripts) execute once per session instead of on every LLM + # request; the cache is evicted on session.deleted. + plugin_returns.append( + f" {native_lit}: async (input: any, output: any) => {{\n" + f" if (!input.sessionID) return;\n" + f" let ctx = sessionStartCache.get(input.sessionID);\n" + f" if (ctx === undefined) {{\n" + f" ctx = _{ev}(input, output);\n" + f" sessionStartCache.set(input.sessionID, ctx ?? \"\");\n" + f" }}\n" + f" if (ctx) output.system.push(ctx);\n" + f" }}," + ) + elif native == "chat.message": + body_lines.append(' return contexts.join("\\n\\n");') + event_entries.append( + f"function _{ev}(input: any, output: any): string {{\n" + + "\n".join(body_lines) + "\n" + " }" + ) + # Part id must start with "prt" (opencode's Identifier brand): an + # invalid id fails the user-part schema validation and crashes the + # whole session (C12). Derive it from the last existing part so the + # brand survives an opencode prefix change, falling back to "prt_" + # when output.parts is empty. + plugin_returns.append( + f" {native_lit}: async (input: any, output: any) => {{\n" + f" const ctx = _{ev}(input, output);\n" + f" if (!ctx) return;\n" + f" const base = output.parts[output.parts.length - 1]?.id ?? \"prt_\" + Date.now().toString(36) + Math.random().toString(36).slice(2, 10);\n" + f" output.parts.push({{ id: base + \".speckit\" + Math.random().toString(36).slice(2, 8), sessionID: input.sessionID, messageID: output.message.id, type: \"text\", text: ctx, synthetic: true }});\n" + f" }}," + ) else: event_entries.append( f"function _{ev}(input: any, output: any) {{\n" + "\n".join(body_lines) + "\n" " }" ) + # Evict the sessionStartCache when the session is deleted so the + # cache doesn't grow unbounded across sessions. + eviction = "" + if native == "session.deleted": + eviction = "if (event.sessionID) sessionStartCache.delete(event.sessionID); " event_handlers.append( - f" if (event.type === {native_lit}) {{ _{ev}(event, event); }}" + f" if (event.type === {native_lit}) {{ {eviction}_{ev}(event, event); }}" ) if event_handlers: @@ -1715,11 +1933,27 @@ def _remove_opencode_entries(config_path: Path) -> bool: return False -def _merge_toml_fragment(dst: Path, fragment: str) -> None: +def _merge_toml_fragment(dst: Path, fragment: str) -> bool: + """Merge Specify-owned TOML entries into *dst*, regenerating the file. + + An unreadable or undecodable pre-existing file aborts the merge instead + of discarding the user's bytes, mirroring ``_load_user_json`` (#22). + Returns False when skipped so callers avoid tracking the untouched file + (S5). + """ _ensure_safe_destination(dst) existing = "" if dst.exists(): - existing = dst.read_text(encoding="utf-8") + try: + existing = dst.read_text(encoding="utf-8") + except (OSError, UnicodeDecodeError) as exc: + logger.warning( + "Could not read %s (it may be unreadable or not UTF-8); " + "skipping event-config merge to preserve user content.", + dst, + ) + logger.debug("Read error detail: %s", exc) + return False existing = re.sub( r'\[\[hooks\.\w+\]\]\n(?:(?!\[\[hooks\.\w+\]\]).)*?speckit_marker = true\n*', "", @@ -1728,6 +1962,7 @@ def _merge_toml_fragment(dst: Path, fragment: str) -> None: ) dst.parent.mkdir(parents=True, exist_ok=True) dst.write_text(existing.rstrip() + "\n\n" + fragment + "\n", encoding="utf-8") + return True def _remove_toml_entries(dst: Path) -> bool: @@ -1741,7 +1976,19 @@ def _remove_toml_entries(dst: Path) -> bool: # the config after install can't make teardown overwrite a file outside # the project (the merge/write path already validates; teardown must too). _ensure_safe_destination(dst) - existing = dst.read_text(encoding="utf-8") + try: + existing = dst.read_text(encoding="utf-8") + except (OSError, UnicodeDecodeError) as exc: + # An unreadable or undecodable file is left untouched rather than + # crashing teardown — it contains only user content as far as we can + # tell, and the caller drops the manifest claim either way (S9). + logger.warning( + "Could not read %s (it may be unreadable or not UTF-8); " + "skipping event-config cleanup to preserve user content.", + dst, + ) + logger.debug("Read error detail: %s", exc) + return False cleaned = re.sub( r'\[\[hooks\.\w+\]\]\n(?:(?!\[\[hooks\.\w+\]\]).)*?speckit_marker = true\n*', "", diff --git a/src/specify_cli/extensions/__init__.py b/src/specify_cli/extensions/__init__.py index ffaf184609..fa764d0f1c 100644 --- a/src/specify_cli/extensions/__init__.py +++ b/src/specify_cli/extensions/__init__.py @@ -305,9 +305,25 @@ def _validate(self): raise ValidationError( f"Invalid extension: expected a mapping, got {type(ext).__name__}" ) + # Check presence AND type: the format/version checks below feed these + # values straight to ``re.match`` and ``packaging.Version``, both of + # which raise a bare TypeError on a non-string. YAML makes that an easy + # authoring slip -- unquoted ``version: 1.0`` parses as a float and + # ``id: 2`` as an int -- and TypeError is not a ValidationError, so it + # escapes every caller that already handles a malformed manifest (see + # list_installed()'s "Corrupted extension" fallback, which catches + # ValidationError only, making one bad extension exit ``specify + # extension list`` with a raw traceback and hide the healthy ones). + # Mirrors the sibling IntegrationDescriptor, which already type-checks + # the same four fields. for field in ["id", "name", "version", "description"]: if field not in ext: raise ValidationError(f"Missing extension.{field}") + if not isinstance(ext[field], str): + raise ValidationError( + f"Invalid extension.{field}: expected a string, " + f"got {type(ext[field]).__name__}" + ) # Validate extension ID format if not re.match(r"^[a-z0-9-]+$", ext["id"]): @@ -345,6 +361,25 @@ def _validate(self): ) if "speckit_version" not in requires: raise ValidationError("Missing requires.speckit_version") + # Presence alone is not enough: check_compatibility() feeds this value to + # ``SpecifierSet(required)``, guarded only by ``except InvalidSpecifier``, + # which a non-string escapes two different ways. A float/int/bool/None + # raises TypeError from the constructor, while a list or dict is an + # *iterable*, so SpecifierSet accepts it and the failure surfaces much + # later as ``AttributeError: 'str' object has no attribute 'filter'`` from + # inside .contains(). Neither is a CompatibilityError, so both bypass the + # CLI's "Compatibility Error" handler and exit 1 with a raw traceback + # naming no field. An unquoted ``speckit_version: 1.0`` is an easy YAML + # slip. Mirrors the sibling IntegrationDescriptor, which already requires + # a non-empty string here. + if ( + not isinstance(requires["speckit_version"], str) + or not requires["speckit_version"].strip() + ): + raise ValidationError( + "Invalid requires.speckit_version: expected a non-empty string, " + f"got {type(requires['speckit_version']).__name__}" + ) # Validate provides section provides = self.data["provides"] @@ -411,6 +446,16 @@ def _validate(self): ) if "name" not in cmd or "file" not in cmd: raise ValidationError("Command missing 'name' or 'file'") + # The pattern match below would raise a bare TypeError on a + # non-string name (``name: 2``), escaping the ValidationError + # contract. The 'file' field needs no check here: + # relative_extension_path_violation() below already rejects a + # non-string value. + if not isinstance(cmd["name"], str): + raise ValidationError( + f"Invalid command name: expected a string, " + f"got {type(cmd['name']).__name__}" + ) # Validate the 'file' field at manifest-load time using the single # shared policy in relative_extension_path_violation(), so manifest @@ -582,6 +627,14 @@ def commands(self) -> List[Dict[str, Any]]: """Get list of provided commands.""" return self.data.get("provides", {}).get("commands", []) + @property + def config(self) -> List[Dict[str, Any]]: + """Get list of provided config templates, normalized to dictionaries.""" + raw = self.data.get("provides", {}).get("config", []) + if not isinstance(raw, list) or not all(isinstance(entry, dict) for entry in raw): + return [] + return raw + @property def hooks(self) -> Dict[str, Any]: """Get hook definitions.""" @@ -1874,6 +1927,17 @@ def check_compatibility( required = manifest.requires_speckit_version # Parse version specifier (e.g., ">=0.1.0,<2.0.0") + # Defense in depth: the manifest validator now rejects a non-string + # requires.speckit_version, but this method is public and also reachable + # with a hand-built manifest object. ``InvalidSpecifier`` alone does not + # cover a non-string -- scalars raise TypeError from the constructor, and + # a list/dict is iterable so it constructs here and only breaks inside + # .contains(). Reject up front so this always reports a CompatibilityError. + if not isinstance(required, str): + raise CompatibilityError( + "Invalid version specifier: expected a string, got " + f"{type(required).__name__} ({required!r})" + ) try: SpecifierSet(required) # Just to validate except InvalidSpecifier: @@ -2116,8 +2180,19 @@ def _matches_source_config_baseline(config_name: str) -> bool: _staged_modes = _loaded_modes for staged_name in sorted(staged_names): staged_file = rescue_staging_dir / staged_name - staged_stat = staged_file.stat() - staged_bytes = staged_file.read_bytes() + # A staged backup that cannot be read or stat'ed must not + # crash the retry with a raw OSError: like an uncomparable + # live config below, treat it as a conflict so both copies + # are preserved and the user resolves it while dest_dir is + # still untouched. Every sibling read in this path (live + # twin, packaged baseline, mode sidecar) already catches + # OSError. + try: + staged_stat = staged_file.stat() + staged_bytes = staged_file.read_bytes() + except OSError: + conflicting.add(staged_name) + continue # Prefer the sidecar-recorded mode; fall back to the staged # file's own mode for backwards-compat with staging dirs # written before the sidecar was introduced. @@ -2209,10 +2284,24 @@ def _matches_source_config_baseline(config_name: str) -> bool: "a regular file or remove it — then reinstall." ) if cfg_file.is_file(): - stranded_configs[cfg_file.name] = ( - cfg_file.read_bytes(), - cfg_file.stat().st_mode, - ) + # A kept config that cannot be read or stat'ed must not + # crash the reinstall with a raw OSError — and must not + # reach the rmtree below unrescued. Like the symlink + # guard above, reject while dest_dir is untouched so the + # preserved bytes are never lost. + try: + stranded_configs[cfg_file.name] = ( + cfg_file.read_bytes(), + cfg_file.stat().st_mode, + ) + except OSError as exc: + raise ValidationError( + "Preserved extension config for " + f"'{manifest.id}' cannot be read " + f"({cfg_file.name}) in {dest_dir}: {exc}. " + "Resolve manually — fix its permissions or " + "remove it — then reinstall." + ) from exc if stranded_configs and not staging_is_complete: # Write a durable backup outside dest_dir before any @@ -2555,6 +2644,149 @@ def install_from_archive( extension_dir, speckit_version, priority=priority, force=force ) + def _config_root_is_contained(self, specify_dir: Path) -> bool: + """Report whether `.specify` is a real directory inside the project. + + Checked component by component so a symlink anywhere on the path is + rejected before it becomes the containment root. A missing `.specify` + is fine: scaffolding creates it under the project root. + """ + try: + root = self.project_root.resolve() + except OSError: + return False + current = self.project_root + for part in specify_dir.relative_to(self.project_root).parts: + current = current / part + if current.is_symlink(): + return False + if not current.exists(): + return True + try: + if current.resolve().relative_to(root) is None: + return False + except (OSError, ValueError): + return False + return current.is_dir() + + @staticmethod + def _target_follows_preserved_convention(target_name: str) -> bool: + """True when a scaffold target survives remove/backup/restore. + + Those paths only handle top-level ``*-config.yml`` and + ``*-config.local.yml`` files, so anything nested or otherwise named is + not preserved across an update. + """ + if "/" in target_name or "\\" in target_name: + return False + return target_name.endswith("-config.yml") or target_name.endswith( + "-config.local.yml" + ) + + def scaffold_config(self, extension_id: str) -> tuple[List[str], List[str], List[str]]: + """Deploy config templates from an installed extension to the project. + + Reads the extension's manifest provides.config section and copies + each config template to the project's .specify/ directory. Existing + config files are never overwritten (user customizations are preserved). + + Args: + extension_id: ID of the installed extension + + Returns: + Tuple of (deployed, skipped_existing, failed) where each is a list + of config file names. + """ + ext_dir = self.extensions_dir / extension_id + manifest_path = ext_dir / "extension.yml" + if not manifest_path.exists(): + return [], [], [] + + manifest = ExtensionManifest(manifest_path) + deployed = [] + skipped_existing = [] + failed = [] + + provides = manifest.data.get("provides", {}) + raw_config = provides.get("config", []) + config_is_malformed = ( + "config" in provides + and ( + not isinstance(raw_config, list) + or not all(isinstance(entry, dict) for entry in raw_config) + ) + ) + if config_is_malformed: + return deployed, skipped_existing, ["provides.config"] + + ext_dir_resolved = ext_dir.resolve() + # Config is deployed beneath the extension's own directory because that + # is where it is read from: ConfigManager._get_project_config() loads + # `.specify/extensions//-config.yml`, and the bundled scripts + # and READMEs use the same location. Writing to `.specify/` put + # the file somewhere nothing ever looks. + config_dir = self.project_root / ".specify" / "extensions" / extension_id + # Resolving that directory and trusting the result as the containment + # root lets a symlinked component point outside the project: every + # target would then satisfy relative_to and copy2 would write + # externally. Refuse a symlinked component up front, matching the + # project safe-write path in shared_infra. + if not self._config_root_is_contained(config_dir): + return deployed, skipped_existing, ["provides.config"] + config_dir_resolved = config_dir.resolve() + + for config_entry in manifest.config: + template_name = config_entry.get("template", "") + target_name = config_entry.get("name", template_name) + failure_name = target_name if isinstance(target_name, str) and target_name else "provides.config" + if not isinstance(template_name, str) or not template_name: + failed.append(failure_name) + continue + if not isinstance(target_name, str) or not target_name: + failed.append(failure_name) + continue + # Only scaffold what removal actually preserves. remove(keep_config) + # keeps top-level files ending in -config.yml / -config.local.yml and + # rmtree's every subdirectory; the backup path globs the same + # top-level pattern. A nested or differently-named target would be + # silently destroyed by `extension add --force` and replaced with the + # template default, losing the user's customization. + if not self._target_follows_preserved_convention(target_name): + failed.append(failure_name) + continue + + template_candidate = ext_dir / template_name + template_path = template_candidate.resolve() + target_path = (config_dir / target_name).resolve() + try: + template_path.relative_to(ext_dir_resolved) + target_path.relative_to(config_dir_resolved) + except ValueError: + failed.append(failure_name) + continue + + if template_candidate.is_symlink() or not template_path.is_file(): + failed.append(failure_name) + continue + + if target_path.exists(): + skipped_existing.append(target_name) + continue + + try: + # mkdir belongs inside the handler: a nested target like + # foo/config.yml must land in `failed` when `.specify/foo` is a + # file or cannot be created, not raise out of scaffolding after + # `extension add` has already installed the extension. + target_path.parent.mkdir(parents=True, exist_ok=True) + shutil.copy2(template_path, target_path) + except OSError: + failed.append(target_name) + continue + deployed.append(target_name) + + return deployed, skipped_existing, failed + def install_from_zip( self, zip_path: Path, diff --git a/src/specify_cli/extensions/_commands.py b/src/specify_cli/extensions/_commands.py index b206cbfb9e..a74160c8f0 100644 --- a/src/specify_cli/extensions/_commands.py +++ b/src/specify_cli/extensions/_commands.py @@ -1093,8 +1093,29 @@ def extension_add( if reg_skills: console.print(f"\n{accent('✓')} {len(reg_skills)} agent skill(s) auto-registered") - console.print("\n[yellow]⚠[/yellow] Configuration may be required") - console.print(f" Check: .specify/extensions/{_escape_markup(str(manifest.id))}/") + # Scaffold config templates automatically + deployed, skipped, failed = manager.scaffold_config(manifest.id) + config_home = f".specify/extensions/{_escape_markup(str(manifest.id))}" + if deployed: + console.print("\n[bold cyan]Config scaffolded:[/bold cyan]") + for cfg in deployed: + console.print(f" • {config_home}/{_escape_markup(str(cfg))}") + if skipped: + console.print(f"\n[dim]Config files already exist (preserved): {_escape_markup(', '.join(skipped))}[/dim]") + if failed: + console.print( + f"\n[yellow]Warning:[/yellow] Config templates not scaffolded: " + f"{_escape_markup(', '.join(failed))}. " + "Verify the extension manifest and template files." + ) + + # Only warn when configuration is actually unresolved. Scaffolding that + # deployed or preserved every template has already answered this, and an + # extension without provides.config has nothing to configure; the blanket + # warning contradicted the output directly above it. + if failed or not (deployed or skipped): + console.print("\n[yellow]⚠[/yellow] Configuration may be required") + console.print(f" Check: {config_home}/") except ValidationError as e: console.print(f"\n[red]Validation Error:[/red] {_escape_markup(str(e))}") @@ -2582,6 +2603,30 @@ def extension_enable( # are re-emitted in installed integrations. _refresh_events_and_warn(project_root) + # Scaffold config templates on enable + try: + deployed, skipped, failed = manager.scaffold_config(extension_id) + except Exception as exc: + console.print( + f"\n[yellow]Warning:[/yellow] Failed to scaffold config for extension " + f"'{_escape_markup(str(display_name))}'." + ) + console.print(f"[dim]Details: {_escape_markup(str(exc))}[/dim]") + deployed, skipped, failed = [], [], [] + config_home = f".specify/extensions/{_escape_markup(str(extension_id))}" + if deployed: + console.print("\n[bold cyan]Config scaffolded:[/bold cyan]") + for cfg in deployed: + console.print(f" • {config_home}/{_escape_markup(str(cfg))}") + if skipped: + console.print(f"\n[dim]Config files already exist (preserved): {_escape_markup(', '.join(skipped))}[/dim]") + if failed: + console.print( + f"\n[yellow]Warning:[/yellow] Config templates not scaffolded: " + f"{_escape_markup(', '.join(failed))}. " + "Verify the extension manifest and template files." + ) + @extension_app.command("disable") def extension_disable( diff --git a/src/specify_cli/integration_runtime.py b/src/specify_cli/integration_runtime.py index eef44574cb..efcd8a9e63 100644 --- a/src/specify_cli/integration_runtime.py +++ b/src/specify_cli/integration_runtime.py @@ -70,8 +70,8 @@ def with_integration_setting( # ``script_type`` changes (``parsed_options`` and ``raw_options`` both # None), the previously-stored ``parsed_options`` are retained above, so # deriving the separator from the argument (None) would drop an - # options-dependent separator (e.g. Copilot ``--skills`` -> "-") back to - # the default ".". + # options-dependent separator (e.g. Copilot ``--commands`` -> ".") back to + # the default "-". current["invoke_separator"] = integration.effective_invoke_separator( current.get("parsed_options"), project_root ) diff --git a/src/specify_cli/integrations/_migrate_commands.py b/src/specify_cli/integrations/_migrate_commands.py index 5ab34ed722..6ee14cadc7 100644 --- a/src/specify_cli/integrations/_migrate_commands.py +++ b/src/specify_cli/integrations/_migrate_commands.py @@ -345,6 +345,14 @@ def integration_switch( selected_script = _resolve_script_type(project_root, script) + # Resolve and validate target options before uninstalling the current + # integration. Invalid options must not leave the project partially + # switched with the previous integration already removed. + target_raw_options, target_parsed_options = _resolve_integration_options( + target_integration, current, target, integration_options + ) + target_integration.is_skills_mode(target_parsed_options, project_root) + # Phase 1: Uninstall current integration (if any) if installed_key: current_integration = get_integration(installed_key) @@ -417,7 +425,10 @@ def integration_switch( fallback_key = installed_keys[0] fallback_integration = get_integration(fallback_key) if fallback_integration is not None: - raw_options, parsed_options = _resolve_integration_options( + ( + fallback_raw_options, + fallback_parsed_options, + ) = _resolve_integration_options( fallback_integration, current, fallback_key, None ) _set_default_integration_or_exit( @@ -426,8 +437,8 @@ def integration_switch( fallback_key, fallback_integration, installed_keys, - raw_options=raw_options, - parsed_options=parsed_options, + raw_options=fallback_raw_options, + parsed_options=fallback_parsed_options, ) else: _write_integration_json( @@ -437,13 +448,6 @@ def integration_switch( _remove_integration_json(project_root) current = _read_integration_json(project_root) - # Build parsed options from --integration-options so the integration - # can determine its effective invoke separator before shared infra - # is installed. - raw_options, parsed_options = _resolve_integration_options( - target_integration, current, target, integration_options - ) - # Refresh shared infrastructure to the current CLI version. Switching # integrations is exactly when stale vendored shared scripts (e.g. # update-agent-context.sh that pre-dates the target integration's @@ -459,11 +463,11 @@ def integration_switch( force=refresh_shared_infra, refresh_managed=True, invoke_separator=_invoke_separator_for_integration( - target_integration, current, target, parsed_options, + target_integration, current, target, target_parsed_options, project_root=project_root, ), invoke_prefix=_invoke_prefix_for_integration( - target_integration, target, parsed_options, project_root + target_integration, target, target_parsed_options, project_root ), refresh_hint=( "To overwrite customizations, re-run with " @@ -485,14 +489,14 @@ def integration_switch( target_integration.key, target_integration.config, project_root, - parsed_options, + target_parsed_options, ) try: target_integration.setup( project_root, manifest, - parsed_options=parsed_options, + parsed_options=target_parsed_options, script_type=selected_script, - raw_options=raw_options, + raw_options=target_raw_options, events=events_map, ) manifest.save() @@ -503,8 +507,8 @@ def integration_switch( target_integration, _dedupe_integration_keys([*installed_keys, target_integration.key]), script_type=selected_script, - raw_options=raw_options, - parsed_options=parsed_options, + raw_options=target_raw_options, + parsed_options=target_parsed_options, ) except Exception as exc: diff --git a/src/specify_cli/integrations/base.py b/src/specify_cli/integrations/base.py index 30a02d7a6e..199e405859 100644 --- a/src/specify_cli/integrations/base.py +++ b/src/specify_cli/integrations/base.py @@ -330,8 +330,8 @@ def is_skills_mode( on-disk layout to avoid silently migrating an existing project to a different mode. The default ignores it. - The default (command-first integrations, e.g. Copilot's default - layout) is skills mode only when ``--skills`` was requested. + The default for command-first integrations is skills mode only when + ``--skills`` was requested. ``SkillsIntegration`` overrides this to return ``True`` by default; skills-first integrations that expose a legacy opt-out (e.g. Bob) override it to honor their own flag. @@ -1256,6 +1256,20 @@ def supports_events(self) -> bool: """Return True if this integration supports agent-native events.""" return bool(getattr(self, "CANONICAL_TO_NATIVE", None) and getattr(self, "events_config_file", None)) + # Context-injection envelope for hook stdout, keyed by canonical event + # (with "*" as the fallback). Not every agent injects a hook's plain-text + # stdout as model context: Gemini/Tabnine/Qwen/Devin are JSON-only + # protocols (plain text becomes user-facing noise), Copilot discards + # non-JSON stdout, and Cursor parses stdout as JSON. Values: + # "hookSpecificOutput" → {"hookSpecificOutput": {"additionalContext": ...}} + # "additionalContext" → {"additionalContext": ...} (top-level, Copilot) + # "additional_context" → {"additional_context": ...} (top-level, Cursor) + # "suppress" → emit nothing (strict-JSON agents on events whose + # output can't be used) + # Absent (no matching key and no "*") → plain stdout passthrough + # (Claude/Codex inject plain stdout; opencode injects via its TS plugin). + events_context_envelope: dict[str, str] = {} + # -- Convenience helpers for subclasses ------------------------------- def install( diff --git a/src/specify_cli/integrations/copilot/__init__.py b/src/specify_cli/integrations/copilot/__init__.py index 9b2cefcb6d..29f4e2556c 100644 --- a/src/specify_cli/integrations/copilot/__init__.py +++ b/src/specify_cli/integrations/copilot/__init__.py @@ -1,13 +1,19 @@ """Copilot integration — GitHub Copilot in VS Code. -Copilot has several unique behaviors compared to standard markdown agents: +Copilot supports two layouts: +- Skills are the default and use ``speckit-/SKILL.md`` directories under + ``.github/skills/`` +- ``--commands`` uses ``.agent.md`` files, companion ``.prompt.md`` files, and + a VS Code settings merge + +The two modes are mutually exclusive. The commands layout remains supported, +but is no longer the preferred default. + +The commands layout has several unique behaviors compared to standard markdown +agents: - Commands use ``.agent.md`` extension (not ``.md``) - Each command gets a companion ``.prompt.md`` file in ``.github/prompts/`` - Installs ``.vscode/settings.json`` with prompt file recommendations - -When ``--skills`` is passed via ``--integration-options``, Copilot scaffolds -commands as ``speckit-/SKILL.md`` directories under ``.github/skills/`` -instead. The two modes are mutually exclusive. """ from __future__ import annotations @@ -19,9 +25,24 @@ from pathlib import Path from typing import Any +import typer + from ..base import IntegrationBase, IntegrationOption, SkillsIntegration from ..manifest import IntegrationManifest +_COPILOT_CORE_COMMANDS = { + "analyze", + "checklist", + "clarify", + "constitution", + "converge", + "implement", + "plan", + "specify", + "tasks", + "taskstoissues", +} + def _copilot_executable() -> str: """Return the executable name for Copilot CLI on this platform. @@ -57,22 +78,24 @@ def _allow_all() -> bool: return True -def _warn_legacy_markdown_default() -> None: - """Warn that Copilot's default markdown scaffold is being phased out.""" - warnings.warn( - "Copilot legacy markdown mode is deprecated and will stop being the " - 'default in a future Spec Kit release; pass --integration-options "--skills" ' - "to opt in to Copilot skills mode now.", - UserWarning, - stacklevel=3, - ) +def _validate_mode_options(parsed_options: dict[str, Any] | None) -> None: + """Reject the two explicit Copilot layout selectors used together.""" + opts = parsed_options or {} + if opts.get("skills") and opts.get("commands"): + from ..._console import console + + console.print( + "[red]Error:[/red] --skills and --commands are mutually exclusive; " + "pass only one." + ) + raise typer.Exit(1) class _CopilotSkillsHelper(SkillsIntegration): """Internal helper used when Copilot is scaffolded in skills mode. - Not registered in the integration registry — only used as a delegate - by ``CopilotIntegration`` when ``--skills`` is passed. + Not registered in the integration registry — only used as the default + skills-layout delegate by ``CopilotIntegration``. """ key = "copilot" @@ -94,13 +117,11 @@ class _CopilotSkillsHelper(SkillsIntegration): class CopilotIntegration(IntegrationBase): """Integration for GitHub Copilot (VS Code IDE + CLI). - The IDE integration (``requires_cli: False``) installs ``.agent.md`` - command files. Workflow dispatch additionally requires the - ``copilot`` CLI to be installed separately. - - When ``--skills`` is passed via ``--integration-options``, commands - are scaffolded as ``speckit-/SKILL.md`` under ``.github/skills/`` - instead of the default ``.agent.md`` + ``.prompt.md`` layout. + The default IDE integration (``requires_cli: False``) installs skills under + ``.github/skills/``. Pass ``--commands`` via ``--integration-options`` to + install the supported ``.agent.md`` + ``.prompt.md`` layout instead. + Workflow dispatch additionally requires the ``copilot`` CLI to be installed + separately. """ key = "copilot" @@ -117,6 +138,7 @@ class CopilotIntegration(IntegrationBase): "args": "$ARGUMENTS", "extension": ".agent.md", } + invoke_separator = "-" CANONICAL_TO_NATIVE = { "session_start": "sessionStart", @@ -130,40 +152,120 @@ class CopilotIntegration(IntegrationBase): } events_config_file = ".github/hooks/speckit.json" events_format = "copilot-json" + # Copilot sessionStart and userPromptSubmitted inject a top-level + # additionalContext field into the model-facing prompt (C13). Non-JSON + # stdout is discarded harmlessly by Copilot on other events, so no other + # event needs an envelope. + events_context_envelope = { + "session_start": "additionalContext", + "user_prompt_submit": "additionalContext", + } # Mutable flag set by setup() — indicates the active scaffolding mode. - _skills_mode: bool = False + _skills_mode: bool = True def effective_invoke_separator( self, parsed_options: dict[str, Any] | None = None, project_root: Path | None = None, ) -> str: - """Return ``"-"`` when skills mode is requested, ``"."`` otherwise.""" - if parsed_options and parsed_options.get("skills"): - return "-" - if self._skills_mode: - return "-" - return self.invoke_separator + """Return the separator for the resolved Copilot layout.""" + return "-" if self.is_skills_mode(parsed_options, project_root) else "." def is_skills_mode( self, parsed_options: dict[str, Any] | None = None, project_root: Path | None = None, ) -> bool: - """Copilot is skills mode when ``--skills`` was requested. + """Copilot defaults to skills; ``--commands`` opts into commands mode. - On the init path ``setup()`` has already recorded the choice in - ``self._skills_mode``; on the ``use``/``install`` path (where no - ``setup()`` runs) the signal comes from *parsed_options* (#3550), which - round-trips because ``--skills`` is persisted in the stored options. + Explicit flags override on-disk detection. Without a flag, existing + projects retain their managed Spec Kit layout while fresh projects use + skills. This prevents ``use`` and ``upgrade`` from silently migrating + projects created before skills became the default. """ - if parsed_options and parsed_options.get("skills"): + opts = parsed_options or {} + _validate_mode_options(opts) + if opts.get("skills"): return True - return self._skills_mode + if opts.get("commands"): + return False + # Fork: skills/commands may use "spec-" or "speckit-" prefix depending + # on whether presets are active (aliases rename speckit.* → spec.*). + try: + from ..base import _get_command_prefix + _prefixes = (_get_command_prefix(), "speckit") + except ImportError: + _prefixes = ("speckit",) + if project_root is not None: + project_root = Path(project_root) + manifest_path = ( + project_root + / ".specify" + / "integrations" + / "copilot.manifest.json" + ) + if manifest_path.is_file(): + try: + manifest_files = IntegrationManifest.load( + self.key, Path(project_root) + ).files + except (OSError, ValueError): + manifest_files = None + if manifest_files is not None and any( + any( + path.startswith(f".github/skills/{p}-") + and path.endswith("/SKILL.md") + for p in _prefixes + ) + for path in manifest_files + ): + return True + if manifest_files is not None and any( + any( + path.startswith(f".github/agents/{p}.") + and path.endswith(".agent.md") + for p in _prefixes + ) + for path in manifest_files + ): + return False + + github_dir = project_root / ".github" + has_managed_skills = any( + any( + ( + github_dir + / "skills" + / f"{p}-{command}" + / "SKILL.md" + ).is_file() + for p in _prefixes + ) + for command in _COPILOT_CORE_COMMANDS + ) + has_managed_commands = any( + any( + ( + github_dir + / "agents" + / f"{p}.{command}.agent.md" + ).is_file() + or ( + github_dir + / "prompts" + / f"{p}.{command}.prompt.md" + ).is_file() + for p in _prefixes + ) + for command in _COPILOT_CORE_COMMANDS + ) + if has_managed_commands and not has_managed_skills: + return False + return True def invoke_separator_for_mode(self, skills_enabled: bool) -> str: - """Skills projects render ``/speckit-``; default markdown ``.``. + """Skills projects render ``/speckit-``; commands use ``.``. Copilot is dual-layout, so — like Bob — the command-reference separator depends on the persisted ``ai_skills`` state rather than a @@ -171,7 +273,7 @@ def invoke_separator_for_mode(self, skills_enabled: bool) -> str: Copilot skills project consistent with ``build_command_invocation`` (which emits ``/speckit-``). """ - return "-" if skills_enabled else self.invoke_separator + return "-" if skills_enabled else "." @classmethod def options(cls) -> list[IntegrationOption]: @@ -184,7 +286,22 @@ def options(cls) -> list[IntegrationOption]: "--skills", is_flag=True, default=False, - help="Scaffold commands as agent skills (speckit-/SKILL.md) instead of .agent.md files", + help=( + "Force the default skills layout (.github/skills/), " + "overriding on-disk auto-detection" + ), + ), + ) + opts.append( + IntegrationOption( + "--commands", + is_flag=True, + default=False, + help=( + "Scaffold .github/agents/*.agent.md commands with companion " + ".github/prompts/*.prompt.md files instead of the default " + "skills layout" + ), ), ) return opts @@ -228,14 +345,22 @@ def build_exec_args( def build_command_invocation(self, command_name: str, args: str = "") -> str: """Build the native invocation for a Copilot command. - Default mode: agents are not slash-commands — return args as prompt. - Skills mode: ``/speckit-`` slash-command dispatch. + Commands mode: agents are not slash-commands — return args as prompt. + Skills mode (default): ``/speckit-`` slash-command dispatch. """ if self._skills_mode: # Use alias map to resolve to canonical form try: from ..._core_fork import resolve_command_alias - resolved = resolve_command_alias(command_name) + # Canonicalize only truly bare names (e.g. "plan") so the + # alias lookup finds speckit.plan -> spec.plan. Dotted names + # ("git.commit", "speckit.plan") are already canonical or + # alias-form — prepending speckit. would break their resolution. + if "." not in command_name: + canonical = f"speckit.{command_name}" + else: + canonical = command_name + resolved = resolve_command_alias(canonical) except Exception: resolved = command_name invocation = "/" + resolved.replace(".", "-") @@ -272,19 +397,11 @@ def dispatch_command( except Exception: resolved = command_name - # Detect skills mode from project layout when not set via setup() - skills_mode = self._skills_mode - if not skills_mode and project_root: - skills_dir = project_root / ".github" / "skills" - if skills_dir.is_dir(): - # Check for spec-* skills (fork format) - skills_mode = any( - d.is_dir() and (d / "SKILL.md").is_file() - for d in skills_dir.glob("spec-*") - ) or any( - d.is_dir() and (d / "SKILL.md").is_file() - for d in skills_dir.glob("speckit-*") - ) + skills_mode = ( + self.is_skills_mode(project_root=project_root) + if project_root + else self._skills_mode + ) if skills_mode: prompt = "/" + resolved.replace(".", "-") @@ -388,20 +505,18 @@ def setup( parsed_options: dict[str, Any] | None = None, **opts: Any, ) -> list[Path]: - """Install copilot commands, companion prompts, and VS Code settings. + """Install Copilot skills or the opt-in commands layout. - When ``parsed_options["skills"]`` is truthy, delegates to skills - scaffolding (``speckit-/SKILL.md`` under ``.github/skills/``). - Otherwise uses the default ``.agent.md`` + ``.prompt.md`` layout. + Skills are the default. ``parsed_options["commands"]`` selects + ``.agent.md`` files, companion prompts, and the VS Code settings merge. + Existing managed command layouts are preserved when no mode is explicit. """ parsed_options = parsed_options or {} - self._skills_mode = bool(parsed_options.get("skills")) + self._skills_mode = self.is_skills_mode(parsed_options, project_root) if self._skills_mode: created = self._setup_skills(project_root, manifest, parsed_options, **opts) else: - if "skills" not in parsed_options: - _warn_legacy_markdown_default() - created = self._setup_default(project_root, manifest, parsed_options, **opts) + created = self._setup_commands(project_root, manifest, parsed_options, **opts) # Install agent runtime events event_files = self.emit_events( @@ -410,14 +525,14 @@ def setup( created.extend(event_files) return created - def _setup_default( + def _setup_commands( self, project_root: Path, manifest: IntegrationManifest, parsed_options: dict[str, Any] | None = None, **opts: Any, ) -> list[Path]: - """Default mode: .agent.md + .prompt.md + VS Code settings merge.""" + """Commands mode: .agent.md + .prompt.md + VS Code settings merge.""" project_root_resolved = project_root.resolve() if manifest.project_root != project_root_resolved: raise ValueError( diff --git a/src/specify_cli/integrations/cursor_agent/__init__.py b/src/specify_cli/integrations/cursor_agent/__init__.py index 58bd89b21f..45c5522a08 100644 --- a/src/specify_cli/integrations/cursor_agent/__init__.py +++ b/src/specify_cli/integrations/cursor_agent/__init__.py @@ -48,6 +48,14 @@ class CursorAgentIntegration(SkillsIntegration): } events_config_file = ".cursor/hooks.json" events_format = "json-flat" + # Cursor sessionStart injects a top-level additional_context (snake_case) + # field (C13). beforeSubmitPrompt has no context output field (block/allow + # only), and plain text on any hook fails Cursor's JSON parse — suppress + # everything else. + events_context_envelope = { + "*": "suppress", + "session_start": "additional_context", + } def build_exec_args( self, diff --git a/src/specify_cli/integrations/devin/__init__.py b/src/specify_cli/integrations/devin/__init__.py index dea6b5d228..4807365346 100644 --- a/src/specify_cli/integrations/devin/__init__.py +++ b/src/specify_cli/integrations/devin/__init__.py @@ -44,6 +44,13 @@ class DevinIntegration(SkillsIntegration): # top-level "hooks" wrapper (U2), unlike the settings.json formats. The # json-root-nested writer/remover operate directly on the root event keys. events_format = "json-root-nested" + # Devin's hooks protocol is JSON-stdout; additionalContext is the + # documented injection field for SessionStart/UserPromptSubmit (C13). + events_context_envelope = { + "*": "suppress", + "session_start": "hookSpecificOutput", + "user_prompt_submit": "hookSpecificOutput", + } def build_exec_args( self, diff --git a/src/specify_cli/integrations/gemini/__init__.py b/src/specify_cli/integrations/gemini/__init__.py index 2200e707c8..1e824d451a 100644 --- a/src/specify_cli/integrations/gemini/__init__.py +++ b/src/specify_cli/integrations/gemini/__init__.py @@ -33,6 +33,15 @@ class GeminiIntegration(TomlIntegration): } events_config_file = ".gemini/settings.json" events_format = "json-nested" + # Gemini mandates JSON-only hook stdout ("silence is mandatory"): plain + # text becomes a user-facing systemMessage, never context. Inject via + # hookSpecificOutput.additionalContext on the two context events and + # suppress stdout everywhere else (C13). + events_context_envelope = { + "*": "suppress", + "session_start": "hookSpecificOutput", + "user_prompt_submit": "hookSpecificOutput", + } # Gemini measures hook timeouts in milliseconds, unlike Claude/Cursor/Codex # which use seconds. The shared formatter converts via _native_timeout (#7) # so the default 60s becomes 60000ms instead of terminating the dispatcher diff --git a/src/specify_cli/integrations/kimi/__init__.py b/src/specify_cli/integrations/kimi/__init__.py index 2b3d409b6f..4517fac037 100644 --- a/src/specify_cli/integrations/kimi/__init__.py +++ b/src/specify_cli/integrations/kimi/__init__.py @@ -317,7 +317,7 @@ def _is_speckit_generated_skill(skill_dir: Path) -> bool: try: content = skill_file.read_text(encoding="utf-8") - except OSError: + except (OSError, UnicodeError): return False if not content.startswith("---"): diff --git a/src/specify_cli/integrations/opencode/__init__.py b/src/specify_cli/integrations/opencode/__init__.py index 660fd0b5fa..007c1187bb 100644 --- a/src/specify_cli/integrations/opencode/__init__.py +++ b/src/specify_cli/integrations/opencode/__init__.py @@ -23,7 +23,15 @@ class OpencodeIntegration(MarkdownIntegration): CANONICAL_TO_NATIVE = { "pre_tool_use": "tool.execute.before", "post_tool_use": "tool.execute.after", - "session_start": "session.created", + # session_start maps to the system-prompt transform hook (not the + # session.created event) so the handler's stdout is injected into the + # system prompt — session.created has no output channel. The hook + # fires per LLM request, which keeps the context present across + # compaction at the cost of running the handler per turn. + "session_start": "experimental.chat.system.transform", + # user_prompt_submit maps to chat.message so handler stdout is + # injected as a synthetic text part on the user's message. + "user_prompt_submit": "chat.message", "session_end": "session.deleted", } events_config_file = "opencode.json" diff --git a/src/specify_cli/integrations/qwen/__init__.py b/src/specify_cli/integrations/qwen/__init__.py index 7ab55d978b..e356f851c0 100644 --- a/src/specify_cli/integrations/qwen/__init__.py +++ b/src/specify_cli/integrations/qwen/__init__.py @@ -30,6 +30,12 @@ class QwenIntegration(MarkdownIntegration): } events_config_file = ".qwen/settings.json" events_format = "json-nested" + # Qwen hooks are a JSON stdin/stdout protocol (Gemini-derived) (C13). + events_context_envelope = { + "*": "suppress", + "session_start": "hookSpecificOutput", + "user_prompt_submit": "hookSpecificOutput", + } # Qwen Code's command hooks measure timeout in milliseconds (default # 60000), per the Qwen Code hooks documentation. Declaring the unit makes # the shared formatter convert the 60s default to 60000ms instead of diff --git a/src/specify_cli/integrations/tabnine/__init__.py b/src/specify_cli/integrations/tabnine/__init__.py index 5e8a803e6c..17b78d1114 100644 --- a/src/specify_cli/integrations/tabnine/__init__.py +++ b/src/specify_cli/integrations/tabnine/__init__.py @@ -33,6 +33,12 @@ class TabnineIntegration(TomlIntegration): } events_config_file = ".tabnine/agent/settings.json" events_format = "json-nested" + # Tabnine is Gemini-hooks-compatible (JSON-only stdout) (C13). + events_context_envelope = { + "*": "suppress", + "session_start": "hookSpecificOutput", + "user_prompt_submit": "hookSpecificOutput", + } # Tabnine mirrors Gemini's hook schema (BeforeTool/AfterTool) and, like # Gemini, measures hook timeouts in milliseconds. Declaring the unit makes # the shared formatter convert the 60s default to 60000ms instead of diff --git a/src/specify_cli/presets/__init__.py b/src/specify_cli/presets/__init__.py index 493826c8e0..c2ff312c51 100644 --- a/src/specify_cli/presets/__init__.py +++ b/src/specify_cli/presets/__init__.py @@ -307,9 +307,25 @@ def _validate(self): # Validate preset metadata pack = self.data["preset"] + # Check presence AND type: the format/version checks below feed these + # values straight to ``re.match`` and ``packaging.Version``, both of + # which raise a bare TypeError on a non-string. YAML makes that an easy + # authoring slip -- unquoted ``version: 1.0`` parses as a float and + # ``id: 2`` as an int -- and TypeError is not a PresetValidationError, + # so it escapes every caller that already handles a malformed manifest + # (see list_installed()'s "Corrupted preset" fallback, which catches + # PresetValidationError only, making one bad preset exit ``specify + # preset list`` with a raw traceback and hide the healthy ones). + # Mirrors the sibling IntegrationDescriptor, which already type-checks + # the same four fields. for field in ["id", "name", "version", "description"]: if field not in pack: raise PresetValidationError(f"Missing preset.{field}") + if not isinstance(pack[field], str): + raise PresetValidationError( + f"Invalid preset.{field}: expected a string, " + f"got {type(pack[field]).__name__}" + ) # Validate pack ID format if not re.match(r'^[a-z0-9-]+$', pack["id"]): @@ -328,6 +344,25 @@ def _validate(self): requires = self.data["requires"] if "speckit_version" not in requires: raise PresetValidationError("Missing requires.speckit_version") + # Presence alone is not enough: check_compatibility() feeds this value to + # ``SpecifierSet(required)``, guarded only by ``except InvalidSpecifier``, + # which a non-string escapes two different ways. A float/int/bool/None + # raises TypeError from the constructor, while a list or dict is an + # *iterable*, so SpecifierSet accepts it and the failure surfaces much + # later as ``AttributeError: 'str' object has no attribute 'filter'`` from + # inside .contains(). Neither is a PresetCompatibilityError, so both + # bypass the CLI's "Compatibility Error" handler and exit 1 with a raw + # traceback naming no field. An unquoted ``speckit_version: 1.0`` is an + # easy YAML slip. Mirrors the sibling IntegrationDescriptor, which already + # requires a non-empty string here. + if ( + not isinstance(requires["speckit_version"], str) + or not requires["speckit_version"].strip() + ): + raise PresetValidationError( + "Invalid requires.speckit_version: expected a non-empty string, " + f"got {type(requires['speckit_version']).__name__}" + ) # Validate provides section provides = self.data["provides"] @@ -367,6 +402,19 @@ def _validate(self): "Template missing 'type', 'name', or 'file'" ) + # 'name' feeds re.match and 'file' feeds os.path.normpath below; + # both raise a bare TypeError on a non-string, which is not a + # PresetValidationError and so escapes the callers that handle a + # malformed manifest. The sibling extension manifest already + # rejects a non-string command 'file' via + # relative_extension_path_violation(). + for field in ("type", "name", "file"): + if not isinstance(tmpl[field], str): + raise PresetValidationError( + f"Invalid template {field}: expected a string, " + f"got {type(tmpl[field]).__name__}" + ) + if tmpl["type"] not in VALID_PRESET_TEMPLATE_TYPES: raise PresetValidationError( f"Invalid template type '{tmpl['type']}': " @@ -502,7 +550,12 @@ def _load(self) -> dict: if not isinstance(data.get("presets"), dict): data["presets"] = {} return data - except (json.JSONDecodeError, FileNotFoundError): + except (json.JSONDecodeError, UnicodeDecodeError, FileNotFoundError): + # Corrupted or missing registry, start fresh. A registry whose + # bytes cannot be decoded as UTF-8 is the same corruption class + # as malformed JSON — only the exception type differs. OSError is + # deliberately not caught: the data may be intact on disk, and + # starting fresh would let a later _save() wipe it. return { "schema_version": self.SCHEMA_VERSION, "presets": {} @@ -727,6 +780,18 @@ def check_compatibility( PresetCompatibilityError: If pack is incompatible """ required = manifest.requires_speckit_version + # Defense in depth: the manifest validator now rejects a non-string + # requires.speckit_version, but this method is public and also reachable + # with a hand-built manifest object. ``InvalidSpecifier`` alone does not + # cover a non-string -- scalars raise TypeError from the constructor, and + # a list/dict is iterable so it constructs here and only breaks inside + # .contains(). Reject up front so this always reports a + # PresetCompatibilityError. + if not isinstance(required, str): + raise PresetCompatibilityError( + "Invalid version specifier: expected a string, got " + f"{type(required).__name__} ({required!r})" + ) try: SpecifierSet(required) # Just to validate except InvalidSpecifier: @@ -2229,7 +2294,10 @@ def apply_to_dir( ] if dir_core_ext_names: self._unregister_skills_in_dir( - dir_core_ext_names, skills_dir, dir_agent + dir_core_ext_names, + skills_dir, + dir_agent, + restore_from_bundled_core=True, ) for _skill_name, cmd_name, top_layer in override_skills: @@ -3118,6 +3186,7 @@ def _unregister_skills( preset_dir: Union[Path, str], *, additional_owned_sources: Optional[Dict[str, str]] = None, + restore_from_bundled_core: bool = False, ) -> Dict[Path, tuple[Optional[str], List[str]]]: """Restore original SKILL.md files after a preset is removed. @@ -3125,6 +3194,17 @@ def _unregister_skills( regenerate the skill from the core command template. If no core template exists, the skill directory is removed. + Args: + restore_from_bundled_core: When True, a missing project-local + core template (the common case — ``specify init`` never + populates ``.specify/templates/commands``) falls back to + the bundled core_pack/repo-root templates so the skill is + restored instead of deleted (#3928). Callers that are + retiring a skill because its command now renders elsewhere + (a command file superseding it) must leave this False so + the skill is removed rather than resurrected with core + content that would duplicate the winning command. + ``registered_skills`` records exactly which agent directories this preset actually wrote to (see :meth:`_register_skills`), so removal restores precisely those directories rather than guessing at every @@ -3198,6 +3278,7 @@ def _unregister_skills( renderer_agent, pack_id=pack_id, additional_owned_sources=additional_owned_sources, + restore_from_bundled_core=restore_from_bundled_core, ) if mutated_names: restored[skills_dir] = ( @@ -3230,6 +3311,7 @@ def _unregister_skills( selected_ai, pack_id=pack_id, additional_owned_sources=additional_owned_sources, + restore_from_bundled_core=restore_from_bundled_core, ) return ( {skills_dir: (selected_ai, mutated_names)} @@ -3303,6 +3385,7 @@ def _unregister_skills_in_dir( *, pack_id: Optional[str] = None, additional_owned_sources: Optional[Dict[str, str]] = None, + restore_from_bundled_core: bool = False, ) -> List[str]: """Restore original SKILL.md files within a single skills directory. @@ -3313,6 +3396,7 @@ def _unregister_skills_in_dir( placeholder resolution and argument-hint formatting. additional_owned_sources: Generated non-preset source markers accepted as owned for specific skill names. + restore_from_bundled_core: See ``_unregister_skills``. Returns: Skill names whose files were restored or removed. @@ -3388,9 +3472,34 @@ def _unregister_skills_in_dir( if current_source not in owned_sources: continue - # Try to find the core command template - core_file = core_templates_dir / f"{short_name}.md" if core_templates_dir.exists() else None - if core_file and not core_file.exists(): + extension_restore = extension_restore_index.get(skill_name) + + # Try to find the core command template. Project-local overrides + # in core_templates_dir take precedence, but that directory is + # rarely populated — the real core commands ship in the bundled + # core_pack (wheel install) or the repo-root templates/ tree + # (source checkout). Callers that want a genuine restore (a + # preset was removed outright, not superseded by another + # renderer) opt into that fallback via restore_from_bundled_core + # so the skill is restored instead of deleted (#3928). An + # installed extension providing a core-named command resolves + # ahead of bundled core elsewhere, so skip the bundled fallback + # when an extension restore exists — otherwise it would win + # over the higher-priority extension layer below. + core_file = core_templates_dir / f"{short_name}.md" + if ( + not core_file.exists() + and restore_from_bundled_core + and extension_restore is None + ): + from .. import _locate_core_pack, _repo_root + + _core_pack = _locate_core_pack() + if _core_pack is not None: + core_file = _core_pack / "commands" / f"{short_name}.md" + else: + core_file = _repo_root() / "templates" / "commands" / f"{short_name}.md" + if not core_file.exists(): core_file = None if core_file: @@ -3442,7 +3551,6 @@ def _unregister_skills_in_dir( mutated_names.append(skill_name) continue - extension_restore = extension_restore_index.get(skill_name) if extension_restore: content = extension_restore["source_file"].read_text(encoding="utf-8") frontmatter, body = registrar.parse_frontmatter(content) @@ -3588,7 +3696,9 @@ def install_from_directory( "registered_skills", registered_skills ) if persisted_skills: - self._unregister_skills(persisted_skills, dest_dir) + self._unregister_skills( + persisted_skills, dest_dir, restore_from_bundled_core=True + ) try: if dest_dir.exists(): shutil.rmtree(dest_dir) @@ -3926,6 +4036,7 @@ def remove(self, pack_id: str) -> bool: restorable_skills, pack_dir, additional_owned_sources=override_sources, + restore_from_bundled_core=True, ) try: from ..agents import CommandRegistrar @@ -5437,7 +5548,7 @@ def _find_in_subdirs(base_dir: Path) -> Optional[Path]: fm_strategy = fm_data.get("strategy") if isinstance(fm_strategy, str) and fm_strategy.lower() in VALID_PRESET_STRATEGIES: strategy = fm_strategy.lower() - except (yaml.YAMLError, OSError): + except (UnicodeDecodeError, yaml.YAMLError, OSError): # Best-effort legacy frontmatter parsing: keep default # strategy ("replace") when content is unreadable/invalid. pass diff --git a/src/specify_cli/workflows/engine.py b/src/specify_cli/workflows/engine.py index 459e95ac4a..a478aafddb 100644 --- a/src/specify_cli/workflows/engine.py +++ b/src/specify_cli/workflows/engine.py @@ -761,6 +761,11 @@ def load(cls, run_id: str, project_root: Path) -> RunState: "Invalid run state: missing required field(s): " + ", ".join(missing_fields) ) + if state_data["run_id"] != run_id: + raise ValueError( + f"Invalid run state: stored run_id {state_data['run_id']!r} " + f"does not match requested run_id {run_id!r}" + ) workflow_id = state_data["workflow_id"] if not isinstance(workflow_id, str) or not _ID_PATTERN.fullmatch( diff --git a/src/specify_cli/workflows/steps/init/__init__.py b/src/specify_cli/workflows/steps/init/__init__.py index 5dc1ee9c02..270badc4fc 100644 --- a/src/specify_cli/workflows/steps/init/__init__.py +++ b/src/specify_cli/workflows/steps/init/__init__.py @@ -11,7 +11,10 @@ import os from typing import Any -from specify_cli._agent_config import DEFAULT_INIT_INTEGRATION, SCRIPT_TYPE_CHOICES +from specify_cli._agent_config import ( + SCRIPT_TYPE_CHOICES, + resolve_default_init_integration, +) from specify_cli.workflows.base import StepBase, StepContext, StepResult, StepStatus from specify_cli.workflows.expressions import evaluate_expression @@ -54,7 +57,8 @@ class InitStep(StepBase): Initialize in the target directory instead of creating a new one. ``integration`` Integration key (e.g. ``copilot``). Defaults to the workflow's - default integration, then to ``DEFAULT_INIT_INTEGRATION``. + default integration, then to the resolved default init integration + (``SPECKIT_INTEGRATION_DEFAULT`` env var, else ``copilot``). ``integration_options`` Extra options for the integration (e.g. ``"--skills"`` or ``"--commands-dir .myagent/cmds"``). @@ -81,7 +85,7 @@ def execute(self, config: dict[str, Any], context: StepContext) -> StepResult: # Apply the same default that specify init uses in non-interactive mode # so that output.integration reflects the actual integration used. if not integration: - integration = DEFAULT_INIT_INTEGRATION + integration = resolve_default_init_integration() integration_options = self._resolve( config.get("integration_options"), context @@ -91,9 +95,17 @@ def execute(self, config: dict[str, Any], context: StepContext) -> StepResult: force = self._resolve_bool(config.get("force"), context) # Workflows run unattended; skip the agent CLI presence check by default. - ignore_agent_tools = self._resolve_bool( - config.get("ignore_agent_tools", True), context - ) + # ``config.get(key, True)`` applies that default only when the key is + # ABSENT: a bare ``ignore_agent_tools:`` in YAML parses to None, which + # ``_resolve_bool`` then turns into False -- flipping the documented + # default and re-enabling the agent-CLI presence check this step promises + # to skip, so an unattended run fails with "Agent Detection Error" for + # any integration whose CLI is not installed. Normalize an explicit null + # to the default, mirroring the while/do-while ``max_iterations`` handling. + raw_ignore_agent_tools = config.get("ignore_agent_tools") + if raw_ignore_agent_tools is None: + raw_ignore_agent_tools = True + ignore_agent_tools = self._resolve_bool(raw_ignore_agent_tools, context) argv: list[str] = ["init"] if here: diff --git a/tests/integration/test_bundler_init_install.py b/tests/integration/test_bundler_init_install.py index c1e079ce27..a13def5ff8 100644 --- a/tests/integration/test_bundler_init_install.py +++ b/tests/integration/test_bundler_init_install.py @@ -44,6 +44,20 @@ def test_precedence_default_when_unspecified(): assert _resolve_init_integration(None, None) == "copilot" +def test_precedence_default_honors_env_var(monkeypatch): + monkeypatch.setenv("SPECKIT_INTEGRATION_DEFAULT", "gemini") + # With no override and no bundle-declared integration, the env-var default + # applies instead of the hardcoded "copilot". + assert _resolve_init_integration(None, None) == "gemini" + assert _resolve_init_integration(None, _manifest()) == "gemini" + # Explicit override and bundle-declared integration still take precedence. + assert _resolve_init_integration("claude", None) == "claude" + assert ( + _resolve_init_integration(None, _manifest(integration={"id": "claude"})) + == "claude" + ) + + def _build_mini(tmp_path: Path) -> Path: bundle = tmp_path / "mini" bundle.mkdir() diff --git a/tests/integrations/test_cli.py b/tests/integrations/test_cli.py index ed77eb6fac..c65c8406d4 100644 --- a/tests/integrations/test_cli.py +++ b/tests/integrations/test_cli.py @@ -69,11 +69,11 @@ def test_integration_copilot_creates_files(self, tmp_path): finally: os.chdir(old_cwd) assert result.exit_code == 0, f"init failed: {result.output}" - from tests.conftest import _cmd_prefix - - prefix = _cmd_prefix() - assert (project / ".github" / "agents" / f"{prefix}.plan.agent.md").exists() - assert (project / ".github" / "prompts" / f"{prefix}.plan.prompt.md").exists() + assert ( + project / ".github" / "skills" / "speckit-plan" / "SKILL.md" + ).exists() + assert not (project / ".github" / "agents").exists() + assert not (project / ".github" / "prompts").exists() assert (project / ".specify" / "scripts" / "bash" / "common.sh").exists() data = json.loads((project / ".specify" / "integration.json").read_text(encoding="utf-8")) @@ -81,6 +81,7 @@ def test_integration_copilot_creates_files(self, tmp_path): opts = json.loads((project / ".specify" / "init-options.json").read_text(encoding="utf-8")) assert opts["integration"] == "copilot" + assert opts["ai_skills"] is True # init must not leave any legacy agent-context keys in init-options.json assert "context_file" not in opts @@ -123,14 +124,75 @@ def fail_select(*_args, **_kwargs): assert result.exit_code == 0, result.output assert f"defaulting to '{specify_cli.DEFAULT_INIT_INTEGRATION}'" in result.output - from tests.conftest import _cmd_prefix - - prefix = _cmd_prefix() - assert (project / ".github" / "agents" / f"{prefix}.plan.agent.md").exists() + assert ( + project / ".github" / "skills" / "speckit-plan" / "SKILL.md" + ).exists() data = json.loads((project / ".specify" / "integration.json").read_text(encoding="utf-8")) assert data["integration"] == specify_cli.DEFAULT_INIT_INTEGRATION + def test_noninteractive_init_honors_default_integration_env_var( + self, tmp_path, monkeypatch + ): + from typer.testing import CliRunner + from specify_cli import app + import specify_cli + + def fail_select(*_args, **_kwargs): + raise AssertionError("non-interactive init should not open the integration picker") + + monkeypatch.setattr(specify_cli, "select_with_arrows", fail_select) + monkeypatch.setenv( + specify_cli.DEFAULT_INIT_INTEGRATION_ENV_VAR, "gemini" + ) + + runner = CliRunner() + project = tmp_path / "noninteractive_env" + result = runner.invoke(app, [ + "init", str(project), "--script", "sh", "--ignore-agent-tools", + ], catch_exceptions=False) + + assert result.exit_code == 0, result.output + assert "defaulting to 'gemini'" in result.output + + data = json.loads((project / ".specify" / "integration.json").read_text(encoding="utf-8")) + assert data["integration"] == "gemini" + + def test_interactive_init_picker_default_honors_env_var( + self, tmp_path, monkeypatch + ): + # The interactive integration picker must receive the resolved + # SPECKIT_INTEGRATION_DEFAULT value as its default_key, not the + # hardcoded constant (guards the picker wiring against regression). + from typer.testing import CliRunner + from specify_cli import app + import specify_cli.commands.init as init_mod + + monkeypatch.setattr(init_mod, "_stdin_is_interactive", lambda: True) + monkeypatch.setenv("SPECKIT_INTEGRATION_DEFAULT", "gemini") + + captured = {} + + def fake_select(options, prompt_text=None, default_key=None): + # Only capture the integration picker (not the script picker). + if "Choose your coding agent integration" in (prompt_text or ""): + captured["default_key"] = default_key + return default_key + + monkeypatch.setattr(init_mod, "select_with_arrows", fake_select) + + runner = CliRunner() + project = tmp_path / "interactive_env" + result = runner.invoke(app, [ + "init", str(project), "--script", "sh", "--ignore-agent-tools", + ], catch_exceptions=False) + + assert result.exit_code == 0, result.output + assert captured.get("default_key") == "gemini" + + data = json.loads((project / ".specify" / "integration.json").read_text(encoding="utf-8")) + assert data["integration"] == "gemini" + def test_init_here_nonempty_noninteractive_errors_with_force_guidance(self, tmp_path): """`init --here` on a non-empty directory with no confirmation input (empty stdin) must fail fast with guidance to use --force, instead of the bare @@ -203,10 +265,9 @@ def test_integration_copilot_auto_promotes(self, tmp_path): finally: os.chdir(old_cwd) assert result.exit_code == 0 - from tests.conftest import _cmd_prefix - - prefix = _cmd_prefix() - assert (project / ".github" / "agents" / f"{prefix}.plan.agent.md").exists() + assert ( + project / ".github" / "skills" / "speckit-plan" / "SKILL.md" + ).exists() def test_init_optional_preset_failure_reports_target_and_continues( self, tmp_path, monkeypatch @@ -1443,7 +1504,7 @@ def test_full_init_claude_resolves_page_templates(self, tmp_path): assert f"/{prefix}.specify" not in script_content def test_full_init_copilot_resolves_page_templates(self, tmp_path): - """Full CLI init with Copilot (markdown agent) produces dot refs in page templates.""" + """Default Copilot skills mode produces hyphen refs in page templates.""" from typer.testing import CliRunner from specify_cli import app @@ -1468,27 +1529,28 @@ def test_full_init_copilot_resolves_page_templates(self, tmp_path): from tests.conftest import _cmd_prefix prefix = _cmd_prefix() - assert f"/{prefix}.plan" in content, f"Copilot (markdown) should use /{prefix}.plan" + assert f"/{prefix}-plan" in content, f"Copilot skills should use /{prefix}-plan" + assert f"/{prefix}.plan" not in content assert "__SPECKIT_COMMAND_" not in content script_content = self._combined_script_content(project, "sh") - assert f"/{prefix}.specify" in script_content - assert f"/{prefix}-specify" not in script_content + assert f"/{prefix}-specify" in script_content + assert f"/{prefix}.specify" not in script_content - def test_full_init_copilot_skills_resolves_page_templates(self, tmp_path): - """Full CLI init with Copilot --skills produces hyphen refs in page templates.""" + def test_full_init_copilot_commands_resolves_page_templates(self, tmp_path): + """Copilot --commands produces dot refs in page templates.""" from typer.testing import CliRunner from specify_cli import app runner = CliRunner() - project = tmp_path / "init-copilot-skills" + project = tmp_path / "init-copilot-commands" old_cwd = os.getcwd() try: os.chdir(tmp_path) result = runner.invoke(app, [ "init", str(project), "--integration", "copilot", - "--integration-options", "--skills", + "--integration-options", "--commands", "--script", "sh", "--ignore-agent-tools", ], catch_exceptions=False) @@ -1502,13 +1564,13 @@ def test_full_init_copilot_skills_resolves_page_templates(self, tmp_path): from tests.conftest import _cmd_prefix prefix = _cmd_prefix() - assert f"/{prefix}-plan" in content, f"Copilot --skills should use /{prefix}-plan" - assert f"/{prefix}.plan" not in content, "dot-notation leaked into Copilot skills page template" + assert f"/{prefix}.plan" in content, f"Copilot --commands should use /{prefix}.plan" + assert f"/{prefix}-plan" not in content assert "__SPECKIT_COMMAND_" not in content script_content = self._combined_script_content(project, "sh") - assert f"/{prefix}-specify" in script_content - assert f"/{prefix}.specify" not in script_content + assert f"/{prefix}.specify" in script_content + assert f"/{prefix}-specify" not in script_content class TestIntegrationCatalogDiscoveryCLI: diff --git a/tests/integrations/test_events.py b/tests/integrations/test_events.py index 659ae48599..556e05caef 100644 --- a/tests/integrations/test_events.py +++ b/tests/integrations/test_events.py @@ -128,6 +128,23 @@ def test_layer2_empty_events_disables(self, tmp_path): ) assert result == {} + def test_unreadable_yaml_override_keeps_prior_layers(self, tmp_path): + """An unreadable override is ignored like malformed YAML.""" + override_file = tmp_path / ".specify" / "integration-events.yml" + override_file.parent.mkdir(parents=True, exist_ok=True) + override_file.write_bytes(b"\xff\xfe") + + result = resolve_events( + "claude", + {"events": {"post_tool_use": {"command": "speckit.tdd.validate"}}}, + tmp_path, + None, + ) + + assert result == { + "post_tool_use": [{"command": "speckit.tdd.validate"}] + } + def test_no_config_no_events(self, tmp_path): """Safe fallback with empty config/options.""" result = resolve_events("claude", None, tmp_path, None) @@ -164,6 +181,13 @@ def test_invalid_yaml_skipped(self, tmp_path): (ext_dir / "extension.yml").write_text("invalid: - - -", encoding="utf-8") assert collect_extension_events(tmp_path) == {} + def test_non_utf8_manifest_skipped(self, tmp_path): + ext_dir = tmp_path / ".specify" / "extensions" / "my-ext" + ext_dir.mkdir(parents=True) + (ext_dir / "extension.yml").write_bytes(b"\xff\xfe") + + assert collect_extension_events(tmp_path) == {} + def test_event_command_ref_canonicalized_via_manifest(self, tmp_path): """R1: events are read from a validated ExtensionManifest, so an obsolete command ref (e.g. my-ext.boot) is canonicalized @@ -227,6 +251,8 @@ def test_opencode_limited(self): integration = OpencodeIntegration() assert integration.supports_events() is True assert integration.CANONICAL_TO_NATIVE["pre_tool_use"] == "tool.execute.before" + assert integration.CANONICAL_TO_NATIVE["session_start"] == "experimental.chat.system.transform" + assert integration.CANONICAL_TO_NATIVE["user_prompt_submit"] == "chat.message" assert "stop" not in integration.CANONICAL_TO_NATIVE def test_copilot_mapping(self): @@ -647,6 +673,104 @@ def test_copilot_stop_mapping(self): # -- Shell quoting & matcher escaping (R2, R4) ------------------------------- +class TestContextInjectionEnvelopes: + """C13: context-injection envelope resolution and emission.""" + + def test_emit_event_stdout_wrapping(self, capsys): + from specify_cli.events import _emit_event_stdout + + _emit_event_stdout("hello ctx", "plain") + assert capsys.readouterr().out == "hello ctx" + + # hookSpecificOutput without native_event: no hookEventName (backward + # compat for callers that don't pass it). + _emit_event_stdout("hello ctx", "hookSpecificOutput") + assert json.loads(capsys.readouterr().out.strip()) == { + "hookSpecificOutput": {"additionalContext": "hello ctx"} + } + + # hookSpecificOutput with native_event: hookEventName included + # (required by Qwen's hooks spec; derived from Claude Code's). + _emit_event_stdout("hello ctx", "hookSpecificOutput", "SessionStart") + assert json.loads(capsys.readouterr().out.strip()) == { + "hookSpecificOutput": { + "additionalContext": "hello ctx", + "hookEventName": "SessionStart", + } + } + + _emit_event_stdout("hello ctx", "additionalContext") + assert json.loads(capsys.readouterr().out.strip()) == { + "additionalContext": "hello ctx" + } + + _emit_event_stdout("hello ctx", "additional_context") + assert json.loads(capsys.readouterr().out.strip()) == { + "additional_context": "hello ctx" + } + + _emit_event_stdout("hello ctx", "suppress") + assert capsys.readouterr().out == "" + + # Empty output emits nothing under any envelope. + _emit_event_stdout("", "additionalContext") + assert capsys.readouterr().out == "" + + def test_envelope_resolution_and_command_formatting(self): + from specify_cli.events import _dispatcher_command, _context_envelope_for + from specify_cli.integrations.gemini import GeminiIntegration + from specify_cli.integrations.qwen import QwenIntegration + from specify_cli.integrations.copilot import CopilotIntegration + from specify_cli.integrations.cursor_agent import CursorAgentIntegration + from specify_cli.integrations.claude import ClaudeIntegration + from specify_cli.integrations.codex import CodexIntegration + + gemini = GeminiIntegration() + assert _context_envelope_for(gemini, "session_start") == "hookSpecificOutput" + assert _context_envelope_for(gemini, "user_prompt_submit") == "hookSpecificOutput" + assert _context_envelope_for(gemini, "pre_tool_use") == "suppress" + + # hookSpecificOutput appends the native event name as a 6th dispatcher + # argument so the dispatcher can populate hookEventName. The default + # timeout (60s) is always emitted as the 4th arg to keep positional + # alignment (R3). + cmd_gemini_start = _dispatcher_command(gemini, Path("/proj"), "speckit.boot", "session_start") + assert cmd_gemini_start.endswith(" 60 hookSpecificOutput SessionStart") + + cmd_gemini_prompt = _dispatcher_command(gemini, Path("/proj"), "speckit.prompt", "user_prompt_submit") + assert cmd_gemini_prompt.endswith(" 60 hookSpecificOutput BeforeAgent") + + cmd_gemini_tool = _dispatcher_command(gemini, Path("/proj"), "speckit.guard", "pre_tool_use") + assert cmd_gemini_tool.endswith(" 60 suppress") + + # Qwen uses the same hookSpecificOutput protocol with its own native + # event names; verify hookEventName threading for Qwen's CamelCase names. + qwen = QwenIntegration() + cmd_qwen_start = _dispatcher_command(qwen, Path("/proj"), "speckit.boot", "session_start") + assert cmd_qwen_start.endswith(" 60 hookSpecificOutput SessionStart") + cmd_qwen_prompt = _dispatcher_command(qwen, Path("/proj"), "speckit.prompt", "user_prompt_submit") + assert cmd_qwen_prompt.endswith(" 60 hookSpecificOutput UserPromptSubmit") + + copilot = CopilotIntegration() + assert _context_envelope_for(copilot, "session_start") == "additionalContext" + assert _context_envelope_for(copilot, "user_prompt_submit") == "additionalContext" + cmd_copilot_start = _dispatcher_command(copilot, Path("/proj"), "speckit.boot", "session_start") + assert cmd_copilot_start.endswith(" 60 additionalContext") + cmd_copilot_prompt = _dispatcher_command(copilot, Path("/proj"), "speckit.prompt", "user_prompt_submit") + assert cmd_copilot_prompt.endswith(" 60 additionalContext") + + cursor = CursorAgentIntegration() + assert _context_envelope_for(cursor, "session_start") == "additional_context" + assert _context_envelope_for(cursor, "user_prompt_submit") == "suppress" + cmd_cursor_start = _dispatcher_command(cursor, Path("/proj"), "speckit.boot", "session_start") + assert cmd_cursor_start.endswith(" 60 additional_context") + + claude = ClaudeIntegration() + codex = CodexIntegration() + assert _context_envelope_for(claude, "session_start") is None + assert _context_envelope_for(codex, "session_start") is None + + class TestDispatcherCommandQuoting: """R2: dispatcher command components are shell-quoted so spaces and shell metacharacters are passed as single arguments, not reinterpreted.""" @@ -744,6 +868,59 @@ def test_matcher_with_quote_stays_valid_toml(self, tmp_path): assert group["matcher"] == 'Ba"sh' +class TestTomlUnreadableConfig: + """An undecodable user config.toml must not crash install or teardown. + + Every JSON merge/remove path goes through ``_load_user_json``, which + skips on an unreadable or malformed file to preserve user content (#22). + The TOML merge and remove read the user's config.toml with no boundary, + so a non-UTF-8 (or otherwise unreadable) file crashed + ``install_integration_events``/``remove_integration_events`` with a raw + ``UnicodeDecodeError`` — and the merge path would have regenerated the + file, discarding the user's bytes, had it not crashed first. + """ + + def test_merge_skips_unreadable_config_and_preserves_bytes(self, tmp_path): + from specify_cli.integrations.codex import CodexIntegration + + integration = CodexIntegration() + manifest = _claude_manifest(tmp_path) + config_path = tmp_path / ".codex" / "config.toml" + config_path.parent.mkdir(parents=True) + user_bytes = b"# codex config \xff\xfe not utf-8\n" + config_path.write_bytes(user_bytes) + + install_integration_events( + integration, tmp_path, manifest, + {"pre_tool_use": [{"command": "speckit.tdd.validate"}]}, + ) + + # User bytes preserved and the skipped file is not tracked (S5). + assert config_path.read_bytes() == user_bytes + manifest.record_existing.assert_not_called() + + def test_teardown_skips_unreadable_config_and_preserves_bytes(self, tmp_path): + from specify_cli.integrations.codex import CodexIntegration + + integration = CodexIntegration() + manifest = _claude_manifest(tmp_path) + install_integration_events( + integration, tmp_path, manifest, + {"pre_tool_use": [{"command": "speckit.tdd.validate"}]}, + ) + config_path = tmp_path / ".codex" / "config.toml" + assert config_path.is_file() + + # The user (or another tool) rewrites the config as non-UTF-8 + # between install and uninstall. + user_bytes = b"# rewritten \xff\xfe not utf-8\n" + config_path.write_bytes(user_bytes) + + remove_integration_events(integration, tmp_path, manifest) + + assert config_path.read_bytes() == user_bytes + + # -- Opencode TS Plugin merging --------------------------------------------- class TestOpencodePluginMerging: @@ -759,6 +936,7 @@ def test_opencode_ts_plugin_generation(self, tmp_path): events = { "pre_tool_use": [{"command": "speckit.tdd.validate", "matcher": "Edit"}], "session_start": [{"command": "speckit.agent-context.update"}], + "session_end": [{"command": "speckit.agent-context.teardown"}], } install_integration_events(integration, tmp_path, manifest, events) @@ -767,13 +945,50 @@ def test_opencode_ts_plugin_generation(self, tmp_path): content = plugin_path.read_text() assert "runEvent" in content assert "tool.execute.before" in content - assert "session.created" in content + assert "experimental.chat.system.transform" in content assert "speckit.tdd.validate" in content assert "speckit.agent-context.update" in content # #13: failures must propagate via throw, not process.exit(2) which # would kill the OpenCode host process. assert "process.exit(2)" not in content assert "throw new Error" in content + # session_start (experimental.chat.system.transform) must be guarded + # so canonical session-start handlers only run when a session is + # present — OpenCode fires this hook for non-session operations + # (e.g. agent generation) with no sessionID. + assert "if (!input.sessionID) return;" in content + # session_start handler output is cached per sessionID so non-idempotent + # handlers run once per session instead of on every LLM request. + assert "sessionStartCache" in content + assert "sessionStartCache.get(input.sessionID)" in content + assert "sessionStartCache.set(input.sessionID" in content + # Cache is evicted on session.deleted (session_end). + assert "sessionStartCache.delete(event.sessionID)" in content + + def test_opencode_ts_plugin_chat_message_part_injection(self, tmp_path): + """user_prompt_submit emits chat.message pushing a synthetic TextPart. + The part ID derives from output.parts[last].id (prt_ brand preserved) + with a prt_ fallback to prevent OpenCode session schema crashes.""" + integration = OpencodeIntegration() + manifest = MagicMock(spec=IntegrationManifest) + manifest.files = {} + manifest.record_file = MagicMock() + manifest.record_existing = MagicMock() + + events = { + "user_prompt_submit": [{"command": "speckit.discover"}], + } + install_integration_events(integration, tmp_path, manifest, events) + + plugin_path = tmp_path / ".opencode/plugin/speckit-events.ts" + assert plugin_path.is_file() + content = plugin_path.read_text() + assert "chat.message" in content + assert "output.parts.push" in content + assert "synthetic: true" in content + assert 'type: "text"' in content + assert "output.parts[output.parts.length - 1]?.id" in content + assert '?? "prt_"' in content def test_opencode_ts_plugin_resolves_interpreter_and_directory_at_load(self, tmp_path): """C8/C9: the dispatcher + interpreter are resolved per-project at @@ -1024,6 +1239,32 @@ def test_py_variant_anchored_under_specify(self, tmp_path): assert PurePath(argv[1]).as_posix().endswith(".specify/scripts/python/boot.py") assert ".specify" in argv[1] + def test_unparseable_script_command_returns_none(self, tmp_path): + """A ``scripts:`` value shlex cannot tokenize must resolve to no argv. + + The generated dispatcher's ``_resolve_argv`` twin wraps its + ``shlex.split`` in ``except ValueError: return None``, but the + CLI-side resolver did not: an unclosed quote in a ``scripts:`` + frontmatter value raised a raw ``ValueError: No closing quotation`` + through ``resolve_and_run_event_command`` instead of degrading to + "no runnable script" like every other malformed-input case here. + """ + from specify_cli.events import _resolve_event_command_argv + + cmd_dir = tmp_path / ".specify" / "templates" / "commands" + cmd_dir.mkdir(parents=True) + (cmd_dir / "boot.md").write_text( + "---\n" + "description: \"Boot\"\n" + "scripts:\n" + " sh: scripts/bash/boot.sh \"unclosed\n" + "---\nBody\n", + encoding="utf-8", + ) + + argv = _resolve_event_command_argv(cmd_dir / "boot.md", tmp_path, None) + assert argv is None + def test_ps_variant_prefixed_with_powershell_launcher(self, tmp_path): """S6: the ps variant prefixes argv with pwsh/powershell -File so subprocess.run(shell=False) can execute the .ps1 script.""" @@ -1102,7 +1343,7 @@ def test_dispatcher_is_self_contained(self, tmp_path): content = (tmp_path / EVENTS_DISPATCHER_REL).read_text() # Delegates to specify_cli when importable. assert "from specify_cli.events import resolve_and_run_event_command" in content - assert "except ImportError" in content + assert "except (ImportError, TypeError):" in content # Inline stdlib fallback resolver for one-time/temporary installs. assert "_run_inline" in content assert "_find_command_template" in content diff --git a/tests/integrations/test_extra_args.py b/tests/integrations/test_extra_args.py index e329c88801..84f48a5fd0 100644 --- a/tests/integrations/test_extra_args.py +++ b/tests/integrations/test_extra_args.py @@ -426,7 +426,7 @@ class _Result: return _Result() -def test_copilot_dispatch_command_includes_extra_args(monkeypatch): +def test_copilot_commands_dispatch_includes_extra_args(monkeypatch): """Locks the bypass fix: `CopilotIntegration.dispatch_command` must honour `SPECKIT_INTEGRATION_COPILOT_EXTRA_ARGS`, not just `build_exec_args`. """ @@ -441,9 +441,9 @@ def test_copilot_dispatch_command_includes_extra_args(monkeypatch): "SPECKIT_INTEGRATION_COPILOT_EXTRA_ARGS", "--allow-tool 'shell(echo)'" ) - CopilotIntegration().dispatch_command( - "speckit.plan", args="body", stream=False - ) + integration = CopilotIntegration() + integration._skills_mode = False + integration.dispatch_command("speckit.plan", args="body", stream=False) assert capture.captured_args is not None # Hook inserted between `-p prompt` and the canonical Copilot flags. diff --git a/tests/integrations/test_integration_copilot.py b/tests/integrations/test_integration_copilot.py index b0ff771965..9138b9ad08 100644 --- a/tests/integrations/test_integration_copilot.py +++ b/tests/integrations/test_integration_copilot.py @@ -2,9 +2,9 @@ import json import os -import warnings import pytest +import typer import yaml from specify_cli.integrations import get_integration @@ -12,7 +12,7 @@ from tests.conftest import _cmd_prefix, _is_fork, _skill_prefix, install_preset_to -class TestCopilotIntegration: +class TestCopilotCommandsMode: def test_copilot_key_and_config(self): copilot = get_integration("copilot") assert copilot is not None @@ -31,7 +31,7 @@ def test_setup_creates_agent_md_files(self, tmp_path): from specify_cli.integrations.copilot import CopilotIntegration copilot = CopilotIntegration() m = IntegrationManifest("copilot", tmp_path) - created = copilot.setup(tmp_path, m) + created = copilot.setup(tmp_path, m, parsed_options={"commands": True}) assert len(created) > 0 agent_files = [f for f in created if ".agent." in f.name] assert len(agent_files) > 0 @@ -39,36 +39,11 @@ def test_setup_creates_agent_md_files(self, tmp_path): assert f.parent == tmp_path / ".github" / "agents" assert f.name.endswith(".agent.md") - def test_setup_warns_legacy_markdown_default_is_deprecated(self, tmp_path): - from specify_cli.integrations.copilot import CopilotIntegration - copilot = CopilotIntegration() - m = IntegrationManifest("copilot", tmp_path) - - with pytest.warns(UserWarning, match="Copilot legacy markdown mode is deprecated"): - created = copilot.setup(tmp_path, m) - - assert any(f.name.endswith(".agent.md") for f in created) - - def test_skills_setup_does_not_warn_about_legacy_default(self, tmp_path): - from specify_cli.integrations.copilot import CopilotIntegration - copilot = CopilotIntegration() - m = IntegrationManifest("copilot", tmp_path) - - with warnings.catch_warnings(record=True) as caught: - warnings.simplefilter("always") - created = copilot.setup(tmp_path, m, parsed_options={"skills": True}) - - assert not any( - "Copilot legacy markdown mode is deprecated" in str(item.message) - for item in caught - ) - assert any(f.name == "SKILL.md" for f in created) - def test_setup_creates_companion_prompts(self, tmp_path): from specify_cli.integrations.copilot import CopilotIntegration copilot = CopilotIntegration() m = IntegrationManifest("copilot", tmp_path) - created = copilot.setup(tmp_path, m) + created = copilot.setup(tmp_path, m, parsed_options={"commands": True}) prompt_files = [f for f in created if f.parent.name == "prompts"] assert len(prompt_files) > 0 for f in prompt_files: @@ -80,7 +55,7 @@ def test_agent_and_prompt_counts_match(self, tmp_path): from specify_cli.integrations.copilot import CopilotIntegration copilot = CopilotIntegration() m = IntegrationManifest("copilot", tmp_path) - created = copilot.setup(tmp_path, m) + created = copilot.setup(tmp_path, m, parsed_options={"commands": True}) agents = [f for f in created if ".agent.md" in f.name] prompts = [f for f in created if ".prompt.md" in f.name] assert len(agents) == len(prompts) @@ -90,7 +65,7 @@ def test_setup_creates_vscode_settings_new(self, tmp_path): copilot = CopilotIntegration() assert copilot._vscode_settings_path() is not None m = IntegrationManifest("copilot", tmp_path) - created = copilot.setup(tmp_path, m) + created = copilot.setup(tmp_path, m, parsed_options={"commands": True}) settings = tmp_path / ".vscode" / "settings.json" assert settings.exists() assert settings in created @@ -104,7 +79,7 @@ def test_setup_merges_existing_vscode_settings(self, tmp_path): existing = {"editor.fontSize": 14, "custom.setting": True} (vscode_dir / "settings.json").write_text(json.dumps(existing, indent=4), encoding="utf-8") m = IntegrationManifest("copilot", tmp_path) - created = copilot.setup(tmp_path, m) + created = copilot.setup(tmp_path, m, parsed_options={"commands": True}) settings = tmp_path / ".vscode" / "settings.json" data = json.loads(settings.read_text(encoding="utf-8")) assert data["editor.fontSize"] == 14 @@ -122,7 +97,7 @@ def test_setup_preserves_non_utf8_vscode_settings(self, tmp_path, caplog): settings.write_bytes(original) m = IntegrationManifest("copilot", tmp_path) - copilot.setup(tmp_path, m) + copilot.setup(tmp_path, m, parsed_options={"commands": True}) assert settings.read_bytes() == original assert "Could not parse" in caplog.text @@ -131,7 +106,7 @@ def test_all_created_files_tracked_in_manifest(self, tmp_path): from specify_cli.integrations.copilot import CopilotIntegration copilot = CopilotIntegration() m = IntegrationManifest("copilot", tmp_path) - created = copilot.setup(tmp_path, m) + created = copilot.setup(tmp_path, m, parsed_options={"commands": True}) for f in created: rel = f.resolve().relative_to(tmp_path.resolve()).as_posix() assert rel in m.files, f"Created file {rel} not tracked in manifest" @@ -140,7 +115,9 @@ def test_install_uninstall_roundtrip(self, tmp_path): from specify_cli.integrations.copilot import CopilotIntegration copilot = CopilotIntegration() m = IntegrationManifest("copilot", tmp_path) - created = copilot.install(tmp_path, m) + created = copilot.install( + tmp_path, m, parsed_options={"commands": True} + ) assert len(created) > 0 m.save() for f in created: @@ -153,7 +130,9 @@ def test_modified_file_survives_uninstall(self, tmp_path): from specify_cli.integrations.copilot import CopilotIntegration copilot = CopilotIntegration() m = IntegrationManifest("copilot", tmp_path) - created = copilot.install(tmp_path, m) + created = copilot.install( + tmp_path, m, parsed_options={"commands": True} + ) m.save() modified_file = created[0] modified_file.write_text("user modified this", encoding="utf-8") @@ -165,7 +144,7 @@ def test_directory_structure(self, tmp_path): from specify_cli.integrations.copilot import CopilotIntegration copilot = CopilotIntegration() m = IntegrationManifest("copilot", tmp_path) - copilot.setup(tmp_path, m) + copilot.setup(tmp_path, m, parsed_options={"commands": True}) agents_dir = tmp_path / ".github" / "agents" assert agents_dir.is_dir() agent_files = sorted(agents_dir.glob(f"{_cmd_prefix()}.*.agent.md")) @@ -181,7 +160,7 @@ def test_templates_are_processed(self, tmp_path): from specify_cli.integrations.copilot import CopilotIntegration copilot = CopilotIntegration() m = IntegrationManifest("copilot", tmp_path) - copilot.setup(tmp_path, m) + copilot.setup(tmp_path, m, parsed_options={"commands": True}) agents_dir = tmp_path / ".github" / "agents" for agent_file in agents_dir.glob(f"{_cmd_prefix()}.*.agent.md"): content = agent_file.read_text(encoding="utf-8") @@ -196,7 +175,7 @@ def test_specify_agent_resolves_active_spec_template(self, tmp_path): from specify_cli.integrations.copilot import CopilotIntegration copilot = CopilotIntegration() m = IntegrationManifest("copilot", tmp_path) - copilot.setup(tmp_path, m) + copilot.setup(tmp_path, m, parsed_options={"commands": True}) specify_file = tmp_path / ".github" / "agents" / f"{_cmd_prefix()}.specify.agent.md" content = specify_file.read_text(encoding="utf-8") @@ -213,7 +192,7 @@ def test_setup_falls_back_to_bundled_command_template_without_preset_override(se copilot = CopilotIntegration() m = IntegrationManifest("copilot", tmp_path) - copilot.setup(tmp_path, m) + copilot.setup(tmp_path, m, parsed_options={"commands": True}) specify_file = tmp_path / ".github" / "agents" / f"{_cmd_prefix()}.specify.agent.md" content = specify_file.read_text(encoding="utf-8") @@ -238,7 +217,7 @@ def test_setup_uses_preset_command_override_when_present(self, tmp_path): encoding="utf-8", ) - copilot.setup(tmp_path, m) + copilot.setup(tmp_path, m, parsed_options={"commands": True}) specify_file = tmp_path / ".github" / "agents" / f"{_cmd_prefix()}.specify.agent.md" content = specify_file.read_text(encoding="utf-8") @@ -251,14 +230,14 @@ def test_plan_command_has_no_context_placeholder(self, tmp_path): from specify_cli.integrations.copilot import CopilotIntegration copilot = CopilotIntegration() m = IntegrationManifest("copilot", tmp_path) - copilot.setup(tmp_path, m) + copilot.setup(tmp_path, m, parsed_options={"commands": True}) plan_file = tmp_path / ".github" / "agents" / f"{_cmd_prefix()}.plan.agent.md" assert plan_file.exists() content = plan_file.read_text(encoding="utf-8") assert "__CONTEXT_FILE__" not in content def test_complete_file_inventory_sh(self, tmp_path): - """Every file produced by specify init --integration copilot --script sh.""" + """Every file produced by Copilot commands mode with shell scripts.""" from typer.testing import CliRunner from specify_cli import app project = tmp_path / "inventory-sh" @@ -267,7 +246,8 @@ def test_complete_file_inventory_sh(self, tmp_path): try: os.chdir(project) result = CliRunner().invoke(app, [ - "init", "--here", "--integration", "copilot", "--script", "sh", + "init", "--here", "--integration", "copilot", + "--integration-options", "--commands", "--script", "sh", ], catch_exceptions=False) finally: os.chdir(old_cwd) @@ -331,7 +311,7 @@ def test_complete_file_inventory_sh(self, tmp_path): ) def test_complete_file_inventory_ps(self, tmp_path): - """Every file produced by specify init --integration copilot --script ps.""" + """Every file produced by Copilot commands mode with PowerShell scripts.""" from typer.testing import CliRunner from specify_cli import app project = tmp_path / "inventory-ps" @@ -340,7 +320,8 @@ def test_complete_file_inventory_ps(self, tmp_path): try: os.chdir(project) result = CliRunner().invoke(app, [ - "init", "--here", "--integration", "copilot", "--script", "ps", + "init", "--here", "--integration", "copilot", + "--integration-options", "--commands", "--script", "ps", ], catch_exceptions=False) finally: os.chdir(old_cwd) @@ -403,54 +384,8 @@ def test_complete_file_inventory_ps(self, tmp_path): f"Extra: {sorted(set(actual) - set(expected))}" ) - def test_default_cli_init_warns_legacy_markdown_is_deprecated(self, tmp_path): - """Default Copilot init should warn users about the future skills default.""" - from typer.testing import CliRunner - from specify_cli import app - project = tmp_path / "default-warning" - project.mkdir() - old_cwd = os.getcwd() - try: - os.chdir(project) - with pytest.warns( - UserWarning, - match="Copilot legacy markdown mode is deprecated", - ): - result = CliRunner().invoke(app, [ - "init", "--here", "--integration", "copilot", "--script", "sh", - ], catch_exceptions=False) - finally: - os.chdir(old_cwd) - - assert result.exit_code == 0, result.output - - def test_skills_cli_init_does_not_warn_about_legacy_markdown(self, tmp_path): - """Explicit Copilot skills mode should not warn about the legacy default.""" - from typer.testing import CliRunner - from specify_cli import app - project = tmp_path / "skills-no-warning" - project.mkdir() - old_cwd = os.getcwd() - try: - os.chdir(project) - with warnings.catch_warnings(record=True) as caught: - warnings.simplefilter("always") - result = CliRunner().invoke(app, [ - "init", "--here", "--integration", "copilot", - "--integration-options", "--skills", "--script", "sh", - ], catch_exceptions=False) - finally: - os.chdir(old_cwd) - - assert result.exit_code == 0, result.output - assert not any( - "Copilot legacy markdown mode is deprecated" in str(item.message) - for item in caught - ) - - class TestCopilotSkillsMode: - """Tests for Copilot integration in --skills mode.""" + """Tests for Copilot's default skills mode.""" _SKILL_COMMANDS = [ "analyze", "clarify", "constitution", "converge", "implement", @@ -463,7 +398,7 @@ def _make_copilot(self): def _setup_skills(self, copilot, tmp_path): m = IntegrationManifest("copilot", tmp_path) - created = copilot.setup(tmp_path, m, parsed_options={"skills": True}) + created = copilot.setup(tmp_path, m) return created, m # -- Options ---------------------------------------------------------- @@ -476,6 +411,137 @@ def test_options_include_skills_flag(self): assert skills_opts[0].is_flag is True assert skills_opts[0].default is False + def test_options_include_commands_flag(self): + copilot = get_integration("copilot") + commands_opts = [o for o in copilot.options() if o.name == "--commands"] + assert len(commands_opts) == 1 + assert commands_opts[0].is_flag is True + assert commands_opts[0].default is False + + def test_default_is_skills_mode(self): + copilot = self._make_copilot() + assert copilot.is_skills_mode() is True + assert copilot.is_skills_mode({}) is True + + def test_commands_flag_disables_skills_mode(self): + copilot = self._make_copilot() + assert copilot.is_skills_mode({"commands": True}) is False + + def test_existing_commands_layout_is_preserved(self, tmp_path): + copilot = self._make_copilot() + agents_dir = tmp_path / ".github" / "agents" + agents_dir.mkdir(parents=True) + (agents_dir / "speckit.plan.agent.md").write_text( + "# plan\n", encoding="utf-8" + ) + assert copilot.is_skills_mode(project_root=tmp_path) is False + + def test_setup_preserves_existing_commands_without_stored_options( + self, tmp_path + ): + copilot = self._make_copilot() + agents_dir = tmp_path / ".github" / "agents" + agents_dir.mkdir(parents=True) + (agents_dir / "speckit.plan.agent.md").write_text( + "# old plan\n", encoding="utf-8" + ) + manifest = IntegrationManifest("copilot", tmp_path) + + created = copilot.setup(tmp_path, manifest) + + assert any(path.name.endswith(".agent.md") for path in created) + assert not (tmp_path / ".github" / "skills").exists() + assert copilot._skills_mode is False + + def test_existing_skills_layout_stays_in_skills_mode(self, tmp_path): + copilot = self._make_copilot() + (tmp_path / ".github" / "skills" / "speckit-plan").mkdir(parents=True) + assert copilot.is_skills_mode(project_root=tmp_path) is True + + def test_commands_manifest_wins_over_untracked_skill(self, tmp_path): + copilot = self._make_copilot() + manifest = IntegrationManifest("copilot", tmp_path) + copilot.setup( + tmp_path, manifest, parsed_options={"commands": True} + ) + manifest.save() + stale_skill = ( + tmp_path + / ".github" + / "skills" + / "speckit-plan" + / "SKILL.md" + ) + stale_skill.parent.mkdir(parents=True) + stale_skill.write_text("# user-authored skill\n", encoding="utf-8") + + assert copilot.is_skills_mode(project_root=tmp_path) is False + + def test_skills_manifest_wins_over_untracked_command(self, tmp_path): + copilot = self._make_copilot() + manifest = IntegrationManifest("copilot", tmp_path) + copilot.setup(tmp_path, manifest) + manifest.save() + stale_agent = ( + tmp_path + / ".github" + / "agents" + / "speckit.plan.agent.md" + ) + stale_agent.parent.mkdir(parents=True) + stale_agent.write_text("# stale command\n", encoding="utf-8") + + assert copilot.is_skills_mode(project_root=tmp_path) is True + + def test_explicit_skills_forces_migration_from_commands(self, tmp_path): + copilot = self._make_copilot() + agents_dir = tmp_path / ".github" / "agents" + agents_dir.mkdir(parents=True) + (agents_dir / "speckit.plan.agent.md").write_text( + "# plan\n", encoding="utf-8" + ) + assert ( + copilot.is_skills_mode({"skills": True}, project_root=tmp_path) + is True + ) + + def test_skills_and_commands_flags_are_mutually_exclusive(self): + copilot = self._make_copilot() + with pytest.raises(typer.Exit): + copilot.is_skills_mode({"skills": True, "commands": True}) + + def test_cli_rejects_skills_and_commands_together(self, tmp_path): + from typer.testing import CliRunner + + from specify_cli import app + + project = tmp_path / "conflicting-modes" + project.mkdir() + old_cwd = os.getcwd() + try: + os.chdir(project) + result = CliRunner().invoke( + app, + [ + "init", + "--here", + "--integration", + "copilot", + "--integration-options", + "--skills --commands", + "--script", + "sh", + ], + catch_exceptions=False, + ) + finally: + os.chdir(old_cwd) + + assert result.exit_code == 1 + assert "--skills and --commands are mutually exclusive" in result.output + assert not (project / ".github" / "skills").exists() + assert not (project / ".github" / "agents").exists() + # -- Skills directory structure --------------------------------------- def test_skills_creates_skill_files(self, tmp_path): @@ -671,16 +737,16 @@ def test_skills_command_refs_use_hyphen(self, tmp_path): def test_skills_mode_invoke_separator(self): """Copilot effective_invoke_separator should reflect skills mode.""" copilot = self._make_copilot() - assert copilot.effective_invoke_separator() == "." + assert copilot.effective_invoke_separator() == "-" assert copilot.effective_invoke_separator({"skills": True}) == "-" - assert copilot.effective_invoke_separator({"skills": False}) == "." + assert copilot.effective_invoke_separator({"commands": True}) == "." def test_invoke_separator_for_mode_tracks_persisted_state(self): """Regression (review #3415): registration paths (preset/extension command refs) must resolve the separator from the persisted ai_skills state. A Copilot skills project renders ``/speckit-`` (hyphen), - matching ``build_command_invocation``; the default markdown layout - renders ``/speckit.`` (dot). + matching ``build_command_invocation``; commands mode renders + ``/speckit.`` (dot). """ copilot = self._make_copilot() assert copilot.invoke_separator_for_mode(True) == "-" @@ -721,7 +787,7 @@ def test_all_files_tracked_in_manifest(self, tmp_path): def test_install_uninstall_roundtrip(self, tmp_path): copilot = self._make_copilot() m = IntegrationManifest("copilot", tmp_path) - created = copilot.install(tmp_path, m, parsed_options={"skills": True}) + created = copilot.install(tmp_path, m) assert len(created) > 0 m.save() for f in created: @@ -733,7 +799,7 @@ def test_install_uninstall_roundtrip(self, tmp_path): def test_modified_file_survives_uninstall(self, tmp_path): copilot = self._make_copilot() m = IntegrationManifest("copilot", tmp_path) - created = copilot.install(tmp_path, m, parsed_options={"skills": True}) + created = copilot.install(tmp_path, m) m.save() modified_file = created[0] modified_file.write_text("user modified this", encoding="utf-8") @@ -750,9 +816,9 @@ def test_build_command_invocation_skills_mode(self): # result depends on whether the agentic-sdlc preset is installed at cwd. pfx = _skill_prefix("plan") assert copilot.build_command_invocation("speckit.plan") == f"/{pfx}-plan" - # Plain name: returned as-is (no prefix added by resolve_command_alias) - assert copilot.build_command_invocation("plan") == "/plan" - assert copilot.build_command_invocation("plan", "my args") == "/plan my args" + # Plain name: canonicalized to speckit.plan before alias resolution + assert copilot.build_command_invocation("plan") == f"/{pfx}-plan" + assert copilot.build_command_invocation("plan", "my args") == f"/{pfx}-plan my args" def test_build_command_invocation_skills_extension_command(self): copilot = self._make_copilot() @@ -766,6 +832,13 @@ def test_build_command_invocation_skills_extension_command(self): def test_build_command_invocation_default_mode(self): copilot = self._make_copilot() + pfx = _skill_prefix("plan") + assert copilot.build_command_invocation("plan", "my args") == f"/{pfx}-plan my args" + assert copilot.build_command_invocation("plan") == f"/{pfx}-plan" + + def test_build_command_invocation_commands_mode(self): + copilot = self._make_copilot() + copilot._skills_mode = False assert copilot.build_command_invocation("plan", "my args") == "my args" assert copilot.build_command_invocation("plan") == "" @@ -781,8 +854,8 @@ def test_skills_setup_does_not_write_context_section(self, tmp_path): # -- CLI integration test --------------------------------------------- - def test_init_with_integration_options_skills(self, tmp_path): - """specify init --integration copilot --integration-options='--skills' scaffolds skills.""" + def test_init_defaults_to_skills(self, tmp_path): + """specify init --integration copilot scaffolds skills by default.""" from typer.testing import CliRunner from specify_cli import app project = tmp_path / "copilot-skills" @@ -792,7 +865,6 @@ def test_init_with_integration_options_skills(self, tmp_path): os.chdir(project) result = CliRunner().invoke(app, [ "init", "--here", "--integration", "copilot", - "--integration-options", "--skills", "--script", "sh", ], catch_exceptions=False) finally: @@ -808,7 +880,7 @@ def test_init_with_integration_options_skills(self, tmp_path): assert not (project / ".vscode" / "settings.json").exists() def test_complete_file_inventory_skills_sh(self, tmp_path): - """Every file produced by specify init --integration copilot --integration-options='--skills' --script sh.""" + """Every file produced by default Copilot init with shell scripts.""" from typer.testing import CliRunner from specify_cli import app project = tmp_path / "inventory-skills-sh" @@ -818,7 +890,6 @@ def test_complete_file_inventory_skills_sh(self, tmp_path): os.chdir(project) result = CliRunner().invoke(app, [ "init", "--here", "--integration", "copilot", - "--integration-options", "--skills", "--script", "sh", ], catch_exceptions=False) finally: @@ -869,36 +940,46 @@ def test_complete_file_inventory_skills_sh(self, tmp_path): # -- Singleton leak: _skills_mode must reset -------------------------- - def test_skills_mode_resets_on_default_setup(self, tmp_path): - """setup() with skills=True then without must reset _skills_mode.""" + def test_skills_mode_resets_between_layouts(self, tmp_path): + """setup() must reset the singleton mode for each selected layout.""" copilot = self._make_copilot() - # First call: skills mode + # First call: default skills mode (tmp_path / "proj1").mkdir() m1 = IntegrationManifest("copilot", tmp_path / "proj1") - copilot.setup(tmp_path / "proj1", m1, parsed_options={"skills": True}) + copilot.setup(tmp_path / "proj1", m1) assert copilot._skills_mode is True - # Second call: default mode (no skills option) + # Second call: explicit commands mode (tmp_path / "proj2").mkdir() m2 = IntegrationManifest("copilot", tmp_path / "proj2") - copilot.setup(tmp_path / "proj2", m2) + copilot.setup( + tmp_path / "proj2", m2, parsed_options={"commands": True} + ) assert copilot._skills_mode is False - - # build_command_invocation must use default (dotted) mode assert copilot.build_command_invocation("plan", "args") == "args" - # -- Auto-detection must ignore unrelated .github/skills/ ------------- + # Third call: a fresh default project must switch back to skills. + (tmp_path / "proj3").mkdir() + m3 = IntegrationManifest("copilot", tmp_path / "proj3") + copilot.setup(tmp_path / "proj3", m3) + assert copilot._skills_mode is True + assert copilot.build_command_invocation("plan") == f"/{_skill_prefix('plan')}-plan" + + # -- Auto-detection must preserve managed commands -------------------- - def test_dispatch_ignores_unrelated_skills_directory(self, tmp_path): - """dispatch_command() must not treat unrelated .github/skills/ as skills mode.""" + def test_dispatch_preserves_commands_with_unrelated_skills(self, tmp_path): + """Unrelated skills must not migrate a managed commands layout.""" copilot = self._make_copilot() - # Create a .github/skills/ with non-speckit content (e.g. GitHub Skills training) + agents_dir = tmp_path / ".github" / "agents" + agents_dir.mkdir(parents=True) + (agents_dir / "speckit.plan.agent.md").write_text( + "# plan\n", encoding="utf-8" + ) unrelated = tmp_path / ".github" / "skills" / "introduction-to-github" unrelated.mkdir(parents=True) (unrelated / "README.md").write_text("# GitHub Skills training\n") - # Should NOT detect skills mode — cli_args should contain --agent import unittest.mock as mock with mock.patch("subprocess.run") as mock_run: mock_run.return_value = mock.Mock(returncode=0, stdout="", stderr="") @@ -937,7 +1018,7 @@ def test_dispatch_detects_speckit_skills_layout(self, tmp_path): # -- Next-steps display for Copilot skills mode ----------------------- def test_init_skills_next_steps_show_skill_syntax(self, tmp_path): - """specify init --integration copilot --integration-options='--skills' shows /speckit-plan not /speckit.plan.""" + """Default Copilot init shows /speckit-plan, not /speckit.plan.""" from typer.testing import CliRunner from specify_cli import app project = tmp_path / "copilot-nextsteps" @@ -947,7 +1028,6 @@ def test_init_skills_next_steps_show_skill_syntax(self, tmp_path): os.chdir(project) result = CliRunner().invoke(app, [ "init", "--here", "--integration", "copilot", - "--integration-options", "--skills", ], catch_exceptions=False) finally: os.chdir(old_cwd) diff --git a/tests/integrations/test_integration_kimi.py b/tests/integrations/test_integration_kimi.py index 47533680a2..c1ab31b8a9 100644 --- a/tests/integrations/test_integration_kimi.py +++ b/tests/integrations/test_integration_kimi.py @@ -200,6 +200,24 @@ def test_teardown_preserves_user_skills_in_legacy_dir(self, tmp_path): assert user_skill.exists() + def test_teardown_preserves_non_utf8_user_skill(self, tmp_path): + i = get_integration("kimi") + + user_skill = ( + tmp_path + / ".kimi" + / "skills" + / "speckit-user-owned" + / "SKILL.md" + ) + user_skill.parent.mkdir(parents=True) + user_skill.write_bytes(b"\xff\xfe") + + m = IntegrationManifest("kimi", tmp_path) + i.teardown(tmp_path, m) + + assert user_skill.read_bytes() == b"\xff\xfe" + class TestKimiCommandInvocation: """Kimi dispatch must use the native ``/skill:`` slash command.""" diff --git a/tests/integrations/test_integration_state.py b/tests/integrations/test_integration_state.py index fc12d436a4..ebedc1056c 100644 --- a/tests/integrations/test_integration_state.py +++ b/tests/integrations/test_integration_state.py @@ -89,10 +89,10 @@ def test_write_integration_json_strips_integration_key(tmp_path): def test_with_integration_setting_recomputes_separator_from_retained_options(): """Updating only script_type must not drop an options-dependent separator. - Copilot resolves the command-ref separator to '-' when '--skills' options - are stored and '.' otherwise. A second call that changes only script_type + Copilot resolves the command-ref separator to '.' when '--commands' is + stored and '-' by default. A second call that changes only script_type (parsed_options=None, raw_options=None) retains the stored parsed_options, - so invoke_separator must stay '-', not be recomputed from the None argument. + so invoke_separator must stay '.', not be recomputed from the None argument. """ from specify_cli.integrations import get_integration from specify_cli.integration_runtime import with_integration_setting @@ -100,15 +100,15 @@ def test_with_integration_setting_recomputes_separator_from_retained_options(): copilot = get_integration("copilot") settings = with_integration_setting( - {}, "copilot", copilot, parsed_options={"skills": True} + {}, "copilot", copilot, parsed_options={"commands": True} ) - assert settings["copilot"]["invoke_separator"] == "-" + assert settings["copilot"]["invoke_separator"] == "." settings2 = with_integration_setting( {"integration_settings": settings}, "copilot", copilot, script_type="ps" ) # parsed_options are retained (only script_type changed) ... - assert settings2["copilot"]["parsed_options"] == {"skills": True} + assert settings2["copilot"]["parsed_options"] == {"commands": True} assert settings2["copilot"]["script"] == "ps" # ... so the separator must reflect them, not the (None) argument. - assert settings2["copilot"]["invoke_separator"] == "-" + assert settings2["copilot"]["invoke_separator"] == "." diff --git a/tests/integrations/test_integration_subcommand.py b/tests/integrations/test_integration_subcommand.py index eb4ccc49fd..020cb8dcbf 100644 --- a/tests/integrations/test_integration_subcommand.py +++ b/tests/integrations/test_integration_subcommand.py @@ -1797,15 +1797,99 @@ def test_switch_between_integrations(self, tmp_path): # Old claude files removed assert not (project / ".claude" / "skills" / _skill_dir_name("plan", project_root=project) / "SKILL.md").exists() - # New copilot files created - assert (project / ".github" / "agents" / f"{_cmd_prefix()}.plan.agent.md").exists() - assert f"{_content_ref('specify', '.')}" in shared_script.read_text(encoding="utf-8") - assert f"{_content_ref('specify')}" not in shared_script.read_text(encoding="utf-8") + # New default Copilot skills created + assert ( + project / ".github" / "skills" / _skill_dir_name("plan", project_root=project) / "SKILL.md" + ).exists() + assert f"{_content_ref('specify')}" in shared_script.read_text(encoding="utf-8") + assert f"{_content_ref('specify', '.')}" not in shared_script.read_text(encoding="utf-8") # integration.json updated data = json.loads((project / ".specify" / "integration.json").read_text(encoding="utf-8")) assert data["integration"] == "copilot" + def test_switch_rejects_conflicting_copilot_modes_before_uninstall( + self, tmp_path + ): + project = _init_project(tmp_path, "claude") + claude_skill = ( + project / ".claude" / "skills" / "speckit-plan" / "SKILL.md" + ) + before_state = json.loads( + (project / ".specify" / "integration.json").read_text( + encoding="utf-8" + ) + ) + + result = _run_in_project( + project, + [ + "integration", + "switch", + "copilot", + "--integration-options", + "--skills --commands", + "--script", + "sh", + ], + ) + + assert result.exit_code == 1 + assert "--skills and --commands are mutually exclusive" in result.output + assert claude_skill.exists() + assert not (project / ".github" / "skills").exists() + assert not (project / ".github" / "agents").exists() + after_state = json.loads( + (project / ".specify" / "integration.json").read_text( + encoding="utf-8" + ) + ) + assert after_state == before_state + + def test_switch_preserves_target_options_with_fallback_integration( + self, tmp_path + ): + project = _init_project(tmp_path, "claude") + install = _run_in_project( + project, + [ + "integration", + "install", + "opencode", + "--script", + "sh", + "--force", + ], + ) + assert install.exit_code == 0, install.output + + result = _run_in_project( + project, + [ + "integration", + "switch", + "copilot", + "--integration-options", + "--commands", + "--script", + "sh", + ], + ) + + assert result.exit_code == 0, result.output + assert ( + project / ".github" / "agents" / f"{_cmd_prefix()}.plan.agent.md" + ).exists() + assert not (project / ".github" / "skills").exists() + state = json.loads( + (project / ".specify" / "integration.json").read_text( + encoding="utf-8" + ) + ) + assert state["integration_settings"]["copilot"]["parsed_options"] == { + "commands": True + } + def test_switch_migrates_extension_commands(self, tmp_path): """Switching should migrate extension commands to the new agent directory.""" project = _init_project(tmp_path, "kimi") @@ -1994,6 +2078,7 @@ def test_switch_refreshes_managed_shared_script_refs(self, tmp_path): os.chdir(project) result = runner.invoke(app, [ "integration", "switch", "copilot", + "--integration-options", "--commands", "--script", "sh", ], catch_exceptions=False) finally: @@ -2032,6 +2117,7 @@ def test_switch_refreshes_stale_managed_shared_infra(self, tmp_path): os.chdir(project) result = runner.invoke(app, [ "integration", "switch", "copilot", + "--integration-options", "--commands", "--script", "sh", ], catch_exceptions=False) finally: @@ -2060,6 +2146,7 @@ def test_switch_preserves_user_customized_shared_infra(self, tmp_path): os.chdir(project) result = runner.invoke(app, [ "integration", "switch", "copilot", + "--integration-options", "--commands", "--script", "sh", ], catch_exceptions=False) finally: @@ -2084,6 +2171,7 @@ def test_switch_refresh_shared_infra_overwrites_customizations(self, tmp_path): os.chdir(project) result = runner.invoke(app, [ "integration", "switch", "copilot", + "--integration-options", "--commands", "--script", "sh", "--refresh-shared-infra", ], catch_exceptions=False) @@ -2349,7 +2437,9 @@ def fail_refresh(*args, **kwargs): assert manifest_path.read_text(encoding="utf-8") == before_manifest def test_upgrade_default_refreshes_shared_script_refs_for_option_separator_change(self, tmp_path): - project = _init_project(tmp_path, "copilot") + project = _init_project( + tmp_path, "copilot", integration_options="--commands" + ) template = project / ".specify" / "templates" / "plan-template.md" managed_script = project / ".specify" / "scripts" / "bash" / "check-prerequisites.sh" customized_script = project / ".specify" / "scripts" / "bash" / "setup-tasks.sh" @@ -2378,6 +2468,49 @@ def test_upgrade_default_refreshes_shared_script_refs_for_option_separator_chang assert f"{_content_ref('specify', '.')}" not in managed_content assert customized_script.read_text(encoding="utf-8") == customized_before + def test_upgrade_preserves_historical_copilot_commands_without_options( + self, tmp_path + ): + """A command manifest restores missing files instead of migrating.""" + project = _init_project( + tmp_path, "copilot", integration_options="--commands" + ) + state_path = project / ".specify" / "integration.json" + state = json.loads(state_path.read_text(encoding="utf-8")) + copilot_settings = state["integration_settings"]["copilot"] + copilot_settings.pop("raw_options", None) + copilot_settings.pop("parsed_options", None) + state_path.write_text(json.dumps(state), encoding="utf-8") + + for path in (project / ".github" / "agents").glob( + "speckit.*.agent.md" + ): + path.unlink() + for path in (project / ".github" / "prompts").glob( + "speckit.*.prompt.md" + ): + path.unlink() + + result = _run_in_project( + project, + ["integration", "upgrade", "copilot", "--script", "sh", "--force"], + ) + + assert result.exit_code == 0, result.output + assert ( + project / ".github" / "agents" / f"{_cmd_prefix()}.plan.agent.md" + ).exists() + # Fork: model-invocation skills (quick-*) always exist for commands-mode + # agents; the migration signal is a command-derived skill dir. + assert not (project / ".github" / "skills" / "speckit-plan").exists() + assert not (project / ".github" / "skills" / "spec-plan").exists() + init_options = json.loads( + (project / ".specify" / "init-options.json").read_text( + encoding="utf-8" + ) + ) + assert init_options.get("ai_skills") is not True + def test_upgrade_non_default_keeps_default_template_invocations(self, tmp_path): project = _init_project(tmp_path, "gemini") template = project / ".specify" / "templates" / "plan-template.md" @@ -2465,7 +2598,9 @@ def test_upgrade_preserves_existing_vscode_settings(self, tmp_path): tracking it, so without ``stale_cleanup_exclusions()`` the Phase 2 stale cleanup would delete it (destroying the user's settings). """ - project = _init_project(tmp_path, "copilot") + project = _init_project( + tmp_path, "copilot", integration_options="--commands" + ) settings = project / ".vscode" / "settings.json" assert settings.is_file(), "init should create .vscode/settings.json" before = json.loads(settings.read_text(encoding="utf-8")) diff --git a/tests/test_commands_package.py b/tests/test_commands_package.py index b8cd262e89..a92470264a 100644 --- a/tests/test_commands_package.py +++ b/tests/test_commands_package.py @@ -50,3 +50,51 @@ def test_init_command_registered(): cmd.callback.__name__ for cmd in app.registered_commands if cmd.callback ] assert "init" in callback_names + + +def test_resolve_default_init_integration_unset(monkeypatch): + from specify_cli._agent_config import ( + DEFAULT_INIT_INTEGRATION, + DEFAULT_INIT_INTEGRATION_ENV_VAR, + resolve_default_init_integration, + ) + monkeypatch.delenv(DEFAULT_INIT_INTEGRATION_ENV_VAR, raising=False) + assert resolve_default_init_integration() == DEFAULT_INIT_INTEGRATION + + +def test_resolve_default_init_integration_valid_override(monkeypatch): + from specify_cli._agent_config import ( + DEFAULT_INIT_INTEGRATION_ENV_VAR, + resolve_default_init_integration, + ) + monkeypatch.setenv(DEFAULT_INIT_INTEGRATION_ENV_VAR, "gemini") + assert resolve_default_init_integration() == "gemini" + + +def test_resolve_default_init_integration_whitespace_trimmed(monkeypatch): + from specify_cli._agent_config import ( + DEFAULT_INIT_INTEGRATION_ENV_VAR, + resolve_default_init_integration, + ) + monkeypatch.setenv(DEFAULT_INIT_INTEGRATION_ENV_VAR, " gemini ") + assert resolve_default_init_integration() == "gemini" + + +def test_resolve_default_init_integration_invalid_warns_and_falls_back( + monkeypatch, capsys +): + from specify_cli._agent_config import ( + DEFAULT_INIT_INTEGRATION, + DEFAULT_INIT_INTEGRATION_ENV_VAR, + resolve_default_init_integration, + ) + monkeypatch.setenv(DEFAULT_INIT_INTEGRATION_ENV_VAR, "not-a-real-agent") + assert resolve_default_init_integration() == DEFAULT_INIT_INTEGRATION + captured = capsys.readouterr() + assert "not-a-real-agent" in captured.err + assert DEFAULT_INIT_INTEGRATION_ENV_VAR in captured.err + + +def test_resolve_default_init_integration_re_exported_from_init(): + from specify_cli import resolve_default_init_integration + assert callable(resolve_default_init_integration) diff --git a/tests/test_extension_skills.py b/tests/test_extension_skills.py index 95d252aebb..0c8335c7a1 100644 --- a/tests/test_extension_skills.py +++ b/tests/test_extension_skills.py @@ -2060,7 +2060,7 @@ def test_rescaffold_toggle_skills_to_command_removes_stale_extension_skill_file( assert skill_file.exists(), "sanity: skills mode should write SKILL.md" # Toggle ai_skills off for the same active agent (copilot) and - # rescaffold, mirroring `integration upgrade copilot` (no --skills). + # rescaffold, mirroring `integration upgrade copilot --commands`. _create_init_options(project_dir, ai="copilot", ai_skills=False) manager.register_enabled_extensions_for_agent("copilot") @@ -2134,7 +2134,7 @@ def test_toggle_to_command_preserves_tracking_for_mirror_in_other_agent_dir( ) # Toggle copilot to command mode (mirroring `integration upgrade - # copilot` with no --skills) — copilot's mirror is now stale. + # copilot --commands`) — copilot's mirror is now stale. _create_init_options(project_dir, ai="copilot", ai_skills=False) manager.register_enabled_extensions_for_agent("copilot") diff --git a/tests/test_extensions.py b/tests/test_extensions.py index 9d76c468be..9d0c3d0f3d 100644 --- a/tests/test_extensions.py +++ b/tests/test_extensions.py @@ -410,6 +410,55 @@ def test_invalid_version(self, temp_dir, valid_manifest_data): with pytest.raises(ValidationError, match="Invalid version"): ExtensionManifest(manifest_path) + @pytest.mark.parametrize( + "bad", + [ + 1.0, # unquoted YAML float -- the likeliest authoring slip + 5, # unquoted int + True, # YAML `yes`/`true` + None, # `speckit_version:` written but left empty + [">=0.1.0"], # iterable: slips past SpecifierSet() entirely + {"min": "0.1"}, # iterable: same + ], + ) + def test_non_string_speckit_version(self, temp_dir, valid_manifest_data, bad): + """A non-string requires.speckit_version must be a ValidationError. + + It was presence-checked only, so it reached ``SpecifierSet(required)`` in + check_compatibility(), which is guarded by ``except InvalidSpecifier`` + alone. A non-string escapes that guard two ways: scalars raise TypeError + from the constructor, and a list/dict is iterable so SpecifierSet accepts + it and the failure surfaces later as ``AttributeError: 'str' object has no + attribute 'filter'`` from inside .contains(). + """ + import yaml + + valid_manifest_data["requires"]["speckit_version"] = bad + + manifest_path = temp_dir / "extension.yml" + with open(manifest_path, 'w') as f: + yaml.dump(valid_manifest_data, f) + + with pytest.raises( + ValidationError, match="Invalid requires.speckit_version" + ): + ExtensionManifest(manifest_path) + + def test_empty_speckit_version(self, temp_dir, valid_manifest_data): + """A blank requires.speckit_version must be rejected, not treated as any.""" + import yaml + + valid_manifest_data["requires"]["speckit_version"] = " " + + manifest_path = temp_dir / "extension.yml" + with open(manifest_path, 'w') as f: + yaml.dump(valid_manifest_data, f) + + with pytest.raises( + ValidationError, match="Invalid requires.speckit_version" + ): + ExtensionManifest(manifest_path) + def test_valid_category(self, temp_dir, valid_manifest_data): """Test manifest with various category values (free-form string).""" import yaml @@ -671,6 +720,102 @@ def test_required_section_not_mapping_rejected( with pytest.raises(ValidationError, match=f"Invalid {section}"): ExtensionManifest(manifest_path) + @pytest.mark.parametrize("field", ["id", "name", "version", "description"]) + @pytest.mark.parametrize("bad", [1.0, 5, None, ["a"], {"a": 1}, True]) + def test_extension_metadata_field_not_string_rejected( + self, temp_dir, valid_manifest_data, field, bad + ): + """A non-string extension. must raise ValidationError, not a raw + TypeError. + + The loop over these four fields only checked key PRESENCE, then fed the + values to ``re.match`` (id) and ``packaging.Version`` (version), both of + which raise a bare TypeError on a non-string. YAML makes that an easy + authoring slip: unquoted ``version: 1.0`` parses as a float and ``id: 2`` + as an int. TypeError is not a ValidationError, so it escaped + list_installed()'s "Corrupted extension" fallback and made + `specify extension list` exit 1 with a raw traceback, hiding every + healthy extension too. The sibling IntegrationDescriptor already + type-checks the same four fields. + """ + import yaml + + valid_manifest_data["extension"][field] = bad + + manifest_path = temp_dir / "extension.yml" + with open(manifest_path, 'w') as f: + yaml.dump(valid_manifest_data, f) + + with pytest.raises(ValidationError, match=f"Invalid extension.{field}"): + ExtensionManifest(manifest_path) + + @pytest.mark.parametrize("bad", [1.0, 5, None, ["a"], {"a": 1}, True]) + def test_command_name_not_string_rejected( + self, temp_dir, valid_manifest_data, bad + ): + """A non-string command name must raise ValidationError, not a raw + TypeError from the name-pattern match. + + The sibling ``file`` field was already covered, since + relative_extension_path_violation() rejects a non-string value; ``name`` + went straight into EXTENSION_COMMAND_NAME_PATTERN.match(). + """ + import yaml + + valid_manifest_data["provides"]["commands"][0]["name"] = bad + + manifest_path = temp_dir / "extension.yml" + with open(manifest_path, 'w') as f: + yaml.dump(valid_manifest_data, f) + + with pytest.raises(ValidationError, match="Invalid command name"): + ExtensionManifest(manifest_path) + + def test_one_bad_manifest_does_not_hide_healthy_extensions(self, temp_dir): + """End-to-end guard for the symptom: an unquoted ``version: 1.0`` in one + installed extension must degrade to "Corrupted extension" and still let + list_installed() report the healthy ones, instead of raising TypeError + out of the whole call. + """ + ext_root = temp_dir / ".specify" / "extensions" + for ext_id, version in (("good-ext", '"1.0.0"'), ("bad-ext", "1.0")): + ext_path = ext_root / ext_id + ext_path.mkdir(parents=True, exist_ok=True) + (ext_path / "extension.yml").write_text( + f"""schema_version: "1.0" +extension: + id: {ext_id} + name: {ext_id} + version: {version} + description: desc +requires: + speckit_version: ">=0.1.0" +provides: + commands: + - name: speckit.{ext_id}.hello + file: commands/hello.md +""", + encoding="utf-8", + ) + (ext_root / ".registry").write_text( + json.dumps( + { + "schema_version": "1.0", + "extensions": { + "good-ext": {"version": "1.0.0", "enabled": True}, + "bad-ext": {"version": "1.0", "enabled": True}, + }, + } + ), + encoding="utf-8", + ) + + listed = {row["id"]: row for row in ExtensionManager(temp_dir).list_installed()} + + assert set(listed) == {"good-ext", "bad-ext"} + assert "Corrupted" not in listed["good-ext"]["description"] + assert "Corrupted" in listed["bad-ext"]["description"] + def test_empty_provides_mapping_is_still_accepted_with_hooks( self, temp_dir, valid_manifest_data ): @@ -1169,6 +1314,28 @@ def test_check_compatibility_invalid(self, extension_dir, project_dir): with pytest.raises(CompatibilityError, match="Extension requires spec-kit"): manager.check_compatibility(manifest, "0.0.1") + @pytest.mark.parametrize( + "bad", + [1.0, 5, True, None, [">=0.1.0"], {"min": "0.1"}], + ) + def test_check_compatibility_non_string_specifier(self, project_dir, bad): + """check_compatibility() must report a non-string as CompatibilityError. + + Defense in depth for the validator check above: this method is public and + reachable with a hand-built manifest, and ``except InvalidSpecifier`` does + not cover a non-string. Without the guard, scalars raise a bare TypeError + and iterables construct fine only to break inside .contains() -- neither + is a CompatibilityError, so both bypass the CLI's "Compatibility Error" + handler and exit 1 with a raw traceback naming no field. + """ + from types import SimpleNamespace + + manager = ExtensionManager(project_dir) + manifest = SimpleNamespace(requires_speckit_version=bad) + + with pytest.raises(CompatibilityError, match="Invalid version specifier"): + manager.check_compatibility(manifest, "0.15.2") + def test_check_compatibility_allows_prerelease_builds(self, extension_dir, project_dir): """Prerelease spec-kit builds should satisfy compatible version ranges.""" manager = ExtensionManager(project_dir) @@ -1505,6 +1672,57 @@ def test_reinstall_with_symlinked_config_rejects_install( assert external_target.read_text() == "model: linked-model\n" assert not manager.registry.is_installed("test-ext") + def test_reinstall_with_unreadable_kept_config_aborts_with_guidance( + self, extension_dir, project_dir, monkeypatch + ): + """An unreadable kept config must abort reinstall, not crash it. + + The sibling symlink guard four lines above raises ``ValidationError`` + with resolution guidance, but the rescue read itself + (``cfg_file.read_bytes()``/``stat()``) had no boundary, so a kept + config that cannot be read (permission or I/O error) crashed the + reinstall with a raw ``OSError``. It must reject the reinstall while + dest_dir is untouched so the preserved bytes are never rescued + half-read or lost to the rmtree below. + """ + manager = ExtensionManager(project_dir) + packaged_config = extension_dir / "test-ext-config.yml" + packaged_config.write_text("model: default-model\n") + manager.install_from_directory( + extension_dir, "0.1.0", register_commands=False + ) + + ext_dir = project_dir / ".specify" / "extensions" / "test-ext" + config_file = ext_dir / "test-ext-config.yml" + config_file.write_text("model: custom-model\nmax_iterations: 99\n") + kept_bytes = config_file.read_bytes() + + manager.remove("test-ext", keep_config=True) + assert not manager.registry.is_installed("test-ext") + assert config_file.is_file() + + # Simulate a kept config that can no longer be read (e.g. a + # permission or I/O error) without touching real permissions so the + # test also runs on platforms where chmod is a no-op. + original_read_bytes = Path.read_bytes + + def failing_read_bytes(self_path, *args, **kwargs): + if self_path == config_file: + raise PermissionError(13, "Permission denied") + return original_read_bytes(self_path, *args, **kwargs) + + monkeypatch.setattr(Path, "read_bytes", failing_read_bytes) + + with pytest.raises(ValidationError, match="cannot be read"): + manager.install_from_directory( + extension_dir, "0.1.0", register_commands=False + ) + + # The kept config survives untouched; nothing was rescued half-read. + monkeypatch.undo() + assert config_file.read_bytes() == kept_bytes + assert not manager.registry.is_installed("test-ext") + def test_retry_with_symlinked_live_config_aborts_and_preserves_both( self, extension_dir, project_dir, monkeypatch ): @@ -1995,6 +2213,87 @@ def flaky_copytree(*args, **kwargs): assert (staging_dir / "test-ext-config.yml").read_bytes() == staged_bytes assert not manager.registry.is_installed("test-ext") + def test_retry_with_unreadable_staged_config_aborts_and_preserves_both( + self, extension_dir, project_dir, monkeypatch + ): + """An unreadable staged backup must abort the retry, not crash it. + + Every sibling read in the retry path (the live twin, the packaged + baseline check, the mode sidecar) already catches ``OSError``, but the + staged file's own ``stat()``/``read_bytes()`` had no boundary, so a + staged config that cannot be read crashed the reinstall with a raw + ``OSError`` instead of the conflict guidance. It must be treated like + an uncomparable live config: preserve both copies and abort while + dest_dir is untouched. + """ + manager = ExtensionManager(project_dir) + + packaged_config = extension_dir / "test-ext-config.yml" + packaged_config.write_text("model: default-model\n") + + manager.install_from_directory( + extension_dir, "0.1.0", register_commands=False + ) + + ext_dir = project_dir / ".specify" / "extensions" / "test-ext" + config_file = ext_dir / "test-ext-config.yml" + config_file.write_text("model: custom-model\nmax_iterations: 99\n") + live_bytes = config_file.read_bytes() + + manager.remove("test-ext", keep_config=True) + assert not manager.registry.is_installed("test-ext") + + staging_dir = manager._rescue_staging_dir("test-ext") + + original_copytree = shutil.copytree + copytree_calls = 0 + + def flaky_copytree(*args, **kwargs): + nonlocal copytree_calls + copytree_calls += 1 + if copytree_calls == 1: + dst = args[1] + Path(dst).mkdir(parents=True, exist_ok=True) + (Path(dst) / "_partial.txt").write_text("partial") + raise OSError("simulated disk full") + return original_copytree(*args, **kwargs) + + monkeypatch.setattr(_ext_module.shutil, "copytree", flaky_copytree) + + with pytest.raises(OSError, match="simulated disk full"): + manager.install_from_directory( + extension_dir, "0.1.0", register_commands=False + ) + + assert staging_dir.exists() + assert (staging_dir / ".rescue-complete").exists() + staged_file = staging_dir / "test-ext-config.yml" + assert staged_file.is_file() + + # Simulate a staged backup that can no longer be read (e.g. a + # permission or I/O error) without touching real permissions so the + # test also runs on platforms where chmod is a no-op. + original_read_bytes = Path.read_bytes + + def failing_read_bytes(self_path, *args, **kwargs): + if self_path == staged_file: + raise PermissionError(13, "Permission denied") + return original_read_bytes(self_path, *args, **kwargs) + + monkeypatch.setattr(Path, "read_bytes", failing_read_bytes) + + with pytest.raises(ValidationError, match="Preserved extension config conflict"): + manager.install_from_directory( + extension_dir, "0.1.0", register_commands=False + ) + + # Both copies must survive: the live config and the staged backup. + monkeypatch.undo() + assert config_file.read_bytes() == live_bytes + assert staging_dir.exists() + assert staged_file.is_file() + assert not manager.registry.is_installed("test-ext") + @pytest.mark.parametrize( "failure_mode", [ @@ -10504,3 +10803,310 @@ def test_forge_extension_info_hyphenates_command_names( # not the manifest's dotted name. assert "speckit-test-ext-hello" in output, output assert "speckit.test-ext.hello" not in output, output + +# ===== Extension Config Scaffolding Tests ===== + + +class TestExtensionConfigScaffolding: + """Test automatic config scaffolding during add/enable lifecycle.""" + + def _make_extension(self, ext_dir, config_entries=None): + """Create a minimal extension with optional config templates.""" + ext_dir.mkdir(parents=True, exist_ok=True) + manifest = { + "schema_version": "1.0", + "extension": { + "id": "test-ext", + "name": "Test Extension", + "version": "1.0.0", + "description": "Test extension", + "author": "Test", + "repository": "https://github.com/test/test", + "license": "MIT", + "homepage": "https://github.com/test/test", + }, + "requires": {"speckit_version": ">=0.1.0"}, + "provides": { + "commands": [{ + "name": "speckit.test-ext.example", + "file": "commands/example.md", + "description": "Example command", + }], + }, + "tags": ["test"], + } + if config_entries: + manifest["provides"]["config"] = config_entries + import yaml + (ext_dir / "extension.yml").write_text(yaml.dump(manifest, default_flow_style=False)) + # Create command file so validation passes + (ext_dir / "commands").mkdir(exist_ok=True) + (ext_dir / "commands" / "example.md").write_text("# Example") + return manifest + + def test_scaffold_config_deploys_template(self, tmp_path): + """Config template lands where ConfigManager reads it, not in .specify/ root.""" + from specify_cli.extensions import ExtensionManager + project = tmp_path / "project" + specify_dir = project / ".specify" + specify_dir.mkdir(parents=True) + ext_dir = specify_dir / "extensions" / "test-ext" + self._make_extension(ext_dir, config_entries=[{ + "name": "test-config.yml", + "template": "config-template.yml", + "description": "Test config", + "required": True, + }]) + (ext_dir / "config-template.yml").write_text("setting: default") + + manager = ExtensionManager(project) + deployed, skipped, failed = manager.scaffold_config("test-ext") + + assert deployed == ["test-config.yml"] + assert skipped == [] + assert failed == [] + # ConfigManager._get_project_config() reads + # .specify/extensions//, so that is where scaffolding must + # put it. Deploying to the .specify/ root left the file somewhere the + # extension never looks. + assert (ext_dir / "test-config.yml").exists() + assert (ext_dir / "test-config.yml").read_text() == "setting: default" + assert not (specify_dir / "test-config.yml").exists() + + def test_scaffold_config_preserves_existing(self, tmp_path): + """Existing config files should never be overwritten.""" + from specify_cli.extensions import ExtensionManager + project = tmp_path / "project" + specify_dir = project / ".specify" + specify_dir.mkdir(parents=True) + ext_dir = specify_dir / "extensions" / "test-ext" + self._make_extension(ext_dir, config_entries=[{ + "name": "test-config.yml", + "template": "config-template.yml", + "description": "Test config", + "required": True, + }]) + (ext_dir / "config-template.yml").write_text("setting: default") + (ext_dir / "test-config.yml").write_text("setting: custom") + + manager = ExtensionManager(project) + deployed, skipped, failed = manager.scaffold_config("test-ext") + + assert deployed == [] + assert skipped == ["test-config.yml"] + assert failed == [] + assert (ext_dir / "test-config.yml").read_text() == "setting: custom" + + def test_scaffold_config_no_config_section(self, tmp_path): + """Extensions without config section should return empty list.""" + from specify_cli.extensions import ExtensionManager + project = tmp_path / "project" + specify_dir = project / ".specify" + specify_dir.mkdir(parents=True) + ext_dir = specify_dir / "extensions" / "test-ext" + self._make_extension(ext_dir) + + manager = ExtensionManager(project) + deployed, skipped, failed = manager.scaffold_config("test-ext") + + assert deployed == [] + assert skipped == [] + assert failed == [] + + def test_scaffold_config_missing_template_file(self, tmp_path): + """Missing template files should be reported as failed.""" + from specify_cli.extensions import ExtensionManager + project = tmp_path / "project" + specify_dir = project / ".specify" + specify_dir.mkdir(parents=True) + ext_dir = specify_dir / "extensions" / "test-ext" + self._make_extension(ext_dir, config_entries=[{ + "name": "test-config.yml", + "template": "nonexistent.yml", + "description": "Test config", + }]) + + manager = ExtensionManager(project) + deployed, skipped, failed = manager.scaffold_config("test-ext") + + assert deployed == [] + assert skipped == [] + assert failed == ["test-config.yml"] + + def test_scaffold_config_rejects_path_traversal(self, tmp_path): + """Config names with path traversal should be rejected.""" + from specify_cli.extensions import ExtensionManager + project = tmp_path / "project" + specify_dir = project / ".specify" + specify_dir.mkdir(parents=True) + ext_dir = specify_dir / "extensions" / "test-ext" + self._make_extension(ext_dir, config_entries=[ + {"name": "../etc/passwd", "template": "config.yml"}, + {"name": "safe.yml", "template": "../../secrets.yml"}, + {"name": "/absolute/path.yml", "template": "config.yml"}, + ]) + (ext_dir / "config.yml").write_text("safe: true") + + manager = ExtensionManager(project) + deployed, skipped, failed = manager.scaffold_config("test-ext") + + assert deployed == [] + assert skipped == [] + assert failed == ["../etc/passwd", "safe.yml", "/absolute/path.yml"] + + def test_scaffold_config_rejects_directory_template(self, tmp_path): + """Directory templates should be rejected (must be regular files).""" + from specify_cli.extensions import ExtensionManager + project = tmp_path / "project" + specify_dir = project / ".specify" + specify_dir.mkdir(parents=True) + ext_dir = specify_dir / "extensions" / "test-ext" + self._make_extension(ext_dir, config_entries=[{ + "name": "test-config.yml", + "template": "config-dir", + }]) + (ext_dir / "config-dir").mkdir() + + manager = ExtensionManager(project) + deployed, skipped, failed = manager.scaffold_config("test-ext") + + assert deployed == [] + assert skipped == [] + assert failed == ["test-config.yml"] + + def test_scaffold_config_rejects_symlink_template(self, tmp_path): + """Symlink templates should not be copied.""" + from specify_cli.extensions import ExtensionManager + project = tmp_path / "project" + specify_dir = project / ".specify" + specify_dir.mkdir(parents=True) + ext_dir = specify_dir / "extensions" / "test-ext" + self._make_extension(ext_dir, config_entries=[{ + "name": "test-config.yml", + "template": "config-link.yml", + }]) + real_template = ext_dir / "config-template.yml" + real_template.write_text("setting: default") + (ext_dir / "config-link.yml").symlink_to(real_template) + + manager = ExtensionManager(project) + deployed, skipped, failed = manager.scaffold_config("test-ext") + + assert deployed == [] + assert skipped == [] + assert failed == ["test-config.yml"] + assert not (specify_dir / "test-config.yml").exists() + + def test_scaffold_config_malformed_manifest(self, tmp_path): + """Malformed config sections should not crash.""" + from specify_cli.extensions import ExtensionManager, ExtensionManifest + import yaml + project = tmp_path / "project" + specify_dir = project / ".specify" + specify_dir.mkdir(parents=True) + ext_dir = specify_dir / "extensions" / "test-ext" + manifest_data = self._make_extension(ext_dir) + manifest_data["provides"]["config"] = "not-a-list" + (ext_dir / "extension.yml").write_text(yaml.dump(manifest_data)) + + manifest = ExtensionManifest(ext_dir / "extension.yml") + assert manifest.config == [] + + manager = ExtensionManager(project) + deployed, skipped, failed = manager.scaffold_config("test-ext") + + assert deployed == [] + assert skipped == [] + assert failed == ["provides.config"] + + def test_scaffold_config_missing_manifest_returns_consistent_result(self, tmp_path): + """A missing extension manifest should return the documented tuple.""" + from specify_cli.extensions import ExtensionManager + project = tmp_path / "project" + (project / ".specify").mkdir(parents=True) + + manager = ExtensionManager(project) + + assert manager.scaffold_config("missing") == ([], [], []) + + def test_scaffold_config_rejects_symlinked_config_root(self, tmp_path): + """A symlinked .specify must not become the containment root. + + Resolving .specify first and trusting the result lets a symlink point + anywhere: every target then satisfies relative_to and copy2 writes + outside the project. + """ + from specify_cli.extensions import ExtensionManager + project = tmp_path / "project" + project.mkdir() + outside = tmp_path / "outside" + outside.mkdir() + (project / ".specify").symlink_to(outside, target_is_directory=True) + + ext_dir = outside / "extensions" / "test-ext" + self._make_extension(ext_dir, config_entries=[{ + "name": "test-config.yml", + "template": "config-template.yml", + "description": "Test config", + "required": True, + }]) + (ext_dir / "config-template.yml").write_text("setting: default") + + manager = ExtensionManager(project) + deployed, skipped, failed = manager.scaffold_config("test-ext") + + assert deployed == [] + assert skipped == [] + assert failed == ["provides.config"] + assert not (outside / "extensions" / "test-ext" / "test-config.yml").exists() + + def test_scaffold_config_rejects_targets_removal_would_not_preserve(self, tmp_path): + """Only top-level *-config.yml targets are scaffolded. + + remove(keep_config=True) rmtree's every subdirectory and keeps only + top-level -config.yml / -config.local.yml files, and the backup path + globs the same pattern. Scaffolding anything else would hand the user a + file that `extension add --force` silently replaces with the template + default. + """ + from specify_cli.extensions import ExtensionManager + for target in ("nested/test-config.yml", "settings.yml", "test-config.yaml"): + project = tmp_path / f"project-{target.replace('/', '_')}" + specify_dir = project / ".specify" + specify_dir.mkdir(parents=True) + ext_dir = specify_dir / "extensions" / "test-ext" + self._make_extension(ext_dir, config_entries=[{ + "name": target, + "template": "config-template.yml", + "description": "Test config", + "required": True, + }]) + (ext_dir / "config-template.yml").write_text("setting: default") + + manager = ExtensionManager(project) + deployed, skipped, failed = manager.scaffold_config("test-ext") + + assert deployed == [], target + assert skipped == [], target + assert failed == [target], target + + def test_scaffold_config_accepts_local_override_name(self, tmp_path): + """*-config.local.yml is preserved by removal, so it may be scaffolded.""" + from specify_cli.extensions import ExtensionManager + project = tmp_path / "project" + specify_dir = project / ".specify" + specify_dir.mkdir(parents=True) + ext_dir = specify_dir / "extensions" / "test-ext" + self._make_extension(ext_dir, config_entries=[{ + "name": "test-config.local.yml", + "template": "config-template.yml", + "description": "Test config", + "required": True, + }]) + (ext_dir / "config-template.yml").write_text("setting: default") + + manager = ExtensionManager(project) + deployed, skipped, failed = manager.scaffold_config("test-ext") + + assert deployed == ["test-config.local.yml"] + assert failed == [] diff --git a/tests/test_post_process.py b/tests/test_post_process.py index 12003f6a07..a99fc6965b 100644 --- a/tests/test_post_process.py +++ b/tests/test_post_process.py @@ -274,3 +274,29 @@ def test_cline_transforms_applied_via_registrar( # _rewrite_handoff_references rewrote the dotted agent handoff assert "agent: speckit-foo" in content assert "agent: speckit.foo" not in content + + +def test_register_commands_propagates_programming_errors(tmp_path): + """Regression: narrowed exception must not swallow TypeError/AttributeError. + + The invoke separator resolution narrowed from bare 'except Exception' to + 'except (ImportError, ValueError, KeyError)'. Programming errors like + TypeError must propagate instead of being silently swallowed. + """ + registrar = CommandRegistrar() + commands = [{"name": "test.cmd", "file": "commands/test.md"}] + + ext_dir = tmp_path / "ext" + ext_dir.mkdir() + + def _broken_get_integration(name): + raise TypeError("intentional programming error") + + import specify_cli.integrations as integ_mod + original = integ_mod.get_integration + integ_mod.get_integration = _broken_get_integration + try: + with pytest.raises(TypeError, match="intentional programming error"): + registrar.register_commands("bob", commands, "ext", ext_dir, tmp_path) + finally: + integ_mod.get_integration = original diff --git a/tests/test_presets.py b/tests/test_presets.py index 06a0f5da40..adc8beaf3c 100644 --- a/tests/test_presets.py +++ b/tests/test_presets.py @@ -217,6 +217,102 @@ def test_required_section_not_mapping_raises_validation_error( ): PresetManifest(manifest_path) + @pytest.mark.parametrize("field", ["id", "name", "version", "description"]) + @pytest.mark.parametrize("bad", [1.0, 5, None, ["a"], {"a": 1}, True]) + def test_preset_metadata_field_not_string_raises_validation_error( + self, temp_dir, valid_pack_data, field, bad + ): + """A non-string preset. raises PresetValidationError, not a raw + TypeError. + + The loop over these four fields only checked key PRESENCE, then fed the + values to ``re.match`` (id) and ``packaging.Version`` (version), both of + which raise a bare TypeError on a non-string. YAML makes that an easy + authoring slip: unquoted ``version: 1.0`` parses as a float and ``id: 2`` + as an int. TypeError is not a PresetValidationError, so it escaped + list_installed()'s "Corrupted preset" fallback and made + `specify preset list` exit 1 with a raw traceback, hiding every healthy + preset too. The sibling IntegrationDescriptor already type-checks the + same four fields. + """ + valid_pack_data["preset"][field] = bad + manifest_path = temp_dir / "preset.yml" + manifest_path.write_text(yaml.safe_dump(valid_pack_data), encoding="utf-8") + + with pytest.raises( + PresetValidationError, + match=rf"Invalid preset\.{field}: expected a string", + ): + PresetManifest(manifest_path) + + @pytest.mark.parametrize("field", ["name", "file"]) + @pytest.mark.parametrize("bad", [1.0, 5, None, ["a"], {"a": 1}, True]) + def test_template_entry_field_not_string_raises_validation_error( + self, temp_dir, valid_pack_data, field, bad + ): + """A non-string template ``name``/``file`` raises PresetValidationError. + + ``name`` reaches ``re.match`` and ``file`` reaches ``os.path.normpath``; + both raise a bare TypeError on a non-string. The sibling extension + manifest already rejects a non-string command ``file`` via + relative_extension_path_violation(). + """ + valid_pack_data["provides"]["templates"][0][field] = bad + manifest_path = temp_dir / "preset.yml" + manifest_path.write_text(yaml.safe_dump(valid_pack_data), encoding="utf-8") + + with pytest.raises( + PresetValidationError, + match=rf"Invalid template {field}: expected a string", + ): + PresetManifest(manifest_path) + + def test_one_bad_manifest_does_not_hide_healthy_presets(self, temp_dir): + """End-to-end guard for the symptom: an unquoted ``version: 1.0`` in one + installed preset must degrade to "Corrupted preset" and still let + list_installed() report the healthy ones, instead of raising TypeError + out of the whole call. + """ + preset_root = temp_dir / ".specify" / "presets" + for pack_id, version in (("good-pack", '"1.0.0"'), ("bad-pack", "1.0")): + pack_path = preset_root / pack_id + pack_path.mkdir(parents=True, exist_ok=True) + (pack_path / "preset.yml").write_text( + f"""schema_version: "1.0" +preset: + id: {pack_id} + name: {pack_id} + version: {version} + description: desc +requires: + speckit_version: ">=0.1.0" +provides: + templates: + - type: template + name: spec + file: templates/spec.md +""", + encoding="utf-8", + ) + (preset_root / ".registry").write_text( + json.dumps( + { + "schema_version": "1.0", + "presets": { + "good-pack": {"version": "1.0.0", "enabled": True}, + "bad-pack": {"version": "1.0", "enabled": True}, + }, + } + ), + encoding="utf-8", + ) + + listed = {row["id"]: row for row in PresetManager(temp_dir).list_installed()} + + assert set(listed) == {"good-pack", "bad-pack"} + assert "Corrupted" not in listed["good-pack"]["description"] + assert "Corrupted" in listed["bad-pack"]["description"] + @pytest.mark.parametrize( "bad", [ @@ -310,6 +406,37 @@ def test_missing_speckit_version(self, temp_dir, valid_pack_data): with pytest.raises(PresetValidationError, match="Missing requires.speckit_version"): PresetManifest(manifest_path) + @pytest.mark.parametrize( + "bad", + [ + 1.0, # unquoted YAML float -- the likeliest authoring slip + 5, # unquoted int + True, # YAML `yes`/`true` + None, # `speckit_version:` written but left empty + [">=0.1.0"], # iterable: slips past SpecifierSet() entirely + {"min": "0.1"}, # iterable: same + " ", # blank string must not mean "any version" + ], + ) + def test_non_string_speckit_version(self, temp_dir, valid_pack_data, bad): + """A non-string requires.speckit_version must be a PresetValidationError. + + It was presence-checked only, so it reached ``SpecifierSet(required)`` in + check_compatibility(), which is guarded by ``except InvalidSpecifier`` + alone. A non-string escapes that guard two ways: scalars raise TypeError + from the constructor, and a list/dict is iterable so SpecifierSet accepts + it and the failure surfaces later as ``AttributeError: 'str' object has no + attribute 'filter'`` from inside .contains(). + """ + valid_pack_data["requires"]["speckit_version"] = bad + manifest_path = temp_dir / "preset.yml" + with open(manifest_path, 'w') as f: + yaml.dump(valid_pack_data, f) + with pytest.raises( + PresetValidationError, match="Invalid requires.speckit_version" + ): + PresetManifest(manifest_path) + def test_no_templates_provided(self, temp_dir, valid_pack_data): """Test pack with no templates.""" valid_pack_data["provides"]["templates"] = [] @@ -388,6 +515,27 @@ def test_empty_registry(self, temp_dir): assert registry.list() == {} assert not registry.is_installed("test-pack") + def test_load_starts_fresh_for_non_utf8_registry(self, temp_dir): + """A registry file with undecodable bytes must start fresh, not raise. + + ``_load()`` already treats malformed JSON as "corrupted registry, + start fresh", but a registry whose *bytes* cannot be decoded as UTF-8 + raised a raw ``UnicodeDecodeError`` from the same boundary — the same + corruption class reaching a different exception type. + """ + packs_dir = temp_dir / "packs" + packs_dir.mkdir() + (packs_dir / PresetRegistry.REGISTRY_FILE).write_bytes( + b"\xff\xfe not utf-8 \xc3\x28" + ) + + registry = PresetRegistry(packs_dir) + + assert registry.data == { + "schema_version": PresetRegistry.SCHEMA_VERSION, + "presets": {}, + } + def test_add_and_get(self, temp_dir): """Test adding and retrieving a pack.""" packs_dir = temp_dir / "packs" @@ -868,6 +1016,26 @@ def test_check_compatibility_invalid(self, pack_dir, temp_dir): with pytest.raises(PresetCompatibilityError, match="Invalid version specifier"): manager.check_compatibility(manifest, "0.1.5") + @pytest.mark.parametrize( + "bad", + [1.0, 5, True, None, [">=0.1.0"], {"min": "0.1"}], + ) + def test_check_compatibility_non_string_specifier(self, pack_dir, temp_dir, bad): + """check_compatibility() must report a non-string as a compatibility error. + + Defense in depth for the validator check: this method is public and the + specifier is read back out of mutable manifest data, and ``except + InvalidSpecifier`` does not cover a non-string. Without the guard, scalars + raise a bare TypeError and iterables construct fine only to break inside + .contains() -- neither is a PresetCompatibilityError, so both bypass the + CLI's "Compatibility Error" handler and exit 1 with a raw traceback. + """ + manager = PresetManager(temp_dir) + manifest = PresetManifest(pack_dir / "preset.yml") + manifest.data["requires"]["speckit_version"] = bad + with pytest.raises(PresetCompatibilityError, match="Invalid version specifier"): + manager.check_compatibility(manifest, "0.1.5") + def test_install_with_priority(self, project_dir, pack_dir): """Test installing a pack with custom priority.""" manager = PresetManager(project_dir) @@ -4924,6 +5092,103 @@ def test_skill_restored_on_preset_remove(self, project_dir, temp_dir): assert "templates/commands/specify.md" in content, "Should reference core template" assert "disable-model-invocation: false" in content + def test_skill_restored_on_preset_remove_without_project_core_templates(self, project_dir): + """Removing a preset must restore core skills even when the project + has no ``.specify/templates/commands`` directory of its own — which + is the normal case, since ``specify init`` never populates it. The + real core commands live in the bundled core_pack/repo-root templates + tree, and restoration must fall back there instead of deleting the + skill outright (#3928). + """ + self._write_init_options(project_dir, ai="claude") + skills_dir = project_dir / ".claude" / "skills" + self._create_skill(skills_dir, "speckit-specify") + + # The project_dir fixture's commands dir is empty, matching a real + # project — specify init never populates project-local overrides + # for unmodified core commands. + core_cmds = project_dir / ".specify" / "templates" / "commands" + assert core_cmds.exists() and not any(core_cmds.iterdir()) + + manager = PresetManager(project_dir) + install_self_test_preset(manager) + + skill_file = skills_dir / "speckit-specify" / "SKILL.md" + assert "preset:self-test" in skill_file.read_text(encoding="utf-8") + + manager.remove("self-test") + + assert skill_file.exists(), "Core skill must be restored, not deleted" + content = skill_file.read_text(encoding="utf-8") + assert "preset:self-test" not in content + assert "templates/commands/specify.md" in content + assert "Create or update the feature specification" in content + + def test_extension_wins_over_bundled_core_on_preset_remove( + self, project_dir, monkeypatch + ): + """When an installed extension owns the same skill name as a core + command, removing a preset that overrode that skill must restore it + from the extension, not silently from the bundled core template. + Extensions are resolved ahead of bundled core elsewhere, and the + bundled-core fallback added for #3928 must not replace that + higher-priority layer. + + The extension-command namespace rules (``speckit..``) + make a genuine end-to-end name collision with a core command + cumbersome to construct through real manifests, so this stubs + ``_build_extension_skill_restore_index`` to exercise the priority + ordering in ``_unregister_skills_in_dir`` directly -- the code path + under test doesn't care how the index entry was produced, only that + it wins over the bundled-core fallback when present. + """ + self._write_init_options(project_dir, ai="claude") + skills_dir = project_dir / ".claude" / "skills" + self._create_skill(skills_dir, "speckit-specify") + + # No project-local core template override — the normal case, and + # the one that makes the bundled-core fallback kick in at all. + core_cmds = project_dir / ".specify" / "templates" / "commands" + assert core_cmds.exists() and not any(core_cmds.iterdir()) + + extension_dir = project_dir / ".specify" / "extensions" / "fakeext" + (extension_dir / "commands").mkdir(parents=True, exist_ok=True) + ext_specify_file = extension_dir / "commands" / "specify.md" + ext_specify_file.write_text( + "---\ndescription: Extension specify command\n---\n\n" + "extension:fakeext specify body\n" + ) + + manager = PresetManager(project_dir) + install_self_test_preset(manager) + + skill_file = skills_dir / "speckit-specify" / "SKILL.md" + assert "preset:self-test" in skill_file.read_text(encoding="utf-8") + + fake_restore_index = { + "speckit-specify": { + "command_name": "speckit.fakeext.specify", + "source_file": ext_specify_file, + "source": "extension:fakeext", + "extension_id": "fakeext", + "extension_dir": extension_dir, + } + } + monkeypatch.setattr( + manager, + "_build_extension_skill_restore_index", + lambda: fake_restore_index, + ) + + manager.remove("self-test") + + assert skill_file.exists() + content = skill_file.read_text(encoding="utf-8") + assert "preset:self-test" not in content + assert "source: extension:fakeext" in content + assert "extension:fakeext specify body" in content + assert "templates/commands/specify.md" not in content + def test_skill_restored_on_remove_resolves_script_placeholders(self, project_dir): """Core restore should resolve {SCRIPT}/{ARGS} placeholders like other skill paths.""" self._write_init_options(project_dir, ai="claude", ai_skills=True, script="sh") @@ -11661,6 +11926,24 @@ def test_resolve_content_rewrites_extension_base_subdir_paths( class TestCollectAllLayers: """Test PresetResolver.collect_all_layers() method.""" + def test_non_utf8_legacy_command_keeps_replace_strategy(self, project_dir): + presets_dir = project_dir / ".specify" / "presets" + command_path = ( + presets_dir / "legacy-pack" / "commands" / "speckit.legacy.md" + ) + command_path.parent.mkdir(parents=True) + command_path.write_bytes(b"\xff\xfe") + PresetRegistry(presets_dir).add( + "legacy-pack", {"version": "1.0.0", "priority": 10} + ) + + layers = PresetResolver(project_dir).collect_all_layers( + "speckit.legacy", "command" + ) + + assert layers[0]["path"] == command_path + assert layers[0]["strategy"] == "replace" + def test_single_core_layer(self, project_dir): """Test collecting layers with only core template.""" resolver = PresetResolver(project_dir) diff --git a/tests/test_workflows.py b/tests/test_workflows.py index 8810753171..1f33f825a8 100644 --- a/tests/test_workflows.py +++ b/tests/test_workflows.py @@ -2254,6 +2254,59 @@ def test_builds_here_argv_and_bootstraps(self, tmp_path): assert "--ignore-agent-tools" in argv assert (tmp_path / ".specify").is_dir() + def test_explicit_null_ignore_agent_tools_keeps_documented_default( + self, tmp_path + ): + """A bare ``ignore_agent_tools:`` must keep the documented default. + + The class docstring says "Because workflows run unattended, the step + defaults to ``--ignore-agent-tools``" and the field docs say "defaults to + ``true``". But ``config.get(key, True)`` applies the default only when the + key is ABSENT — a bare ``ignore_agent_tools:`` in YAML parses to None, + which ``_resolve_bool`` turned into False, dropping the flag and + re-enabling the agent-CLI presence check for an unattended run. + """ + from specify_cli.workflows.steps.init import InitStep + from specify_cli.workflows.base import StepContext, StepStatus + + step = InitStep() + ctx = StepContext( + project_root=str(tmp_path), default_integration="copilot" + ) + result = step.execute( + { + "id": "bootstrap", + "here": True, + "script": "sh", + "ignore_agent_tools": None, + }, + ctx, + ) + + assert result.status == StepStatus.COMPLETED + assert "--ignore-agent-tools" in result.output["argv"] + + def test_explicit_false_ignore_agent_tools_is_honoured(self, tmp_path): + """An explicit ``false`` must still opt in to the agent-CLI check.""" + from specify_cli.workflows.steps.init import InitStep + from specify_cli.workflows.base import StepContext + + step = InitStep() + ctx = StepContext( + project_root=str(tmp_path), default_integration="copilot" + ) + result = step.execute( + { + "id": "bootstrap", + "here": True, + "script": "sh", + "ignore_agent_tools": False, + }, + ctx, + ) + + assert "--ignore-agent-tools" not in result.output["argv"] + def test_default_integration_falls_back_to_workflow_default(self, tmp_path): from specify_cli.workflows.steps.init import InitStep from specify_cli.workflows.base import StepContext, StepStatus @@ -2268,6 +2321,24 @@ def test_default_integration_falls_back_to_workflow_default(self, tmp_path): assert result.status == StepStatus.COMPLETED assert result.output["integration"] == "copilot" + def test_default_integration_honors_env_var(self, tmp_path, monkeypatch): + # With no step-level and no workflow-level default, the resolved + # SPECKIT_INTEGRATION_DEFAULT value must drive both output.integration + # and the argv passed to init (guards against reverting to the constant). + from specify_cli.workflows.steps.init import InitStep + from specify_cli.workflows.base import StepContext, StepStatus + + monkeypatch.setenv("SPECKIT_INTEGRATION_DEFAULT", "gemini") + step = InitStep() + ctx = StepContext(project_root=str(tmp_path)) + result = step.execute( + {"id": "bootstrap", "here": True, "script": "sh"}, ctx + ) + assert result.status == StepStatus.COMPLETED + assert result.output["integration"] == "gemini" + argv = result.output["argv"] + assert "--integration" in argv and "gemini" in argv + def test_project_name_creates_subdirectory(self, tmp_path): from specify_cli.workflows.steps.init import InitStep from specify_cli.workflows.base import StepContext, StepStatus @@ -7060,6 +7131,35 @@ def test_load_not_found(self, project_dir): with pytest.raises(FileNotFoundError): RunState.load("nonexistent", project_dir) + def test_load_rejects_stored_run_id_mismatch(self, project_dir): + """The state payload cannot redirect later writes to another run.""" + from specify_cli.workflows.engine import RunState + + run_dir = ( + project_dir + / ".specify" + / "workflows" + / "runs" + / "requested-run" + ) + run_dir.mkdir(parents=True) + (run_dir / "state.json").write_text( + json.dumps( + { + "run_id": "other-run", + "workflow_id": "test-workflow", + "status": "created", + } + ), + encoding="utf-8", + ) + + with pytest.raises( + ValueError, + match="stored run_id 'other-run' does not match requested run_id 'requested-run'", + ): + RunState.load("requested-run", project_dir) + @pytest.mark.parametrize( ("installed_workflow_id", "installed_registry_root"), [