Skip to content

Commit 1d8e25e

Browse files
author
Christian Kaman
committed
install-rules: write to docs, constitution, and agent context file
The install-rules command previously wrote a single docs file that the AI agent could safely ignore. Change it to also update the spec-kit constitution and the agent-specific system context file so the rules become binding at runtime for whichever agent the user initialized the project with. - scripts/bash/install-rules.sh: new helper that performs all three writes. Parses .specify/init-options.json for the agent id and project name. Maps agent ids to their native context files (CLAUDE.md, AGENTS.md, .cursorrules, .windsurfrules, GEMINI.md, .github/copilot-instructions.md). Defaults to AGENTS.md for any unknown agent so the emerging cross-agent convention still works. Supports --docs, --project-name, and --force flags. Backs up the full docs file before replacement. Appends the short rules block to the constitution and agent context file idempotently — skips if the section already exists, unless --force. - commands/install-rules.md: rewrite the Context and Steps sections to reflect the three-target design. Adds a script reference in the frontmatter and documents the agent-to-file mapping, the --force semantics, and the safety rules. - tests/install-rules/writes-three-targets.sh: fixture with a claude init, asserts docs/DEVELOPMENT-RULES.md exists with project name substituted, constitution contains the Development Rules section, CLAUDE.md is written with the agent-specific block, and the summary output mentions the detected agent. - tests/install-rules/agent-fallback.sh: fixture with no .specify/init-options.json at all. Installer defaults to generic + AGENTS.md, creates the constitution from scratch, and still substitutes a project name passed via --project-name. - tests/install-rules/idempotent-append.sh: runs the installer twice, asserts the constitution and AGENTS.md each contain exactly one "## Development Rules" heading, and the second run prints "skipped" for both append targets. - extension.yml: version bumped to 0.2.2. - README.md: version badge and verify block updated to 0.2.2. - CHANGELOG.md: 0.2.2 entry documenting the three-target change and the new helper script, with full per-agent mapping. Test suite is now 8 tests (was 5). All pass on macOS.
1 parent 0cd824c commit 1d8e25e

8 files changed

Lines changed: 463 additions & 57 deletions

File tree

CHANGELOG.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,47 @@
33
All notable changes to `tekimax-security` will be documented here.
44
Format: [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) · SemVer.
55

6+
## [0.2.2] — 2026-04-13
7+
8+
### Changed
9+
10+
- **`install-rules` command** now writes to three targets instead of
11+
one, so the rules are binding on the AI agent at runtime instead
12+
of sitting in a docs file the agent may never read:
13+
1. `docs/DEVELOPMENT-RULES.md` — full human-readable reference
14+
(unchanged behavior, existing files backed up with timestamp)
15+
2. `.specify/memory/constitution.md` — spec-kit constitution, read
16+
by every spec-kit-aware agent at session start. Appends a
17+
`## Development Rules` section with the 8 key principles and
18+
a pointer to the full doc. Safe to re-run — skips if the
19+
section already exists unless `--force` is passed.
20+
3. Agent-specific context file — detected from
21+
`.specify/init-options.json` and mapped per agent:
22+
- `claude``CLAUDE.md`
23+
- `copilot``.github/copilot-instructions.md`
24+
- `gemini``GEMINI.md`
25+
- `cursor` / `cursor-agent``.cursorrules`
26+
- `windsurf``.windsurfrules`
27+
- everything else → `AGENTS.md` (the emerging cross-agent convention)
28+
29+
- **New helper script** `scripts/bash/install-rules.sh` performs the
30+
three-target writes atomically. Detects the project name from
31+
`.specify/init-options.json` or the current directory name.
32+
Accepts `--docs`, `--project-name`, and `--force` flags. Prints a
33+
summary box showing which files were created, appended, or skipped.
34+
35+
### Added
36+
37+
- **Three new tests** under `tests/install-rules/`:
38+
- `writes-three-targets.sh` — claude agent, verifies all three
39+
files are written and project name is substituted into the docs
40+
- `agent-fallback.sh` — unknown/generic agent, verifies fallback to
41+
`AGENTS.md` and constitution creation from scratch
42+
- `idempotent-append.sh` — running twice doesn't duplicate the
43+
`## Development Rules` section in the constitution or agent file
44+
45+
Test suite is now 8 tests (was 5). All pass.
46+
647
## [0.2.1] — 2026-04-13
748

849
### Added

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
1111
[![Spec Kit Extension](https://img.shields.io/badge/spec--kit-extension-7c3aed)](https://github.com/github/spec-kit)
1212
[![License](https://img.shields.io/badge/license-Apache--2.0-blue)](LICENSE)
13-
[![Version](https://img.shields.io/badge/version-0.2.1-green)](CHANGELOG.md)
13+
[![Version](https://img.shields.io/badge/version-0.2.2-green)](CHANGELOG.md)
1414
[![Status](https://img.shields.io/badge/status-alpha-orange)]()
1515
[![Made by TEKIMAX](https://img.shields.io/badge/made%20by-TEKIMAX-fbbf24)](https://tekimax.com)
1616

@@ -64,7 +64,7 @@ specify extension add --dev /path/to/speckit-security
6464

6565
# 3. Verify
6666
specify extension list
67-
# → ✓ TEKIMAX Secure SDD (v0.2.1)
67+
# → ✓ TEKIMAX Secure SDD (v0.2.2)
6868
# Security-first extension for Spec Kit
6969
# Commands: 8 | Hooks: 5 | Status: Enabled
7070
```

commands/install-rules.md

Lines changed: 68 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,97 @@
11
---
2-
description: "Install a DEVELOPMENT-RULES.md into the user's project with commit, file-structure, code-org, naming, docs, and test rules"
2+
description: "Install development rules into the project — writes docs/DEVELOPMENT-RULES.md, appends to .specify/memory/constitution.md, and writes the agent-specific context file"
3+
scripts:
4+
sh: .specify/extensions/tekimax-security/scripts/bash/install-rules.sh
35
---
46

57
# Install Development Rules
68

7-
Copy the `speckit-security` development rules template into the user's
8-
project so their team inherits the same discipline: clean commit
9-
messages, hooks-in-hooks-directory, DRY, helper extraction, file length
10-
limits, naming conventions, inline documentation for intent, and
11-
incremental unit test requirements.
9+
Install the speckit-security development discipline into the user's
10+
project so both humans and the active AI agent inherit it. The rules
11+
cover commit messages, file structure, DRY, helper extraction, file
12+
length, naming, inline documentation, unit test requirements, and the
13+
review checklist.
1214

1315
## User Input
1416

1517
$ARGUMENTS
1618

1719
## Context
1820

19-
The rules are opinionated but stack-agnostic and have been battle-tested
20-
on this extension's own codebase. The goal is to raise the baseline
21-
engineering discipline of any project adopting `speckit-security`
22-
without forcing them to invent conventions from scratch.
21+
Writing the rules to a single `docs/` file is not enough — the AI
22+
agent only reads files it's explicitly directed to. To make the rules
23+
*binding* at runtime, they also need to land in the spec-kit
24+
constitution (which every spec-kit-aware agent reads at session start)
25+
and in the agent's native system-context file.
26+
27+
This command delegates to a bash helper that handles all three writes
28+
atomically, detects the active agent from `.specify/init-options.json`,
29+
and safely appends to existing files without clobbering them.
2330

2431
## Steps
2532

26-
1. **Locate the project root** — the directory containing `.specify/`.
33+
1. Run the installer script:
2734

28-
2. **Determine the target path** — default is `docs/DEVELOPMENT-RULES.md`
29-
at the project root. If the user passed a path in `$ARGUMENTS`, use
30-
that instead.
35+
```bash
36+
bash {SCRIPT}
37+
```
3138

32-
3. **Check for an existing file at the target path.** If one exists:
33-
- **Do not overwrite silently.** Back it up to
34-
`<target>.backup-<date>.md` and note the backup path.
35-
- Or exit and ask the user to confirm overwrite.
39+
Optional arguments:
40+
- `--docs <path>` — override the default `docs/DEVELOPMENT-RULES.md` target
41+
- `--project-name <name>` — override project name detection
42+
- `--force` — replace an existing `## Development Rules` section
43+
in the constitution or agent context file instead of skipping it
3644

37-
4. **Read the template** from
38-
`.specify/extensions/tekimax-security/templates/development-rules.md`.
45+
2. The script performs three writes:
3946

40-
5. **Substitute variables** in the template:
41-
- `{{PROJECT_NAME}}` → the project name from `.specify/init-options.json`
42-
or the directory name if the JSON isn't present.
47+
**Target 1 — `docs/DEVELOPMENT-RULES.md`**
4348

44-
6. **Write the rendered file** to the target path. Create the `docs/`
45-
directory if it doesn't exist.
49+
Full human-readable rules. Template is copied from
50+
`.specify/extensions/tekimax-security/templates/development-rules.md`
51+
with `{{PROJECT_NAME}}` substituted. Existing files are backed up
52+
with a timestamped suffix before being overwritten.
4653

47-
7. **Update the project's `CONTRIBUTING.md` if present** to add a
48-
reference:
54+
**Target 2 — `.specify/memory/constitution.md`**
4955

50-
```markdown
51-
## Development Rules
56+
Spec-kit's project constitution. Every spec-kit-aware agent reads
57+
this at session start, so rules written here bind every agent the
58+
user interacts with. The script appends a `## Development Rules`
59+
section with the key principles (short form) and a pointer to the
60+
full doc. If the section already exists, the script skips it
61+
unless `--force` was passed.
5262

53-
See [docs/DEVELOPMENT-RULES.md](docs/DEVELOPMENT-RULES.md) for the
54-
full development discipline — commit messages, file structure,
55-
code organization, naming, documentation, and unit test rules.
56-
```
63+
**Target 3 — Agent-specific context file**
5764

58-
If no `CONTRIBUTING.md` exists, skip this step and note it in the
59-
output.
65+
The agent is detected from `.specify/init-options.json` (`ai`
66+
field). The script maps the agent to its native context file:
6067

61-
8. **Print a summary** of what was installed:
68+
| Agent | File |
69+
|---|---|
70+
| `claude` | `CLAUDE.md` |
71+
| `copilot` | `.github/copilot-instructions.md` |
72+
| `gemini` | `GEMINI.md` |
73+
| `cursor` / `cursor-agent` | `.cursorrules` |
74+
| `windsurf` | `.windsurfrules` |
75+
| `opencode`, `codex`, `kiro-cli`, and everything else | `AGENTS.md` |
6276

63-
```
64-
✓ Installed DEVELOPMENT-RULES.md at docs/DEVELOPMENT-RULES.md
65-
✓ Added reference in CONTRIBUTING.md
66-
67-
Next steps:
68-
1. Review the rules and customize §5 (naming) for your language
69-
2. Remove any sections that don't apply (e.g. bash-specific rules
70-
for a TypeScript project)
71-
3. Commit the file
72-
4. Link it from your CONTRIBUTING.md if you don't already
73-
```
77+
The same short-form rules section is appended to the detected
78+
context file. Same safety rules as the constitution: skip if
79+
section exists, unless `--force`.
80+
81+
3. The script prints a summary box with the three target paths and
82+
whether each was created, appended, or skipped.
83+
84+
4. If the user wants to review before committing, they can diff the
85+
three files against the backups or against their git index.
7486

7587
## Rules
7688

77-
- **Never overwrite an existing file without backing it up.**
78-
- **Never modify files outside the project root.**
79-
- **Leave a visible note** in the installed file indicating which
80-
command installed it and that it can be freely customized.
81-
- The installed rules are **a starting point**, not a straitjacket.
82-
Teams are expected to adapt them to their language, framework, and
83-
conventions.
89+
- **Never silently overwrite.** The full `docs/DEVELOPMENT-RULES.md`
90+
is backed up before replacement; the constitution and agent context
91+
files are append-only unless `--force` is passed.
92+
- **Never modify files outside the project root.** The script uses
93+
relative paths and refuses to write to absolute paths.
94+
- **Detect the agent correctly.** If `.specify/init-options.json` is
95+
missing or malformed, default to `generic` + `AGENTS.md`.
96+
- **Print what changed.** The summary box is the contract — every run
97+
tells the user exactly which files were touched.

extension.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ schema_version: "1.0"
33
extension:
44
id: "tekimax-security"
55
name: "TEKIMAX Secure SDD"
6-
version: "0.2.1"
6+
version: "0.2.2"
77
description: "Security-first extension for Spec Kit — threat modeling, red teaming, AI guardrails, data contracts, and model governance gates."
88
author: "Christian Kaman (TEKIMAX) <support@tekimax.com>"
99
repository: "https://github.com/TEKIMAX/speckit-security"

0 commit comments

Comments
 (0)