specjig 0.0.1-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +51 -0
- package/LICENSE +24 -0
- package/README.md +107 -0
- package/bin/specjig.mjs +7 -0
- package/harness.lock.json +61 -0
- package/package.json +56 -1
- package/src/cli.mjs +278 -0
- package/src/lib/install.mjs +242 -0
- package/src/lib/openspec.mjs +83 -0
- package/src/lib/util.mjs +86 -0
- package/templates/.claude/hooks/sdd-commit-guard.mjs +39 -0
- package/templates/.claude/hooks/sdd-fix-mode-guard.mjs +34 -0
- package/templates/.claude/hooks/sdd-lib/change-id.mjs +47 -0
- package/templates/.claude/hooks/sdd-lib/io.mjs +29 -0
- package/templates/.claude/hooks/sdd-lib/patterns.mjs +130 -0
- package/templates/.claude/hooks/sdd-prompt-guard.mjs +17 -0
- package/templates/.claude/hooks/sdd-protect-secrets.mjs +32 -0
- package/templates/.claude/rules/openspec.md +14 -0
- package/templates/.claude/rules/security.md +31 -0
- package/templates/.claude/rules/test-data.md +22 -0
- package/templates/.claude/settings.json +97 -0
- package/templates/.claude/skills/change-pr/SKILL.md +61 -0
- package/templates/.claude/skills/spec-challenge/SKILL.md +63 -0
- package/templates/.claude/skills/spec-compaction/SKILL.md +47 -0
- package/templates/.claude/skills/trace-why/SKILL.md +30 -0
- package/templates/.githooks/commit-msg +4 -0
- package/templates/.github/workflows/sdd-ci-triage.yml +61 -0
- package/templates/.github/workflows/sdd-confluence-sync.yml +24 -0
- package/templates/.github/workflows/sdd-drift-check.yml +50 -0
- package/templates/.github/workflows/sdd-fix-pr-guard.yml +25 -0
- package/templates/.github/workflows/sdd-release-notes.yml +45 -0
- package/templates/.github/workflows/sdd-security-review.yml +23 -0
- package/templates/.github/workflows/sdd-spec-gate.yml +23 -0
- package/templates/.github/workflows/sdd-spec-review.yml +51 -0
- package/templates/.mcp.json +8 -0
- package/templates/.sdd/harness.json +21 -0
- package/templates/.sdd/scripts/check-commit-msg.mjs +15 -0
- package/templates/.sdd/scripts/check-trailers.mjs +27 -0
- package/templates/.sdd/scripts/confluence-sync.mjs +110 -0
- package/templates/.sdd/scripts/drift-check.mjs +30 -0
- package/templates/.sdd/scripts/fix-pr-guard.mjs +17 -0
- package/templates/.sdd/scripts/lib.mjs +31 -0
- package/templates/.sdd/scripts/release-notes.mjs +63 -0
- package/templates/AGENTS.md +87 -0
- package/templates/CLAUDE.md +30 -0
- package/templates/openspec/config.yaml +38 -0
- package/templates/openspec/schemas/sdd/schema.yaml +379 -0
- package/templates/openspec/schemas/sdd/templates/design.md +29 -0
- package/templates/openspec/schemas/sdd/templates/impact.md +27 -0
- package/templates/openspec/schemas/sdd/templates/proposal.md +43 -0
- package/templates/openspec/schemas/sdd/templates/spec.md +13 -0
- package/templates/openspec/schemas/sdd/templates/tasks.md +15 -0
- package/templates/openspec/schemas/sdd/templates/tests.md +17 -0
- package/vendor/skills/grilling/.upstream.json +8 -0
- package/vendor/skills/grilling/SKILL.md +30 -0
- package/vendor/skills/receiving-code-review/.upstream.json +8 -0
- package/vendor/skills/receiving-code-review/SKILL.md +205 -0
- package/vendor/skills/systematic-debugging/.upstream.json +8 -0
- package/vendor/skills/systematic-debugging/SKILL.md +283 -0
- package/vendor/skills/systematic-debugging/condition-based-waiting-example.ts +158 -0
- package/vendor/skills/systematic-debugging/condition-based-waiting.md +115 -0
- package/vendor/skills/systematic-debugging/defense-in-depth.md +122 -0
- package/vendor/skills/systematic-debugging/find-polluter.sh +72 -0
- package/vendor/skills/systematic-debugging/root-cause-tracing.md +169 -0
- package/vendor/skills/test-driven-development/.upstream.json +8 -0
- package/vendor/skills/test-driven-development/SKILL.md +330 -0
- package/vendor/skills/test-driven-development/writing-good-tests.md +198 -0
- package/vendor/skills/two-axis-review/.upstream.json +8 -0
- package/vendor/skills/two-axis-review/SKILL.md +89 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. The format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses
|
|
5
|
+
[Semantic Versioning](https://semver.org/).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## [0.2.0] - 2026-11-24
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- The npm package, the CLI command (`npx specjig …`) and the GitHub repository are now named
|
|
14
|
+
`specjig`.
|
|
15
|
+
|
|
16
|
+
## [0.1.1] - 2026-11-24
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
- Releases publish to npm through Trusted Publishing (OIDC) with automatic provenance.
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
|
|
24
|
+
- `--version` printed the help text instead of the version (`-v` worked).
|
|
25
|
+
|
|
26
|
+
## [0.1.0] - 2026-11-23
|
|
27
|
+
|
|
28
|
+
### Added
|
|
29
|
+
|
|
30
|
+
- CLI: `init`, `update`, `check`, `audit-secrets`, `github-setup`.
|
|
31
|
+
- OpenSpec integration with two modes: `install` (harness pins and bumps `@fission-ai/openspec`,
|
|
32
|
+
2.1.1) and `existing` (keeps the project's own OpenSpec; CI uses its version).
|
|
33
|
+
- `sdd` schema, a fork of `spec-driven`: risk levels, `impact` and `tests` artifacts,
|
|
34
|
+
layer-split tasks, mandatory Open questions, TDD in apply.
|
|
35
|
+
- `AGENTS.md` / `CLAUDE.md` with the change lifecycle, traceability and governance.
|
|
36
|
+
- Claude Code settings: `permissions.deny` for secrets and real data, hooks
|
|
37
|
+
`sdd-protect-secrets`, `sdd-prompt-guard`, `sdd-fix-mode-guard`, `sdd-commit-guard`.
|
|
38
|
+
- Rules: security (PII/PHI, auth, tenant isolation), test data, openspec.
|
|
39
|
+
- Pinned skills: `grilling`, `two-axis-review` (mattpocock/skills); `test-driven-development`,
|
|
40
|
+
`systematic-debugging`, `receiving-code-review` (obra/superpowers).
|
|
41
|
+
- Own skills: `spec-challenge`, `change-pr`, `trace-why`, `spec-compaction`.
|
|
42
|
+
- Playwright MCP, pinned.
|
|
43
|
+
- `Change-Id` commit trailer enforced by Claude hook, git `commit-msg` hook and CI.
|
|
44
|
+
- Workflows: spec gate, drift check, spec-aware review, security review, CI triage with fix PRs,
|
|
45
|
+
fix-PR guard with auto-merge, release notes, Confluence sync.
|
|
46
|
+
- Update model with file ownership (managed / block / merge / seed), `.sdd-new` on conflicts, and opt-outs (deleted files or `exclude` in `.sdd/harness.json` stay out).
|
|
47
|
+
|
|
48
|
+
[Unreleased]: https://github.com/Vlad-Movchan/specjig/compare/v0.2.0...HEAD
|
|
49
|
+
[0.2.0]: https://github.com/Vlad-Movchan/specjig/compare/v0.1.1...v0.2.0
|
|
50
|
+
[0.1.1]: https://github.com/Vlad-Movchan/specjig/compare/v0.1.0...v0.1.1
|
|
51
|
+
[0.1.0]: https://github.com/Vlad-Movchan/specjig/releases/tag/v0.1.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 specjig contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
Vendored skills under vendor/skills/ keep their upstream MIT licenses
|
|
24
|
+
(mattpocock/skills, obra/superpowers); see each .upstream.json.
|
package/README.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# specjig
|
|
2
|
+
|
|
3
|
+
[](https://github.com/Vlad-Movchan/specjig/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/specjig)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
**A reusable agent harness for spec-driven development with Claude Code.** One command adds a
|
|
8
|
+
complete, opinionated setup to any repository:
|
|
9
|
+
|
|
10
|
+
- [OpenSpec](https://github.com/Fission-AI/OpenSpec) with an `sdd` schema: risk levels, impact
|
|
11
|
+
map, test plan from spec scenarios, tasks split by layer.
|
|
12
|
+
- `AGENTS.md` / `CLAUDE.md` with the change lifecycle, traceability and governance.
|
|
13
|
+
- Guardrails: secrets and real data never reach the agent (permission rules and fail-closed
|
|
14
|
+
hooks), a `Change-Id` trailer on every commit, tests and specs frozen for CI fix agents.
|
|
15
|
+
- Pinned skills: TDD, systematic debugging, grilling, code review in both directions, plus
|
|
16
|
+
spec challenge, PR, trace and compaction skills.
|
|
17
|
+
- GitHub workflows: spec gate, drift check, spec-aware review, security review, CI triage with
|
|
18
|
+
fix PRs, release notes, Confluence export.
|
|
19
|
+
|
|
20
|
+
Every upstream piece is pinned and moves only through a reviewed bump. Projects get it with
|
|
21
|
+
`specjig update`, which never overwrites local edits.
|
|
22
|
+
|
|
23
|
+
## Why OpenSpec
|
|
24
|
+
|
|
25
|
+
OpenSpec keeps two states of the product at once. `openspec/specs/` is how the system behaves
|
|
26
|
+
now; `openspec/changes/<id>/` is how it will behave, plus why and how. Archiving a change merges
|
|
27
|
+
it into `specs/`, so decisions stay next to the code. With the `Change-Id` trailer,
|
|
28
|
+
`git blame` → commit → change folder explains any line.
|
|
29
|
+
|
|
30
|
+
## Quick start
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm i -D -E specjig # or: pnpm add -D -E specjig
|
|
34
|
+
npx specjig init
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Then:
|
|
38
|
+
|
|
39
|
+
1. Fill the TODOs in `AGENTS.md`, `openspec/config.yaml` and `.sdd/harness.json`.
|
|
40
|
+
2. In GitHub, add the `ANTHROPIC_API_KEY` secret and run `npx specjig github-setup` to create the labels.
|
|
41
|
+
3. In Claude Code, start a change with `/openspec-propose`.
|
|
42
|
+
|
|
43
|
+
The harness needs Node 20+ and works in any repository. A non-JS project gets a tooling-only
|
|
44
|
+
`package.json`. Already using OpenSpec? `init` asks whether to keep your installation
|
|
45
|
+
(`--openspec existing`) or let the harness manage it (`--openspec install`); see
|
|
46
|
+
[updating](docs/updating.md#openspec-ownership-install-or-existing).
|
|
47
|
+
|
|
48
|
+
## Commands
|
|
49
|
+
|
|
50
|
+
| Command | What it does |
|
|
51
|
+
|---------|--------------|
|
|
52
|
+
| `specjig init [--openspec install\|existing]` | Sets up OpenSpec, installs harness files, enables the `commit-msg` hook, updates `.gitignore` |
|
|
53
|
+
| `specjig update [--openspec …]` | Re-applies files after upgrading the package; keeps local edits (`<file>.sdd-new` on conflict) |
|
|
54
|
+
| `specjig check` | Shows the project, pinned and latest versions of the harness, OpenSpec and skills |
|
|
55
|
+
| `specjig audit-secrets [paths…]` | Scans this project's Claude transcripts and the given logs for leaked secrets |
|
|
56
|
+
| `specjig github-setup` | Creates the PR labels the workflows use |
|
|
57
|
+
|
|
58
|
+
## Documentation
|
|
59
|
+
|
|
60
|
+
| Topic | |
|
|
61
|
+
|-------|-|
|
|
62
|
+
| [Workflow](docs/workflow.md) | Change lifecycle, the `sdd` schema, risk levels, traceability |
|
|
63
|
+
| [Skills](docs/skills.md) | What is bundled and why (e.g. superpowers TDD over mattpocock `tdd`) |
|
|
64
|
+
| [CI workflows](docs/ci.md) | What runs where, which checks block, setup and cost controls |
|
|
65
|
+
| [Governance](docs/governance.md) | Secrets, data, hooks, policy, cost and how each is checked |
|
|
66
|
+
| [Updating](docs/updating.md) | Pins, how upstream bumps reach projects, file ownership, OpenSpec modes |
|
|
67
|
+
| [Customizing](docs/customizing.md) | `.sdd/harness.json`, opting out, adding your own rules and skills |
|
|
68
|
+
|
|
69
|
+
## What gets installed
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
AGENTS.md, CLAUDE.md your project facts + managed workflow/governance block
|
|
73
|
+
.claude/settings.json deny rules for secrets, ask for push/merge/publish, hooks
|
|
74
|
+
.claude/hooks/ protect-secrets, prompt-guard, fix-mode-guard, commit-guard
|
|
75
|
+
.claude/rules/ security (PII/PHI, auth, tenant isolation), test data, openspec
|
|
76
|
+
.claude/skills/ pinned third-party skills, harness skills, OpenSpec skills
|
|
77
|
+
.mcp.json Playwright MCP (pinned)
|
|
78
|
+
.githooks/commit-msg Change-Id trailer for human commits
|
|
79
|
+
openspec/schemas/sdd/ the sdd schema
|
|
80
|
+
openspec/config.yaml project context and per-artifact rules
|
|
81
|
+
.sdd/harness.json layers, domain paths, frozen paths, opt-outs
|
|
82
|
+
.sdd/scripts/ CI helpers
|
|
83
|
+
.github/workflows/sdd-*.yml CI workflows
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Limits
|
|
87
|
+
|
|
88
|
+
- Hooks are guardrails, not a sandbox. For OS-level enforcement, also enable Claude Code's sandbox.
|
|
89
|
+
- The guardrail hooks and skills target Claude Code. Other agents get the workflow and rules
|
|
90
|
+
through `AGENTS.md`.
|
|
91
|
+
- Tested on Linux and macOS. Windows is untested.
|
|
92
|
+
|
|
93
|
+
## Contributing
|
|
94
|
+
|
|
95
|
+
Issues and PRs are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md); report security issues
|
|
96
|
+
privately as described in [SECURITY.md](SECURITY.md).
|
|
97
|
+
|
|
98
|
+
## Credits
|
|
99
|
+
|
|
100
|
+
Built on [OpenSpec](https://github.com/Fission-AI/OpenSpec) and skills from
|
|
101
|
+
[mattpocock/skills](https://github.com/mattpocock/skills) and
|
|
102
|
+
[obra/superpowers](https://github.com/obra/superpowers), all MIT licensed and vendored at pinned
|
|
103
|
+
commits (see `vendor/skills/*/.upstream.json`).
|
|
104
|
+
|
|
105
|
+
## License
|
|
106
|
+
|
|
107
|
+
[MIT](LICENSE)
|
package/bin/specjig.mjs
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$comment": "Pinned upstream versions. Bump with `npm run vendor:update` / `npm run openspec:bump`, never by hand-editing vendor/.",
|
|
3
|
+
"openspec": {
|
|
4
|
+
"package": "@fission-ai/openspec",
|
|
5
|
+
"version": "2.1.1",
|
|
6
|
+
"schemaForkedFrom": "spec-driven"
|
|
7
|
+
},
|
|
8
|
+
"skills": [
|
|
9
|
+
{
|
|
10
|
+
"dest": "grilling",
|
|
11
|
+
"repo": "mattpocock/skills",
|
|
12
|
+
"path": "skills/productivity/grilling",
|
|
13
|
+
"branch": "main",
|
|
14
|
+
"sha": "7739eaed7f8f3915437a8def198a6d0d7206dbc7",
|
|
15
|
+
"exclude": [
|
|
16
|
+
"agents/"
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"dest": "two-axis-review",
|
|
21
|
+
"repo": "mattpocock/skills",
|
|
22
|
+
"path": "skills/engineering/code-review",
|
|
23
|
+
"branch": "main",
|
|
24
|
+
"sha": "7739eaed7f8f3915437a8def198a6d0d7206dbc7",
|
|
25
|
+
"exclude": [
|
|
26
|
+
"agents/"
|
|
27
|
+
],
|
|
28
|
+
"rename": {
|
|
29
|
+
"name": "two-axis-review"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"dest": "test-driven-development",
|
|
34
|
+
"repo": "obra/superpowers",
|
|
35
|
+
"path": "skills/test-driven-development",
|
|
36
|
+
"branch": "main",
|
|
37
|
+
"sha": "5bf4e78011075bcfc0dc295f0724994cd123ee71"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"dest": "receiving-code-review",
|
|
41
|
+
"repo": "obra/superpowers",
|
|
42
|
+
"path": "skills/receiving-code-review",
|
|
43
|
+
"branch": "main",
|
|
44
|
+
"sha": "3fb75974186ea7fada621d8ab77b3b02169baf57"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"dest": "systematic-debugging",
|
|
48
|
+
"repo": "obra/superpowers",
|
|
49
|
+
"path": "skills/systematic-debugging",
|
|
50
|
+
"branch": "main",
|
|
51
|
+
"sha": "22f0b463e7a5e579904dd6211a520321035526f7"
|
|
52
|
+
}
|
|
53
|
+
],
|
|
54
|
+
"mcp": {
|
|
55
|
+
"@playwright/mcp": "0.0.86"
|
|
56
|
+
},
|
|
57
|
+
"actions": {
|
|
58
|
+
"anthropics/claude-code-action": "v1",
|
|
59
|
+
"anthropics/claude-code-security-review": "0c6a49f1fa56a1d472575da86a94dbc1edb78eda"
|
|
60
|
+
}
|
|
61
|
+
}
|
package/package.json
CHANGED
|
@@ -1 +1,56 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"name": "specjig",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Reusable agent harness for spec-driven development: OpenSpec + sdd schema, Claude Code settings, guardrail hooks, pinned skills and CI workflows.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"claude-code",
|
|
7
|
+
"openspec",
|
|
8
|
+
"sdd",
|
|
9
|
+
"spec-driven-development",
|
|
10
|
+
"agent-harness",
|
|
11
|
+
"claude",
|
|
12
|
+
"ai-agents",
|
|
13
|
+
"tdd",
|
|
14
|
+
"guardrails"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://github.com/Vlad-Movchan/specjig#readme",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/Vlad-Movchan/specjig/issues"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/Vlad-Movchan/specjig.git"
|
|
23
|
+
},
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"author": "specjig contributors",
|
|
26
|
+
"type": "module",
|
|
27
|
+
"bin": {
|
|
28
|
+
"specjig": "bin/specjig.mjs"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"bin",
|
|
32
|
+
"src",
|
|
33
|
+
"templates",
|
|
34
|
+
"vendor",
|
|
35
|
+
"harness.lock.json",
|
|
36
|
+
"README.md",
|
|
37
|
+
"LICENSE",
|
|
38
|
+
"CHANGELOG.md"
|
|
39
|
+
],
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=20"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"test": "node --test test/*.test.mjs",
|
|
48
|
+
"vendor:check": "node scripts/vendor.mjs --check",
|
|
49
|
+
"vendor:update": "node scripts/vendor.mjs --update",
|
|
50
|
+
"vendor:sync": "node scripts/vendor.mjs",
|
|
51
|
+
"openspec:check": "node scripts/openspec-bump.mjs --check",
|
|
52
|
+
"openspec:bump": "node scripts/openspec-bump.mjs",
|
|
53
|
+
"lint": "node scripts/lint.mjs",
|
|
54
|
+
"test:e2e": "node --test --test-timeout=600000 test/e2e/smoke.mjs"
|
|
55
|
+
}
|
|
56
|
+
}
|
package/src/cli.mjs
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { readFile, readdir, writeFile } from 'node:fs/promises';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { applyFiles, printReport } from './lib/install.mjs';
|
|
6
|
+
import { chooseMode, ciVersion, compatibilityWarning, describe, detectOpenspec } from './lib/openspec.mjs';
|
|
7
|
+
import {
|
|
8
|
+
addDevDepArgs,
|
|
9
|
+
detectPackageManager,
|
|
10
|
+
lock,
|
|
11
|
+
log,
|
|
12
|
+
parseArgs,
|
|
13
|
+
pkgName,
|
|
14
|
+
pkgVersion,
|
|
15
|
+
PKG_ROOT,
|
|
16
|
+
readJson,
|
|
17
|
+
run,
|
|
18
|
+
tryRun,
|
|
19
|
+
} from './lib/util.mjs';
|
|
20
|
+
|
|
21
|
+
const HELP = `specjig ${pkgVersion()}: spec-driven agent harness (OpenSpec + Claude Code)
|
|
22
|
+
|
|
23
|
+
Usage: specjig <command> [options]
|
|
24
|
+
|
|
25
|
+
Commands:
|
|
26
|
+
init Install the harness into the current project
|
|
27
|
+
update Re-apply harness files after upgrading specjig; bumps OpenSpec to the pinned version
|
|
28
|
+
check Show installed vs pinned vs latest versions (harness, OpenSpec, skills)
|
|
29
|
+
audit-secrets Scan Claude session transcripts (and --paths) for leaked secrets
|
|
30
|
+
github-setup Create the PR labels the CI workflows use (needs gh)
|
|
31
|
+
|
|
32
|
+
Options:
|
|
33
|
+
--dir <path> Project directory (default: cwd)
|
|
34
|
+
--openspec <mode> install: the harness pins and bumps OpenSpec (default for new projects)
|
|
35
|
+
existing: keep the project's own OpenSpec; only add schema, skills, hooks, CI
|
|
36
|
+
(asked interactively when OpenSpec is already present; remembered for update)
|
|
37
|
+
--skip-install Do not install @fission-ai/openspec as a devDependency (install mode)
|
|
38
|
+
--no-package-json Do not create a package.json in non-JS projects
|
|
39
|
+
--no-git-hooks Do not set core.hooksPath to .githooks
|
|
40
|
+
`;
|
|
41
|
+
|
|
42
|
+
export async function main(argv) {
|
|
43
|
+
const { flags, positional } = parseArgs(argv);
|
|
44
|
+
const cmd = positional[0];
|
|
45
|
+
const cwd = path.resolve(flags.dir ?? process.cwd());
|
|
46
|
+
if (!cmd && flags.version) return console.log(pkgVersion());
|
|
47
|
+
if (!cmd && flags.help) return console.log(HELP);
|
|
48
|
+
switch (cmd) {
|
|
49
|
+
case 'init':
|
|
50
|
+
return init(cwd, flags);
|
|
51
|
+
case 'update':
|
|
52
|
+
return update(cwd, flags);
|
|
53
|
+
case 'check':
|
|
54
|
+
return check(cwd);
|
|
55
|
+
case 'audit-secrets':
|
|
56
|
+
return auditSecrets(cwd, positional.slice(1));
|
|
57
|
+
case 'github-setup':
|
|
58
|
+
return githubSetup(cwd);
|
|
59
|
+
case '--version':
|
|
60
|
+
case '-v':
|
|
61
|
+
return console.log(pkgVersion());
|
|
62
|
+
default:
|
|
63
|
+
console.log(HELP);
|
|
64
|
+
if (cmd && cmd !== 'help' && cmd !== '--help') process.exitCode = 1;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// ---------------------------------------------------------------------------------------
|
|
69
|
+
async function ensurePackageJson(cwd, flags) {
|
|
70
|
+
const file = path.join(cwd, 'package.json');
|
|
71
|
+
if (existsSync(file)) return true;
|
|
72
|
+
if (flags['no-package-json']) return false;
|
|
73
|
+
const name = path.basename(cwd).toLowerCase().replace(/[^a-z0-9-]/g, '-');
|
|
74
|
+
await writeFile(file, JSON.stringify({ name: `${name}-tooling`, private: true, description: 'Dev tooling (specjig, OpenSpec)' }, null, 2) + '\n');
|
|
75
|
+
log.ok('created package.json (tooling only: OpenSpec and specjig are pinned here)');
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function installOpenspec(cwd, flags) {
|
|
80
|
+
const { package: pkg, version } = lock().openspec;
|
|
81
|
+
if (flags['skip-install']) return log.warn(`skipped installing ${pkg}@${version} (--skip-install)`);
|
|
82
|
+
if (!(await ensurePackageJson(cwd, flags))) {
|
|
83
|
+
return log.warn(`no package.json: run OpenSpec as "npx -y ${pkg}@${version}"`);
|
|
84
|
+
}
|
|
85
|
+
const deps = readJson(path.join(cwd, 'package.json')).devDependencies ?? {};
|
|
86
|
+
if (deps[pkg] === version) return log.ok(`${pkg}@${version} already pinned`);
|
|
87
|
+
const pm = detectPackageManager(cwd);
|
|
88
|
+
run(pm, addDevDepArgs(pm, `${pkg}@${version}`), { cwd, quiet: true });
|
|
89
|
+
log.ok(`${pkg}@${version} pinned in devDependencies (${pm})`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function openspec(cwd, args) {
|
|
93
|
+
const { package: pkg, version } = lock().openspec;
|
|
94
|
+
const det = detectOpenspec(cwd);
|
|
95
|
+
if (det.bin) return run(det.bin, args, { cwd, quiet: true });
|
|
96
|
+
return run('npx', ['-y', `${pkg}@${version}`, ...args], { cwd, quiet: true });
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// `openspec init` flags differ between versions (e.g. --scope appeared after 2.0): only pass what this one knows.
|
|
100
|
+
function initArgs(cwd) {
|
|
101
|
+
let help = '';
|
|
102
|
+
try {
|
|
103
|
+
help = openspec(cwd, ['init', '--help']);
|
|
104
|
+
} catch {
|
|
105
|
+
/* fall back to the minimal flag set */
|
|
106
|
+
}
|
|
107
|
+
const args = ['init', '--tools', 'claude'];
|
|
108
|
+
if (help.includes('--scope')) args.push('--scope', 'project');
|
|
109
|
+
if (help.includes('--no-animation')) args.push('--no-animation');
|
|
110
|
+
return [...args, '.'];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Resolve the OpenSpec mode and set OpenSpec up accordingly. Returns the manifest entry. */
|
|
114
|
+
async function setupOpenspec(cwd, flags, { previous, isUpdate }) {
|
|
115
|
+
const det = detectOpenspec(cwd);
|
|
116
|
+
const mode = await chooseMode(det, { flag: flags.openspec, previous });
|
|
117
|
+
|
|
118
|
+
if (mode === 'install') {
|
|
119
|
+
await installOpenspec(cwd, flags);
|
|
120
|
+
if (!existsSync(path.join(cwd, 'openspec'))) {
|
|
121
|
+
openspec(cwd, initArgs(cwd));
|
|
122
|
+
log.ok('openspec init (Claude Code skills and /openspec-* commands)');
|
|
123
|
+
} else {
|
|
124
|
+
openspec(cwd, ['update', '.']);
|
|
125
|
+
log.ok(`OpenSpec instruction files refreshed (${lock().openspec.version})`);
|
|
126
|
+
}
|
|
127
|
+
return { mode, version: lock().openspec.version };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// existing: never install, bump or refresh the project's OpenSpec.
|
|
131
|
+
log.ok(`keeping the project's OpenSpec (${describe(det)}); the harness will not install or bump it`);
|
|
132
|
+
if (!det.initialized && !isUpdate) {
|
|
133
|
+
openspec(cwd, initArgs(cwd));
|
|
134
|
+
log.ok('openspec init with the project\'s OpenSpec');
|
|
135
|
+
}
|
|
136
|
+
const warning = compatibilityWarning(det);
|
|
137
|
+
if (warning) log.warn(warning);
|
|
138
|
+
return { mode, version: ciVersion(mode, det) };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function checkSchema(cwd, openspecEntry) {
|
|
142
|
+
try {
|
|
143
|
+
openspec(cwd, ['schema', 'validate', 'sdd']);
|
|
144
|
+
log.ok('sdd schema loads with this OpenSpec');
|
|
145
|
+
} catch (e) {
|
|
146
|
+
log.warn(`sdd schema did not validate with this OpenSpec: ${e.message.split('\n').slice(-2).join(' ').trim()}`);
|
|
147
|
+
if (openspecEntry.mode === 'existing') log.warn('Upgrade the project\'s OpenSpec or rerun with --openspec=install.');
|
|
148
|
+
}
|
|
149
|
+
const cfg = path.join(cwd, 'openspec', 'config.yaml');
|
|
150
|
+
if (existsSync(cfg) && !/^schema:\s*sdd\s*$/m.test(readFileSync(cfg, 'utf8'))) {
|
|
151
|
+
log.info(` - openspec/config.yaml keeps its default schema. Use sdd per change ("openspec new change <id> --schema sdd")
|
|
152
|
+
or set "schema: sdd"; harness rules for config.yaml: ${path.join(PKG_ROOT, 'templates/openspec/config.yaml')}`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function setupGitHooks(cwd, flags) {
|
|
157
|
+
if (flags['no-git-hooks']) return;
|
|
158
|
+
if (!tryRun('git', ['rev-parse', '--is-inside-work-tree'], { cwd })) {
|
|
159
|
+
return log.warn('not a git repository: run "git init" and then "git config core.hooksPath .githooks"');
|
|
160
|
+
}
|
|
161
|
+
const current = tryRun('git', ['config', '--get', 'core.hooksPath'], { cwd });
|
|
162
|
+
if (current && current !== '.githooks') {
|
|
163
|
+
return log.warn(`core.hooksPath is "${current}" (husky?). Call .sdd/scripts/check-commit-msg.mjs from your commit-msg hook.`);
|
|
164
|
+
}
|
|
165
|
+
tryRun('git', ['config', 'core.hooksPath', '.githooks'], { cwd });
|
|
166
|
+
log.ok('git commit-msg hook enabled (core.hooksPath=.githooks)');
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async function init(cwd, flags) {
|
|
170
|
+
log.info(`specjig ${pkgVersion()} → ${cwd}`);
|
|
171
|
+
log.step('1. OpenSpec');
|
|
172
|
+
const manifestFile = path.join(cwd, '.sdd', 'manifest.json');
|
|
173
|
+
const previous = existsSync(manifestFile) ? readJson(manifestFile).openspec?.mode : undefined;
|
|
174
|
+
const openspecEntry = await setupOpenspec(cwd, flags, { previous, isUpdate: false });
|
|
175
|
+
|
|
176
|
+
log.step('2. Harness files');
|
|
177
|
+
printReport(await applyFiles(cwd, { openspec: openspecEntry }));
|
|
178
|
+
checkSchema(cwd, openspecEntry);
|
|
179
|
+
|
|
180
|
+
log.step('3. Git');
|
|
181
|
+
setupGitHooks(cwd, flags);
|
|
182
|
+
|
|
183
|
+
log.step('Next steps');
|
|
184
|
+
log.info(` 1. Fill the TODOs in AGENTS.md, openspec/config.yaml and .sdd/harness.json (layers, domain paths).
|
|
185
|
+
2. Validate the schema: npx openspec schema validate sdd
|
|
186
|
+
3. GitHub: add secret ANTHROPIC_API_KEY (and CONFLUENCE_* for the export), then: npx specjig github-setup
|
|
187
|
+
4. Commit everything except .env files. Start a change with /openspec-propose in Claude Code.`);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
async function update(cwd, flags) {
|
|
191
|
+
const manifestFile = path.join(cwd, '.sdd', 'manifest.json');
|
|
192
|
+
const before = existsSync(manifestFile) ? readJson(manifestFile) : null;
|
|
193
|
+
if (!before) throw new Error('No .sdd/manifest.json: run "specjig init" first.');
|
|
194
|
+
log.info(`specjig ${before.harnessVersion} → ${pkgVersion()}`);
|
|
195
|
+
|
|
196
|
+
log.step('1. OpenSpec');
|
|
197
|
+
// Manifests from 0.1.0 have no openspec.mode: the harness managed OpenSpec then.
|
|
198
|
+
const previous = before.openspec?.mode ?? 'install';
|
|
199
|
+
const openspecEntry = await setupOpenspec(cwd, flags, { previous, isUpdate: true });
|
|
200
|
+
|
|
201
|
+
log.step('2. Harness files');
|
|
202
|
+
printReport(await applyFiles(cwd, { isUpdate: true, openspec: openspecEntry }));
|
|
203
|
+
checkSchema(cwd, openspecEntry);
|
|
204
|
+
setupGitHooks(cwd, flags);
|
|
205
|
+
log.info('\nReview with "git diff", run "npx openspec validate --all --strict", then commit with "Change-Id: none".');
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// ---------------------------------------------------------------------------------------
|
|
209
|
+
async function check(cwd) {
|
|
210
|
+
const l = lock();
|
|
211
|
+
const manifestFile = path.join(cwd, '.sdd', 'manifest.json');
|
|
212
|
+
const installed = existsSync(manifestFile) ? readJson(manifestFile) : null;
|
|
213
|
+
const latestHarness = tryRun('npm', ['view', pkgName(), 'version']);
|
|
214
|
+
const latestOpenspec = tryRun('npm', ['view', l.openspec.package, 'dist-tags.latest']);
|
|
215
|
+
const projectOpenspec = detectOpenspec(cwd).version;
|
|
216
|
+
|
|
217
|
+
const row = (name, inProject, pinned, latest) =>
|
|
218
|
+
console.log(`${name.padEnd(26)} ${String(inProject ?? '-').padEnd(12)} ${String(pinned ?? '-').padEnd(12)} ${latest ?? '?'}${latest && pinned && latest !== pinned ? ' ← newer available' : ''}`);
|
|
219
|
+
console.log(`${'component'.padEnd(26)} ${'project'.padEnd(12)} ${'pinned'.padEnd(12)} latest`);
|
|
220
|
+
row(pkgName(), installed?.harnessVersion, pkgVersion(), latestHarness);
|
|
221
|
+
const mode = installed?.openspec?.mode ?? 'install';
|
|
222
|
+
row(l.openspec.package, projectOpenspec, mode === 'existing' ? '(project)' : l.openspec.version, latestOpenspec);
|
|
223
|
+
for (const s of l.skills) row(`skill:${s.dest}`, null, s.sha.slice(0, 7), null);
|
|
224
|
+
console.log(`\nSkills are pinned per harness release. Harness maintainers bump them with "npm run vendor:update".`);
|
|
225
|
+
console.log(`OpenSpec mode: ${mode}${mode === 'existing' ? ' (project-owned; the harness never installs or bumps it)' : ''}`);
|
|
226
|
+
if (installed && installed.harnessVersion !== pkgVersion()) console.log('Project is behind this harness version: run "npx specjig update".');
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// ---------------------------------------------------------------------------------------
|
|
230
|
+
async function auditSecrets(cwd, extraPaths) {
|
|
231
|
+
const { findSecrets, mask } = await import(path.join(PKG_ROOT, 'templates/.claude/hooks/sdd-lib/patterns.mjs'));
|
|
232
|
+
const encoded = cwd.replace(/[^a-zA-Z0-9]/g, '-');
|
|
233
|
+
const transcripts = path.join(os.homedir(), '.claude', 'projects', encoded);
|
|
234
|
+
const targets = [];
|
|
235
|
+
if (existsSync(transcripts)) {
|
|
236
|
+
for (const f of await readdir(transcripts)) if (f.endsWith('.jsonl')) targets.push(path.join(transcripts, f));
|
|
237
|
+
} else log.warn(`no Claude transcripts at ${transcripts}`);
|
|
238
|
+
targets.push(...extraPaths.map((p) => path.resolve(cwd, p)));
|
|
239
|
+
|
|
240
|
+
let total = 0;
|
|
241
|
+
for (const file of targets) {
|
|
242
|
+
if (!existsSync(file)) continue;
|
|
243
|
+
const lines = (await readFile(file, 'utf8')).split('\n');
|
|
244
|
+
lines.forEach((line, i) => {
|
|
245
|
+
for (const hit of findSecrets(line)) {
|
|
246
|
+
total++;
|
|
247
|
+
console.log(`${file}:${i + 1} ${hit.name} ${mask(hit.match)}`);
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
log.info(`\nScanned ${targets.length} file(s): ${total} finding(s).`);
|
|
252
|
+
if (total) {
|
|
253
|
+
log.info('Rotate every real secret found, then delete or redact the affected transcript files.');
|
|
254
|
+
process.exitCode = 1;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// ---------------------------------------------------------------------------------------
|
|
259
|
+
const LABELS = [
|
|
260
|
+
['low-risk', '0e8a16', 'Change is low risk: skips drift warning and spec challenge'],
|
|
261
|
+
['ai-review', '5319e7', 'Run the spec-aware AI review on this PR'],
|
|
262
|
+
['security-review', 'b60205', 'Run the AI security review on this PR'],
|
|
263
|
+
['ai-triage', 'fbca04', 'Let the CI triage agent classify failures and open fix PRs'],
|
|
264
|
+
['ai-fix', 'c5def5', 'Fix PR opened by the CI triage agent'],
|
|
265
|
+
];
|
|
266
|
+
|
|
267
|
+
async function githubSetup(cwd) {
|
|
268
|
+
if (!tryRun('gh', ['auth', 'status'])) throw new Error('gh is not authenticated: run "gh auth login".');
|
|
269
|
+
for (const [name, color, description] of LABELS) {
|
|
270
|
+
run('gh', ['label', 'create', name, '--color', color, '--description', description, '--force'], { cwd, quiet: true });
|
|
271
|
+
log.ok(`label ${name}`);
|
|
272
|
+
}
|
|
273
|
+
const secrets = tryRun('gh', ['secret', 'list'], { cwd }) ?? '';
|
|
274
|
+
for (const s of ['ANTHROPIC_API_KEY']) {
|
|
275
|
+
if (!secrets.includes(s)) log.warn(`repository secret ${s} is missing: gh secret set ${s}`);
|
|
276
|
+
}
|
|
277
|
+
log.info('\nEnable "Allow auto-merge" in repo settings so low-risk fix PRs can merge after green CI.');
|
|
278
|
+
}
|