Metadata-Version: 2.5
Name: specnest
Version: 1.2.0
Summary: Reusable spec-driven workflow CLI
Author: A42SS
License-Expression: MIT
License-File: LICENSE
Requires-Python: >=3.11
Requires-Dist: argcomplete>=3.8.0
Requires-Dist: pyyaml>=6.0.4
Description-Content-Type: text/markdown

# SpecNest

SpecNest is a CLI for validating and coordinating spec-driven development. It
stores plans, tasks, and architecture decision records (ADRs) as Markdown with
YAML metadata. Humans review and approve the specifications; implementers use
the CLI to find and update ready tasks.

The CLI uses a small, fixed documentation layout in the consuming project.
Initialization provides starter agent profiles for a choice of AI harnesses,
which you can adapt to your project; SpecNest does not execute agents or
install automation.

## Installation

SpecNest requires Python 3.11 or newer. From a checkout of this repository,
install it into your Python environment:

```sh
python -m pip install .
specnest --version
```

PyYAML is installed as a dependency. `python -m specnest` is equivalent to
`specnest` if the environment's scripts directory is not on your PATH.

### Optional short alias

To type `sn` instead of `specnest`, run:

```sh
specnest shortcut          # creates sn next to the specnest executable
specnest shortcut spn      # or choose a different name
specnest shortcut --remove # removes sn (only if SpecNest created it)
```

SpecNest creates the shortcut only if the name is free. It refuses if the name
is already used by a file in the target directory, an executable on `PATH`,
or a zsh or bash alias, function, builtin, or reserved word. The shortcut is a
relative symlink to `specnest`, so it continues to work after upgrades. It is
opt-in because Python packages cannot safely check for name collisions during
installation.

## Shell completion

The installed `specnest` command supports explicit shell completion through
`argcomplete`. Keep `specnest` and `register-python-argcomplete` on `PATH` from
the same active Python environment; for example, activate the virtual
environment where SpecNest is installed before registering completion. These
commands only activate completion in the current shell session:

### Bash

```bash
eval "$(register-python-argcomplete --shell bash specnest --complete-arguments -o nospace)"
```

### Zsh

If Zsh's completion system is not already initialized in the session, run
`compinit` first:

```zsh
autoload -Uz compinit
compinit
eval "$(register-python-argcomplete --shell zsh specnest)"
```

### Fish

```fish
register-python-argcomplete --shell fish specnest | source
```

### PowerShell 7

```powershell
register-python-argcomplete --shell powershell specnest | Out-String | Invoke-Expression
```

For example, after activation, press Tab at the end of each partial command:

| Shell | Command | SpecNest candidates |
| --- | --- | --- |
| Bash | `specnest n` | `new`, `next` |
| Zsh | `specnest task PLAN-0001-T01 --status bl` | `blocked` |
| Fish | `specnest init --harness co` | `codex`, `copilot` |
| PowerShell | `specnest new "A title" --o` | `--owner` |

The completion is static: it uses the parser's commands, options, and fixed
choices for `new` (`plan`, `adr`), `task --status`, and `init --harness`. It
does not look up plans, ADRs, tasks, owners, or approvers, and it does not
suggest free-form values or filesystem paths. You can also complete fixed
choices after a quoted root path, for example:

```sh
specnest --root "/path/with spaces/project" init --harness co
```

SpecNest suppresses its default file completer. The Bash registration above
also replaces Bash's default filename fallback for this command. Other shells
and user-installed shell plugins may provide their own fallback suggestions;
those are separate from SpecNest's candidates.

To keep completion enabled in new sessions, you may manually add the relevant
activation command to your shell's startup file (for example, `~/.bashrc`,
`~/.zshrc`, Fish's `~/.config/fish/config.fish`, or your PowerShell profile).
SpecNest never edits these files or enables global completion. To disable a
persistent registration, remove the line you added and start a fresh shell.

The completion workflow tests Python 3.11 with Bash, Zsh, and Fish on Linux
and PowerShell 7 on Windows. It prints the shell versions tested in each run.
Other shell versions and operating-system combinations are unverified. The
registrations target the `specnest` executable; if you installed the optional
`sn` shortcut, you may explicitly include `sn` as another executable in the
upstream `register-python-argcomplete` command.

## Quick start

The following example is for a new or empty consuming project. If your project
already has these files, integrate the examples rather than overwriting them.
Run the commands from that project's root.

1. Initialize the project, replacing `alice` with a human approver's GitHub
   handle:

   ```sh
   specnest init --approver alice
   ```

   You can omit `--approver` to enter the handle interactively. It is required
   for a new configuration when input is not interactive. The command creates
   `docs/specs.config.yaml`, starter plan and ADR templates, and `planner`,
   `implementer`, and `reviewer` agent profiles.

   Select your agent harness with `--harness`; the default is `copilot`. For
   example, to use Claude Code instead:

   ```sh
   specnest init --approver alice --harness claude
   ```

   | Harness | Project agent files |
   | --- | --- |
   | `copilot` | `.github/agents/*.agent.md` |
   | `claude` (Claude Code) | `.claude/agents/*.md` |
   | `codex` | `.codex/agents/*.toml` |
   | `gemini` (Gemini CLI) | `.gemini/agents/*.md` |
   | `cursor` | `.cursor/agents/*.md` |

   Specify `--harness` each time if not using Copilot. You can repeat `init`
   with another harness to add its profiles. Existing files are never
   overwritten, including older starter profiles; update those manually if
   desired. For harnesses that use profile metadata for identity, profiles with
   the same agent name are reused even under a different filename. If a default
   filename contains a different or invalid agent, rename or fix it before
   retrying. If a configuration already exists, an explicitly supplied approver
   must already be listed there. Initialization rejects symlinked directories
   rather than writing through them.

   The profiles are guidance, not a permission boundary: configure your
   harness's tools and permissions separately, and keep approval with humans.
   Your harness may require trusting the project or starting a new session
   before it discovers new profiles.

2. Create `docs/architecture/decisions/ADR-0001-use-python.md`:

   ```markdown
   ---
   id: ADR-0001
   title: Use Python for the smoke check
   status: proposed
   owner: alice
   created: 2025-01-01
   updated: 2025-01-01
   supersedes: []
   ---

   # ADR-0001: Use Python for the smoke check

   ## Context

   The example needs a portable command.

   ## Decision

   Use Python to print a known string.

   ## Consequences

   The check requires Python.
   ```

3. Create `docs/plans/PLAN-0001-add-a-smoke-check.md`:

   ````markdown
   ---
   id: PLAN-0001
   title: Add a smoke check
   status: review
   owner: alice
   created: 2025-01-01
   updated: 2025-01-01
   adrs: [ADR-0001]
   depends_on: []
   ---

   # PLAN-0001: Add a smoke check

   ## Context

   The example needs a repeatable smoke check.

   ## Goals

   - Verify a simple Python command.

   ## Non-goals

   - Monitor a production service.

   ## Approach

   Follow ADR-0001 and verify the command's output.

   ## Tasks

   ### PLAN-0001-T01: Verify the smoke check

   ```yaml
   status: todo
   depends_on: []
   agent: implementer
   ```

   Run the command and check its output.

   **Acceptance criteria**

   - [ ] `python -c "print('ok')"` prints `ok`.

   ## Validation

   Repeat the acceptance criterion.

   ## Risks

   - This example does not check application behavior.
   ````

4. Validate, approve the ADR before the plan, and work through the task. Use
   the configured approver's handle in place of `alice`:

   ```sh
   specnest validate
   specnest approve ADR-0001 --by alice
   specnest approve PLAN-0001 --by alice
   specnest list
   specnest next --json
   specnest show PLAN-0001-T01
   specnest task PLAN-0001-T01 --status in-progress
   python -c "print('ok')"
   specnest task PLAN-0001-T01 --status done
   specnest validate
   ```

Completing the last task automatically marks the plan `done`. SpecNest does
not run acceptance criteria or authenticate the person named by `--by`; use
your own review process and access controls.

## Commands

```bash
specnest --help
specnest <command> --help
```

| Command | Purpose |
| --- | --- |
| `specnest init [--approver HANDLE] [--harness HARNESS]` | Initialize a project without overwriting existing files. |
| `specnest validate` | Report errors and warnings across all plans and ADRs. Warnings alone do not fail validation. |
| `specnest list` | List plans and ADRs, including task progress. |
| `specnest next [--plan PLAN-0001] [--json]` | Select a ready task from approved plans; resume an in-progress task before a new one within the same plan. |
| `specnest show ID` | Show a task brief or summarize a plan or ADR. |
| `specnest task ID --status STATUS [--reason TEXT]` | Update a task. Status is `todo`, `in-progress`, `done`, or `blocked`; a blocked task requires a reason. |
| `specnest approve ID --by HANDLE` | Record a human approval and seal the plan or ADR. |
| `specnest new {plan,adr} TITLE [--owner HANDLE]` | Create a draft from a project-supplied template. |
| `specnest shortcut [NAME] [--bin-dir DIR] [--remove]` | Create or remove a short alias (default `sn`) if the name is free. |

Without `--root`, `init` uses the current directory; other commands search it
and its parents for `docs/specs.config.yaml`. To operate elsewhere, put
`--root` **before** the command, for example
`specnest --root /path/to/project init --approver alice`.

Exit codes are `0` for success, `1` for validation or workflow errors, `2` for
argument errors, and `3` when `next` finds no ready task. With `next --json`,
the success response contains `task`, `title`, `status`, `agent`, `plan`, and
`plan_path`; the no-task response contains `"task": null` and a list of
`"reasons"`.

## Repository format and workflow

SpecNest looks for files in these locations, relative to the project root:

```text
docs/specs.config.yaml                  # approvers
docs/plans/PLAN-0001-example.md         # plans
docs/architecture/decisions/ADR-0001-example.md
docs/templates/plan.md                  # required only for "new plan"
docs/templates/adr.md                   # required only for "new adr"
.github/agents/implementer.agent.md     # Copilot; or a profile for another harness
.claude/agents/implementer.md           # Claude Code
.codex/agents/implementer.toml          # Codex
.gemini/agents/implementer.md           # Gemini CLI
.cursor/agents/implementer.md           # Cursor
```

Only the selected harness's agent files are needed. Referenced agents may be
defined in any supported harness directory. SpecNest identifies Copilot agents
by their filenames; the other harnesses use the profile's `name` (Cursor also
supports its filename when `name` is omitted). Task briefs list matching
profile paths.

Plan and ADR filenames must start with their ID; `PLAN-0001.md` and
`ADR-0001.md` are also accepted. Both types require `id`, `title`, `status`,
`owner`, `created`, and `updated` front matter; dates use `YYYY-MM-DD`. The H1
must be `# ID: Title`. Plans need Context, Goals, Non-goals, Approach, Tasks,
Validation, and Risks sections; ADRs need Context, Decision, and Consequences.
Incomplete sections and placeholders are warnings in drafts and errors when
the document is ready for review or approval.

Under a plan's `## Tasks` section, each task has a heading such as
`### PLAN-0001-T01: Title`, followed immediately (apart from blank lines) by a
fenced YAML metadata block and an **Acceptance criteria** list. The metadata
may contain `status`, `depends_on`, `agent`, and `blocked_reason`; task
dependencies are task ID lists, and the default agent is `implementer`.
Plan `depends_on` and `adrs` are lists of plan IDs and ADR IDs respectively.
The validator checks references, task and plan dependency cycles, agent files,
statuses, and approval seals.

A typical lifecycle is:

1. Write a `draft` plan or ADR, fill in its content, then set its status to
   `review` (plan) or `proposed` (ADR).
2. Run `specnest validate`. A human approver accepts referenced ADRs and then
   approves the plan. Approved plans may only rely on accepted ADRs.
3. Use `next`, `show`, and `task` to work in dependency order. A plan waits for
   prerequisite plans to be `done`; a task waits for prerequisite tasks to be
   `done`. Use `--status blocked --reason "..."` when work cannot proceed.
4. After the last task is done, the plan becomes `done`. Reopening a completed
   task is rejected when dependent work has already started.

Approvals detect changes to sealed content. Task status and blocked reason,
along with selected administrative front matter, may change without breaking
the seal. To amend an approved plan, return it to `review`, remove its
`approval` block, make the changes, and have a human approve it again. A
deprecated or superseded ADR puts dependent approved plans on hold until they
are amended and re-approved. See [Architecture](docs/architecture.md) for
details and limitations.

### Scaffolding drafts

`new` needs `docs/templates/plan.md` or `docs/templates/adr.md` in the
consuming project. `init` copies the bundled
[plan](src/specnest/templates/plan.md) and
[ADR](src/specnest/templates/adr.md) templates there if they do not already
exist. It also copies the bundled
[agent templates](src/specnest/templates/agents/) to the selected harness's
project directory. You can edit or replace the copied files with your own:

```sh
specnest new plan "Improve the smoke check" --owner alice
specnest new adr "Choose a test runner" --owner alice
```

Templates use `{{id}}`, `{{title}}`, `{{owner}}`, and `{{date}}` substitutions.
The owner defaults to the first configured approver. Fill in the resulting
drafts and replace their placeholders before review.

## Development

With [uv](https://docs.astral.sh/uv/) installed, set up the locked development
dependencies and run the test suite from this checkout:

```sh
uv sync --locked
make test
```

The tests use temporary project directories; they do not require a GitHub
account or modify a consuming project. Without Make, run
`uv run --locked python -m pytest -q` instead.

## Contributing

Issues and pull requests are welcome. Before opening a pull request, run
`make test` and describe the changes and their intended behavior.

By submitting a contribution, you confirm that you have the right to submit it
and agree to license it under the project's [MIT license](LICENSE).

## Publishing

Releases go to [TestPyPI](https://test.pypi.org/) first, then to PyPI:

| Command | What it does |
| --- | --- |
| `make publish-test` | Runs the tests, builds the sdist and wheel in `dist/pypi`, and uploads the current version to TestPyPI. |
| `make verify-test` | Installs the current version's wheel from TestPyPI in an isolated environment and checks `specnest --version`. |
| `make publish` | Runs the tests, builds, verifies the TestPyPI release, and uploads the same version to PyPI. |

`make publish` stops before uploading if the current version is not installable
from TestPyPI. PyPI and TestPyPI versions are immutable and public; use a new
version for every release and keep the version in `pyproject.toml` and
`src/specnest/__init__.py` in sync.

Uploads authenticate with API tokens, never with a username and password.
TestPyPI and PyPI are separate services, so create an account, enable 2FA, and
create an API token on each: [TestPyPI](https://test.pypi.org/manage/account/)
and [PyPI](https://pypi.org/manage/account/). The first upload of a new project
needs an account-scoped token; afterward, replace it with a project-scoped token.
Both registries upload through their `/legacy/` endpoint, which is PyPI's
current upload API despite its name.

In Bash or Zsh, enter each token without echoing it or saving it in shell
history:

```sh
printf 'TestPyPI token: '
read -rs TEST_PYPI_TOKEN; echo
export TEST_PYPI_TOKEN
make publish-test
make verify-test
unset TEST_PYPI_TOKEN

printf 'PyPI token: '
read -rs PYPI_TOKEN; echo
export PYPI_TOKEN
make publish
unset PYPI_TOKEN
```

Do not commit tokens.

### Publishing from GitHub Actions

[`.github/workflows/publish.yml`](.github/workflows/publish.yml) publishes with
[Trusted Publishing](https://docs.pypi.org/trusted-publishers/), so no tokens
are stored in GitHub:

- **Run workflow** (manual) runs the tests, builds, uploads to TestPyPI, and
  verifies the install.
- **Pushing a `vX.Y.Z` tag** does the same, then uploads the same files to PyPI.
  The tag must match the version in `pyproject.toml`.

See the [release management guide](docs/release-management.md) for one-time
setup, the complete release procedure, and local publishing details.

To release:

```sh
git tag vX.Y.Z
git push origin vX.Y.Z
```

## License

The package is distributed under the MIT license. The implementation and license
are attributed to A42SS; see [LICENSE](LICENSE) for the full terms.

The software is provided **as is**, without warranty. Use it at your own risk:
review changes and keep backups before running commands that modify files.