specjig 0.0.0-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 +106 -2
- package/bin/specjig.mjs +7 -0
- package/harness.lock.json +61 -0
- package/package.json +54 -4
- 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
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// Managed by specjig. Shared by the Claude Code hooks, the git hooks and `specjig audit-secrets`.
|
|
2
|
+
// Project-specific additions go into .sdd/harness.json -> guard.extraSecretPaths (globs).
|
|
3
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
|
|
6
|
+
// Files whose basename marks them as secret-bearing. Templates like .env.example stay readable.
|
|
7
|
+
const SECRET_BASENAME = [
|
|
8
|
+
/^\.env$/i,
|
|
9
|
+
/^\.env\.(?!(example|sample|template|dist|defaults|schema)(\.|$))[\w.-]+$/i,
|
|
10
|
+
/^\.envrc$/i,
|
|
11
|
+
/^\.netrc$/i,
|
|
12
|
+
/^\.npmrc$/i,
|
|
13
|
+
/^\.pypirc$/i,
|
|
14
|
+
/^\.pgpass$/i,
|
|
15
|
+
/^credentials(\.json)?$/i,
|
|
16
|
+
/^secrets?\.(json|ya?ml|toml|env)$/i,
|
|
17
|
+
/^service[-_]?account.*\.json$/i,
|
|
18
|
+
/^id_(rsa|dsa|ecdsa|ed25519)(\.pub)?$/i,
|
|
19
|
+
/\.(pem|key|p12|pfx|jks|keystore|kdbx|asc|gpg)$/i,
|
|
20
|
+
// Database dumps and raw data exports.
|
|
21
|
+
/\.(dump|sql\.gz|sql\.bz2|bak|sqlite3?|db)$/i,
|
|
22
|
+
/^dump.*\.sql$/i,
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
// Directories that hold secrets or real (non-synthetic) data.
|
|
26
|
+
const SECRET_DIR = /(^|\/)(\.ssh|\.aws|\.gnupg|\.docker|\.kube|secrets?|dumps?|backups?|data\/(real|prod|production|raw|pii|phi))(\/|$)/i;
|
|
27
|
+
|
|
28
|
+
const ALLOWED = [/\.example$/i, /\.sample$/i, /\.template$/i, /(^|\/)test\/fixtures\/certs\//i];
|
|
29
|
+
|
|
30
|
+
let extraGlobs = null;
|
|
31
|
+
function loadExtra(cwd) {
|
|
32
|
+
if (extraGlobs) return extraGlobs;
|
|
33
|
+
extraGlobs = [];
|
|
34
|
+
const cfg = path.join(cwd, '.sdd', 'harness.json');
|
|
35
|
+
if (existsSync(cfg)) {
|
|
36
|
+
try {
|
|
37
|
+
const json = JSON.parse(readFileSync(cfg, 'utf8'));
|
|
38
|
+
extraGlobs = (json.guard?.extraSecretPaths ?? []).map(globToRegExp);
|
|
39
|
+
} catch {
|
|
40
|
+
/* malformed config: fall back to built-ins */
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return extraGlobs;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function globToRegExp(glob) {
|
|
47
|
+
let re = '';
|
|
48
|
+
for (let i = 0; i < glob.length; i++) {
|
|
49
|
+
const c = glob[i];
|
|
50
|
+
if (c === '*' && glob[i + 1] === '*') {
|
|
51
|
+
re += '.*';
|
|
52
|
+
i++;
|
|
53
|
+
if (glob[i + 1] === '/') i++;
|
|
54
|
+
} else if (c === '*') re += '[^/]*';
|
|
55
|
+
else if (c === '?') re += '[^/]';
|
|
56
|
+
else re += c.replace(/[.+^${}()|[\]\\]/g, '\\$&');
|
|
57
|
+
}
|
|
58
|
+
return new RegExp(`(^|/)${re}$`, 'i');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Returns a reason string if `p` points at a protected file, else null. */
|
|
62
|
+
export function protectedPath(p, cwd = process.cwd()) {
|
|
63
|
+
if (!p || typeof p !== 'string') return null;
|
|
64
|
+
const norm = p.replace(/\\/g, '/').replace(/^["']|["']$/g, '');
|
|
65
|
+
const rel = path.isAbsolute(norm) ? path.relative(cwd, norm).replace(/\\/g, '/') : norm.replace(/^\.\//, '');
|
|
66
|
+
if (ALLOWED.some((r) => r.test(rel))) return null;
|
|
67
|
+
const base = rel.split('/').pop();
|
|
68
|
+
if (SECRET_BASENAME.some((r) => r.test(base))) return `"${base}" is a secret-bearing or raw-data file`;
|
|
69
|
+
if (SECRET_DIR.test(rel)) return `"${rel}" is inside a directory reserved for secrets or real data`;
|
|
70
|
+
if (loadExtra(cwd).some((r) => r.test(rel))) return `"${rel}" matches guard.extraSecretPaths in .sdd/harness.json`;
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Shell commands that dump the process environment (where CI and dev shells keep tokens).
|
|
75
|
+
const ENV_DUMP = [
|
|
76
|
+
/(^|[;&|(]\s*)(printenv|env)\s*($|[;&|)>])/,
|
|
77
|
+
/(^|[;&|(]\s*)export\s+-p\b/,
|
|
78
|
+
/(^|[;&|(]\s*)(declare|typeset)\s+-x?p\b/,
|
|
79
|
+
/\/proc\/[^\s/]+\/environ/,
|
|
80
|
+
/\bdocker\s+(inspect|exec\b.*\benv\b)/,
|
|
81
|
+
/\bgh\s+auth\s+token\b/,
|
|
82
|
+
/\bgit\s+config\b.*\bcredential/,
|
|
83
|
+
/\bsecurity\s+find-(generic|internet)-password\b/,
|
|
84
|
+
];
|
|
85
|
+
|
|
86
|
+
/** Returns a reason string if a shell command would read a protected file or dump secrets. */
|
|
87
|
+
export function protectedCommand(cmd, cwd = process.cwd()) {
|
|
88
|
+
if (!cmd || typeof cmd !== 'string') return null;
|
|
89
|
+
for (const r of ENV_DUMP) if (r.test(cmd)) return 'the command would print environment variables or stored credentials';
|
|
90
|
+
// Split on shell syntax and check every word that looks like a path (also `rev:path` and `<file`).
|
|
91
|
+
const words = cmd.split(/[\s;&|()<>`'"=]+/).flatMap((w) => [w, ...(w.includes(':') ? [w.split(':').pop()] : [])]);
|
|
92
|
+
for (const w of words) {
|
|
93
|
+
if (!w || w.startsWith('-')) continue;
|
|
94
|
+
const reason = protectedPath(w, cwd);
|
|
95
|
+
if (reason) return reason;
|
|
96
|
+
}
|
|
97
|
+
// Globs that would expand to env files, e.g. `cat .env*` or `cat .e?v`.
|
|
98
|
+
if (/(^|[\s/])\.e[\w?*[\]]*[*?[]/.test(cmd) || /(^|[\s/])\.env\*/.test(cmd)) {
|
|
99
|
+
return 'the command uses a glob that can expand to .env files';
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// High-signal secret formats. Used for prompts, transcripts and logs (not for file paths).
|
|
105
|
+
export const SECRET_PATTERNS = [
|
|
106
|
+
['AWS access key', /\b(AKIA|ASIA)[0-9A-Z]{16}\b/],
|
|
107
|
+
['GitHub token', /\b(gh[pousr]_[A-Za-z0-9]{36,}|github_pat_[A-Za-z0-9_]{60,})\b/],
|
|
108
|
+
['Anthropic API key', /\bsk-ant-[A-Za-z0-9_-]{20,}/],
|
|
109
|
+
['OpenAI API key', /\bsk-(proj-)?[A-Za-z0-9]{32,}\b/],
|
|
110
|
+
['Slack token', /\bxox[abprs]-[A-Za-z0-9-]{10,}/],
|
|
111
|
+
['Stripe live key', /\b[rs]k_live_[A-Za-z0-9]{20,}/],
|
|
112
|
+
['Google API key', /\bAIza[0-9A-Za-z_-]{35}\b/],
|
|
113
|
+
['Atlassian API token', /\bATATT3[A-Za-z0-9_=-]{20,}/],
|
|
114
|
+
['Private key block', /-----BEGIN (RSA |EC |OPENSSH |DSA |PGP )?PRIVATE KEY( BLOCK)?-----/],
|
|
115
|
+
['JWT', /\beyJ[A-Za-z0-9_-]{10,}\.eyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}/],
|
|
116
|
+
['Connection string with password', /\b[a-z][a-z0-9+.-]*:\/\/[^\s:/@]+:[^\s@/]{6,}@[^\s]+/i],
|
|
117
|
+
];
|
|
118
|
+
|
|
119
|
+
/** Returns [{name, match}] for every secret-like string in `text`. */
|
|
120
|
+
export function findSecrets(text) {
|
|
121
|
+
const hits = [];
|
|
122
|
+
if (!text) return hits;
|
|
123
|
+
for (const [name, re] of SECRET_PATTERNS) {
|
|
124
|
+
const g = new RegExp(re.source, re.flags.includes('g') ? re.flags : re.flags + 'g');
|
|
125
|
+
for (const m of text.matchAll(g)) hits.push({ name, match: m[0], index: m.index });
|
|
126
|
+
}
|
|
127
|
+
return hits;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export const mask = (s) => (s.length <= 8 ? '****' : `${s.slice(0, 4)}…${s.slice(-2)} (${s.length} chars)`);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Managed by specjig. UserPromptSubmit guard: a prompt that contains something shaped like a
|
|
3
|
+
// secret is rejected before it reaches the model, the transcript or the session history.
|
|
4
|
+
import { findSecrets } from './sdd-lib/patterns.mjs';
|
|
5
|
+
import { readHookInput } from './sdd-lib/io.mjs';
|
|
6
|
+
|
|
7
|
+
const input = await readHookInput();
|
|
8
|
+
const hits = findSecrets(input.prompt ?? '');
|
|
9
|
+
if (hits.length) {
|
|
10
|
+
const kinds = [...new Set(hits.map((h) => h.name))].join(', ');
|
|
11
|
+
process.stderr.write(
|
|
12
|
+
`[specjig] Prompt rejected: it looks like it contains a secret (${kinds}). ` +
|
|
13
|
+
'Remove it and reference the variable name instead (e.g. $STRIPE_KEY). Rotate the secret if it was real.\n',
|
|
14
|
+
);
|
|
15
|
+
process.exit(2);
|
|
16
|
+
}
|
|
17
|
+
process.exit(0);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Managed by specjig. PreToolUse guard: the agent never reads, greps, globs, edits or
|
|
3
|
+
// shell-accesses secret-bearing files (.env, keys, credentials, DB dumps, real-data folders),
|
|
4
|
+
// and never dumps the environment. Complements permissions.deny in .claude/settings.json:
|
|
5
|
+
// deny rules cover exact paths, this hook covers variants (nested paths, globs, `git show :.env`).
|
|
6
|
+
import { protectedCommand, protectedPath } from './sdd-lib/patterns.mjs';
|
|
7
|
+
import { block, projectDir, readHookInput } from './sdd-lib/io.mjs';
|
|
8
|
+
|
|
9
|
+
const input = await readHookInput();
|
|
10
|
+
const cwd = projectDir(input);
|
|
11
|
+
const t = input.tool_input ?? {};
|
|
12
|
+
|
|
13
|
+
const pathFields = [t.file_path, t.path, t.notebook_path].filter(Boolean);
|
|
14
|
+
for (const p of pathFields) {
|
|
15
|
+
const reason = protectedPath(p, cwd);
|
|
16
|
+
if (reason) block(`${reason}. Secrets stay out of the agent context. Ask the human for the *names* of the variables you need, or read .env.example.`);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Glob / Grep patterns that target secret files, e.g. "**/.env*" or glob: "*.pem".
|
|
20
|
+
for (const pattern of [t.pattern, t.glob].filter(Boolean)) {
|
|
21
|
+
if (input.tool_name === 'Grep' && pattern === t.pattern) continue; // Grep's pattern is a regex over content
|
|
22
|
+
if (/\.env(?![\w.-]*\.(example|sample|template))/i.test(pattern) || /\.(pem|key|p12|pfx)\b/i.test(pattern)) {
|
|
23
|
+
block(`the pattern "${pattern}" targets secret-bearing files.`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (input.tool_name === 'Bash') {
|
|
28
|
+
const reason = protectedCommand(t.command, cwd);
|
|
29
|
+
if (reason) block(`${reason}. If a command genuinely needs secrets, the human runs it outside the agent session.`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
process.exit(0);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
paths:
|
|
3
|
+
- "openspec/**"
|
|
4
|
+
---
|
|
5
|
+
<!-- Managed by specjig. -->
|
|
6
|
+
# Working in openspec/
|
|
7
|
+
|
|
8
|
+
- `openspec/specs/` is the current truth. Never edit it by hand except a capability's `## Purpose`;
|
|
9
|
+
everything else changes through a change and `openspec archive`.
|
|
10
|
+
- `openspec/changes/archive/` is history. Never edit archived changes.
|
|
11
|
+
- Use the `sdd` schema: proposal → specs → (challenge) → impact → tests → design → tasks.
|
|
12
|
+
- After editing a change, run `npx openspec validate <change-id> --strict` and fix every issue.
|
|
13
|
+
- Requirements use SHALL/MUST; each has at least one `#### Scenario:` with WHEN and THEN.
|
|
14
|
+
- No PII/PHI and no secrets in specs, examples or scenarios; use synthetic values.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<!-- Managed by specjig. Project additions go into .claude/rules/security.local.md -->
|
|
2
|
+
# Security rules
|
|
3
|
+
|
|
4
|
+
Applied when writing design, code and reviews. `/security-review` checks the diff; these rules
|
|
5
|
+
add what it does not know about this project's domain.
|
|
6
|
+
|
|
7
|
+
## PII / PHI
|
|
8
|
+
|
|
9
|
+
- Never log request bodies, headers, tokens, emails, phone numbers, names, addresses, birth
|
|
10
|
+
dates, government IDs, medical data or free-text user input. Log stable internal IDs instead.
|
|
11
|
+
- No PII/PHI in URLs (path or query): URLs end up in access logs, browser history and Referer.
|
|
12
|
+
Use POST bodies or opaque IDs.
|
|
13
|
+
- Error messages and exceptions returned to clients carry no PII and no stack traces.
|
|
14
|
+
- Analytics, traces and metrics labels carry no PII.
|
|
15
|
+
|
|
16
|
+
## Auth
|
|
17
|
+
|
|
18
|
+
- Every new endpoint, job and message handler states who may call it; deny by default.
|
|
19
|
+
- Authorization is checked on the server, per resource, not only per route.
|
|
20
|
+
- Tokens and session IDs never appear in logs, URLs or error messages.
|
|
21
|
+
|
|
22
|
+
## Tenant isolation
|
|
23
|
+
|
|
24
|
+
- Every query on tenant-owned data is scoped by tenant, enforced in the data-access layer,
|
|
25
|
+
not left to callers. A test proves tenant A cannot read or modify tenant B's records.
|
|
26
|
+
- Caches, queues, file storage keys and search indexes include the tenant.
|
|
27
|
+
|
|
28
|
+
## In design.md
|
|
29
|
+
|
|
30
|
+
High-risk changes have a **Security** section: data classification touched, authn/authz
|
|
31
|
+
changes, tenant boundary, logging of new fields, and how each is tested.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
---
|
|
2
|
+
paths:
|
|
3
|
+
- "**/*test*/**"
|
|
4
|
+
- "**/*.test.*"
|
|
5
|
+
- "**/*.spec.*"
|
|
6
|
+
- "**/*_test.*"
|
|
7
|
+
- "**/test_*.*"
|
|
8
|
+
- "**/fixtures/**"
|
|
9
|
+
- "**/seeds/**"
|
|
10
|
+
- "**/factories/**"
|
|
11
|
+
- "e2e/**"
|
|
12
|
+
---
|
|
13
|
+
<!-- Managed by specjig. -->
|
|
14
|
+
# Test data rules
|
|
15
|
+
|
|
16
|
+
- Synthetic data only. Generate fixtures with factories or a seeded faker (fixed seed, so runs
|
|
17
|
+
are reproducible). Never copy records from production, staging, dumps or support tickets.
|
|
18
|
+
- Use reserved values: emails `@example.com`, phones from the fictional ranges, IPs from
|
|
19
|
+
192.0.2.0/24, card numbers from the payment provider's published test set.
|
|
20
|
+
- No real secrets in tests. Use obviously fake values (`test-key-not-secret`) and inject via
|
|
21
|
+
config, so production keys can never be picked up by a test run.
|
|
22
|
+
- Tests map to scenarios in the change's `tests.md`; name tests after the scenario they cover.
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/claude-code-settings.json",
|
|
3
|
+
"permissions": {
|
|
4
|
+
"deny": [
|
|
5
|
+
"Read(./.env)",
|
|
6
|
+
"Read(./.env.local)",
|
|
7
|
+
"Read(./.env.*.local)",
|
|
8
|
+
"Read(./.env.development)",
|
|
9
|
+
"Read(./.env.production)",
|
|
10
|
+
"Read(./.env.staging)",
|
|
11
|
+
"Read(./.env.test)",
|
|
12
|
+
"Read(**/.env)",
|
|
13
|
+
"Read(**/.envrc)",
|
|
14
|
+
"Read(**/.npmrc)",
|
|
15
|
+
"Read(**/.netrc)",
|
|
16
|
+
"Read(**/.pgpass)",
|
|
17
|
+
"Read(**/*.pem)",
|
|
18
|
+
"Read(**/*.key)",
|
|
19
|
+
"Read(**/*.p12)",
|
|
20
|
+
"Read(**/*.pfx)",
|
|
21
|
+
"Read(**/id_rsa*)",
|
|
22
|
+
"Read(**/id_ed25519*)",
|
|
23
|
+
"Read(**/credentials.json)",
|
|
24
|
+
"Read(**/service-account*.json)",
|
|
25
|
+
"Read(**/secrets/**)",
|
|
26
|
+
"Read(**/*.dump)",
|
|
27
|
+
"Read(**/*.sql.gz)",
|
|
28
|
+
"Read(**/dumps/**)",
|
|
29
|
+
"Read(**/backups/**)",
|
|
30
|
+
"Read(**/data/real/**)",
|
|
31
|
+
"Read(**/data/prod/**)",
|
|
32
|
+
"Read(**/data/pii/**)",
|
|
33
|
+
"Read(**/data/phi/**)",
|
|
34
|
+
"Read(~/.ssh/**)",
|
|
35
|
+
"Read(~/.aws/**)",
|
|
36
|
+
"Read(~/.config/gh/**)",
|
|
37
|
+
"Edit(./.env)",
|
|
38
|
+
"Edit(**/.env)",
|
|
39
|
+
"Edit(**/*.pem)",
|
|
40
|
+
"Edit(**/*.key)",
|
|
41
|
+
"Edit(**/secrets/**)",
|
|
42
|
+
"Bash(printenv *)",
|
|
43
|
+
"Bash(gh auth token *)",
|
|
44
|
+
"Bash(git push --force *)",
|
|
45
|
+
"Bash(git push -f *)"
|
|
46
|
+
],
|
|
47
|
+
"ask": [
|
|
48
|
+
"Bash(git push *)",
|
|
49
|
+
"Bash(gh pr merge *)",
|
|
50
|
+
"Bash(npm publish *)",
|
|
51
|
+
"Bash(pnpm publish *)"
|
|
52
|
+
],
|
|
53
|
+
"allow": [
|
|
54
|
+
"Bash(npx openspec *)",
|
|
55
|
+
"Bash(openspec *)",
|
|
56
|
+
"Bash(git status *)",
|
|
57
|
+
"Bash(git diff *)",
|
|
58
|
+
"Bash(git log *)",
|
|
59
|
+
"Bash(git blame *)",
|
|
60
|
+
"Bash(git show *)"
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
"sandbox": {
|
|
64
|
+
"filesystem": {
|
|
65
|
+
"denyRead": ["~/.ssh", "~/.aws", "~/.config/gh", "~/.docker/config.json", "~/.kube"]
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"hooks": {
|
|
69
|
+
"UserPromptSubmit": [
|
|
70
|
+
{
|
|
71
|
+
"hooks": [
|
|
72
|
+
{ "type": "command", "command": "node \"$CLAUDE_PROJECT_DIR/.claude/hooks/sdd-prompt-guard.mjs\"", "timeout": 10 }
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
],
|
|
76
|
+
"PreToolUse": [
|
|
77
|
+
{
|
|
78
|
+
"matcher": "Read|Edit|MultiEdit|Write|NotebookEdit|Grep|Glob|LS|Bash",
|
|
79
|
+
"hooks": [
|
|
80
|
+
{ "type": "command", "command": "node \"$CLAUDE_PROJECT_DIR/.claude/hooks/sdd-protect-secrets.mjs\"", "timeout": 10, "onFailure": "block" }
|
|
81
|
+
]
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"matcher": "Edit|MultiEdit|Write|NotebookEdit|Bash",
|
|
85
|
+
"hooks": [
|
|
86
|
+
{ "type": "command", "command": "node \"$CLAUDE_PROJECT_DIR/.claude/hooks/sdd-fix-mode-guard.mjs\"", "timeout": 10, "onFailure": "block" }
|
|
87
|
+
]
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"matcher": "Bash",
|
|
91
|
+
"hooks": [
|
|
92
|
+
{ "type": "command", "command": "node \"$CLAUDE_PROJECT_DIR/.claude/hooks/sdd-commit-guard.mjs\"", "timeout": 10 }
|
|
93
|
+
]
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: change-pr
|
|
3
|
+
description: Open a GitHub pull request for an OpenSpec change with Change-Id trailers on every commit and links to the change, its specs and tests in the description. Use when the user asks to open, create or prepare a PR for a change.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# PR for a change
|
|
7
|
+
|
|
8
|
+
Thin wrapper over `gh pr create` that makes the PR traceable to its OpenSpec change.
|
|
9
|
+
|
|
10
|
+
## 1. Identify the change
|
|
11
|
+
|
|
12
|
+
The change id is the folder name under `openspec/changes/`. Take it from the user, from the
|
|
13
|
+
`Change-Id` trailers on the branch, or from the only active change. If several are possible, ask.
|
|
14
|
+
|
|
15
|
+
## 2. Check the commits
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
git log --format='%h %s%n%(trailers:key=Change-Id,valueonly)' origin/HEAD..HEAD
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Every commit needs `Change-Id: <id>` (or `none` for non-behavioral commits). If one is
|
|
22
|
+
missing, tell the human and propose `git rebase -x` / an amend; do not rewrite pushed history
|
|
23
|
+
without approval.
|
|
24
|
+
|
|
25
|
+
## 3. Check readiness
|
|
26
|
+
|
|
27
|
+
- `npx openspec validate <id> --strict` passes.
|
|
28
|
+
- All tasks in the layer(s) this PR covers are checked in `tasks.md`.
|
|
29
|
+
- Tests listed in `tests.md` for those tasks exist and pass.
|
|
30
|
+
- High risk: `challenge.md` exists and `/security-review` was run.
|
|
31
|
+
|
|
32
|
+
Report anything missing instead of opening the PR.
|
|
33
|
+
|
|
34
|
+
## 4. Create the PR
|
|
35
|
+
|
|
36
|
+
Title: `<type>(<capability>): <summary>`. Labels: `low-risk` when the proposal says
|
|
37
|
+
`Risk: low`; otherwise none (high risk is the default). Body:
|
|
38
|
+
|
|
39
|
+
```markdown
|
|
40
|
+
## Change
|
|
41
|
+
[`<id>`](openspec/changes/<id>/proposal.md) · Risk: <low|high> · Layer: <backend|frontend|all>
|
|
42
|
+
|
|
43
|
+
<Why, 1–3 sentences from proposal.md>
|
|
44
|
+
|
|
45
|
+
## Specs
|
|
46
|
+
- [`<capability>`](openspec/changes/<id>/specs/<capability>/spec.md): ADDED/MODIFIED requirements …
|
|
47
|
+
|
|
48
|
+
## Tests
|
|
49
|
+
<Scenario → test file mapping from tests.md for what this PR implements>
|
|
50
|
+
|
|
51
|
+
## Design
|
|
52
|
+
[design.md](openspec/changes/<id>/design.md) · [challenge.md](openspec/changes/<id>/challenge.md) (if present)
|
|
53
|
+
|
|
54
|
+
## Checklist
|
|
55
|
+
- [ ] `openspec validate --strict` green
|
|
56
|
+
- [ ] Every commit has `Change-Id: <id>`
|
|
57
|
+
- [ ] No PII/PHI or secrets in code, tests, logs, fixtures
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Use relative links: GitHub resolves them against the PR branch. Push and `gh pr create`
|
|
61
|
+
need the human's approval.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: spec-challenge
|
|
3
|
+
description: Challenge an OpenSpec change's proposal and delta specs in a clean context until ambiguities are closed (hidden assumptions, contradictions, edge cases, error behavior). Use for high-risk changes after the delta specs are written and before impact/design/tasks, or when the user says "challenge the spec" or "grill the change".
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Spec challenge
|
|
7
|
+
|
|
8
|
+
Step 4 of the change lifecycle. Skip for **low-risk** changes (proposal says `Risk: low`) unless
|
|
9
|
+
the user asks for it.
|
|
10
|
+
|
|
11
|
+
The challenger must not share the author's context: assumptions the author made silently are
|
|
12
|
+
exactly what this step exists to surface.
|
|
13
|
+
|
|
14
|
+
## 1. Run the challenge in a fresh subagent
|
|
15
|
+
|
|
16
|
+
Spawn a subagent with a **fresh context** (not a fork). Give it only:
|
|
17
|
+
|
|
18
|
+
- the paths `openspec/changes/<id>/proposal.md` and `openspec/changes/<id>/specs/**`,
|
|
19
|
+
- the paths of the main specs those deltas modify (`openspec/specs/<capability>/spec.md`),
|
|
20
|
+
- this brief:
|
|
21
|
+
|
|
22
|
+
> Use the `grilling` skill on this change. You are reviewing the proposal and delta specs, not
|
|
23
|
+
> the code. Build the design tree from what the specs leave undecided. Look specifically for:
|
|
24
|
+
> hidden assumptions; contradictions between requirements, or with the main specs; missing
|
|
25
|
+
> edge cases (empty, max size, concurrency, retries, time zones, partial failure); undefined
|
|
26
|
+
> error behavior; scenarios without a clear WHEN or THEN; requirements that cannot be tested;
|
|
27
|
+
> security and privacy gaps (PII/PHI, authz, tenant boundary).
|
|
28
|
+
> Look facts up in the repository yourself; ask only about decisions. Return every question with
|
|
29
|
+
> your recommended answer and the requirement/scenario it concerns.
|
|
30
|
+
|
|
31
|
+
## 2. Put the questions to the human
|
|
32
|
+
|
|
33
|
+
Relay the subagent's rounds to the human in the `grilling` format (numbered, each with a
|
|
34
|
+
recommended answer). Decisions are the human's. Keep going until the frontier is empty.
|
|
35
|
+
|
|
36
|
+
## 3. Resolve every finding
|
|
37
|
+
|
|
38
|
+
Each finding gets exactly one resolution:
|
|
39
|
+
|
|
40
|
+
| Resolution | When | Action |
|
|
41
|
+
|------------|------|--------|
|
|
42
|
+
| **Spec fix** | Requirement wrong, vague or contradictory | Edit the delta requirement |
|
|
43
|
+
| **New scenario** | Edge case or error behavior was missing | Add `#### Scenario:` (WHEN/THEN) |
|
|
44
|
+
| **Proposal fix** | Scope, motivation or risk level was wrong | Edit `proposal.md` (re-evaluate risk) |
|
|
45
|
+
| **Open question** | Answer is genuinely deferrable and changes neither specs, approach nor tasks | Add to `## Open questions` in `proposal.md` with an owner |
|
|
46
|
+
| **Out of scope** | Valid but belongs to another change | Note under Non-goals; create a follow-up change if needed |
|
|
47
|
+
| **Accepted risk** | Known gap the human accepts | Record in `challenge.md` with who accepted and why |
|
|
48
|
+
|
|
49
|
+
## 4. Record
|
|
50
|
+
|
|
51
|
+
Write `openspec/changes/<id>/challenge.md`:
|
|
52
|
+
|
|
53
|
+
```markdown
|
|
54
|
+
# Spec challenge: <id>
|
|
55
|
+
|
|
56
|
+
Date: YYYY-MM-DD · Rounds: N
|
|
57
|
+
|
|
58
|
+
| # | Finding | Concerns | Resolution | Outcome |
|
|
59
|
+
|---|---------|----------|------------|---------|
|
|
60
|
+
| 1 | Behavior on duplicate submit undefined | Req "Create order" | New scenario | "Duplicate submit returns existing order" |
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Then run `npx openspec validate <id> --strict` and continue with impact, tests and design.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: spec-compaction
|
|
3
|
+
description: Compact openspec/specs by removing requirements and scenarios that are outdated or fully expressed by tests, through a regular OpenSpec change. Use when specs have grown noisy, before a release, or when the user asks to compact, prune or clean up specs.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Spec compaction
|
|
7
|
+
|
|
8
|
+
Specs are a contract for humans and agents, not a second copy of the test suite. Compaction keeps
|
|
9
|
+
what explains **behavior and intent** and drops what only restates detail already pinned by tests.
|
|
10
|
+
|
|
11
|
+
Compaction is itself a change: never edit `openspec/specs/` directly.
|
|
12
|
+
|
|
13
|
+
## Keep
|
|
14
|
+
|
|
15
|
+
- Requirements that state **observable behavior or intent** (why the system does it), even if tested.
|
|
16
|
+
- Security, privacy, compliance and tenant-isolation requirements, always.
|
|
17
|
+
- Error behavior and edge cases that were decided deliberately (look for them in archived
|
|
18
|
+
`challenge.md` / `design.md`).
|
|
19
|
+
- Anything a stakeholder reads in the Confluence export.
|
|
20
|
+
|
|
21
|
+
## Remove or merge
|
|
22
|
+
|
|
23
|
+
- **Outdated:** the requirement no longer matches the code and no active change restores it.
|
|
24
|
+
Confirm with `trace-why` and the tests; if behavior silently drifted, that is a bug or a missing
|
|
25
|
+
change, so report it, do not compact it away.
|
|
26
|
+
- **Duplicated:** the same behavior stated in two capabilities → keep it in the owning one.
|
|
27
|
+
- **Test-restating scenarios:** a scenario that only enumerates input/output values already
|
|
28
|
+
covered one-to-one by a named test → replace the enumeration with one representative scenario
|
|
29
|
+
plus a reference to the test file.
|
|
30
|
+
- **Implementation detail:** class names, libraries, internal steps → remove (belongs in design or code).
|
|
31
|
+
|
|
32
|
+
## Process
|
|
33
|
+
|
|
34
|
+
1. Pick the capability(ies). Check no active change modifies them (`npx openspec list`); if one
|
|
35
|
+
does, compact after it is archived.
|
|
36
|
+
2. For each requirement, collect evidence: tests that cover its scenarios (grep for scenario
|
|
37
|
+
names / behaviors), the change that introduced it (`trace-why`), current code behavior.
|
|
38
|
+
3. Draft a table for the human: requirement → keep / remove / merge / shorten, with evidence.
|
|
39
|
+
Wait for approval; removal of a requirement is a product decision.
|
|
40
|
+
4. Create change `compact-<capability>` (`skip_specs` is **not** set): use `## REMOVED Requirements`
|
|
41
|
+
with **Reason** and **Migration** ("covered by `<test path>`" or "obsolete since `<change>`"),
|
|
42
|
+
and `## MODIFIED Requirements` for shortened ones (full block, per OpenSpec rules).
|
|
43
|
+
Risk: low unless a security requirement is touched.
|
|
44
|
+
5. `npx openspec validate compact-<capability> --strict`, PR via `change-pr`, archive after merge.
|
|
45
|
+
|
|
46
|
+
Prior art checked: `sdd-spec-gc` (fearovex/claude-config) and `spec-compact` (kevinlin) cover
|
|
47
|
+
staleness and duplication but not test coverage; this skill adds the test-evidence rule.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: trace-why
|
|
3
|
+
description: Explain why a line, function or behavior exists by following git blame → commit → Change-Id trailer → OpenSpec change (proposal, design, specs). Use when code is unclear, looks wrong or redundant, before deleting or "simplifying" something, or when the user asks "why is this here".
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Trace why
|
|
7
|
+
|
|
8
|
+
Do not guess intent from code. Follow the chain and quote what was decided.
|
|
9
|
+
|
|
10
|
+
1. **Blame the line(s).** Ignore pure formatting and move commits:
|
|
11
|
+
```bash
|
|
12
|
+
git blame -w -C -C -L <start>,<end> --porcelain <file>
|
|
13
|
+
```
|
|
14
|
+
If the last commit is a refactor/format commit (`Change-Id: none`), blame its parent:
|
|
15
|
+
`git blame <sha>^ -L … <file>` and repeat until you reach a commit with a real Change-Id.
|
|
16
|
+
2. **Read the trailer.**
|
|
17
|
+
```bash
|
|
18
|
+
git log -1 --format='%H%n%s%n%(trailers:key=Change-Id,valueonly)' <sha>
|
|
19
|
+
```
|
|
20
|
+
3. **Open the change.** `openspec/changes/<id>/` if still active, else
|
|
21
|
+
`openspec/changes/archive/*-<id>/`. Read `proposal.md` (why), `design.md` (how,
|
|
22
|
+
alternatives rejected), `challenge.md` (edge cases decided), `tests.md` and the delta specs.
|
|
23
|
+
4. **Check the current contract.** `npx openspec show <capability> --type spec` shows the
|
|
24
|
+
requirement as it stands today (later changes may have modified it).
|
|
25
|
+
5. **Answer** with: the requirement or decision that explains the line, links to the files,
|
|
26
|
+
and whether the current code still matches it. If the trail breaks (no trailer, change
|
|
27
|
+
missing), say so explicitly and only then fall back to reading surrounding code and tests.
|
|
28
|
+
|
|
29
|
+
Search locally before asking a human or a tracker:
|
|
30
|
+
`grep -rn "<term>" openspec/specs openspec/changes`.
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Managed by specjig. When CI fails on a PR labelled `ai-triage`, an agent classifies the
|
|
2
|
+
# cause. For lint / format / types / dependencies it opens a separate fix PR (labels ai-fix,
|
|
3
|
+
# low-risk) into the PR branch; anything else gets a classification comment for a human.
|
|
4
|
+
# Guardrails: SDD_MODE=fix freezes tests and openspec/ (hook), sdd-fix-pr-guard re-checks the
|
|
5
|
+
# diff, --max-turns caps cost.
|
|
6
|
+
name: sdd / CI triage
|
|
7
|
+
on:
|
|
8
|
+
workflow_run:
|
|
9
|
+
workflows: ["CI"] # TODO: names of your CI workflows
|
|
10
|
+
types: [completed]
|
|
11
|
+
permissions:
|
|
12
|
+
contents: write
|
|
13
|
+
pull-requests: write
|
|
14
|
+
actions: read
|
|
15
|
+
id-token: write
|
|
16
|
+
jobs:
|
|
17
|
+
triage:
|
|
18
|
+
if: github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.event == 'pull_request'
|
|
19
|
+
runs-on: ubuntu-latest
|
|
20
|
+
timeout-minutes: 30
|
|
21
|
+
steps:
|
|
22
|
+
- id: pr
|
|
23
|
+
env:
|
|
24
|
+
GH_TOKEN: ${{ github.token }}
|
|
25
|
+
HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
|
|
26
|
+
run: |
|
|
27
|
+
pr=$(gh pr list --repo "${{ github.repository }}" --head "$HEAD_BRANCH" --state open --json number,labels \
|
|
28
|
+
--jq '.[] | select(any(.labels[]; .name == "ai-triage")) | .number' | head -1)
|
|
29
|
+
echo "number=$pr" >> "$GITHUB_OUTPUT"
|
|
30
|
+
- if: steps.pr.outputs.number != ''
|
|
31
|
+
uses: actions/checkout@v4
|
|
32
|
+
with:
|
|
33
|
+
ref: ${{ github.event.workflow_run.head_branch }}
|
|
34
|
+
fetch-depth: 0
|
|
35
|
+
- if: steps.pr.outputs.number != ''
|
|
36
|
+
uses: anthropics/claude-code-action@{{CLAUDE_CODE_ACTION}}
|
|
37
|
+
env:
|
|
38
|
+
SDD_MODE: fix
|
|
39
|
+
with:
|
|
40
|
+
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
|
|
41
|
+
prompt: |
|
|
42
|
+
REPO: ${{ github.repository }} PR: #${{ steps.pr.outputs.number }}
|
|
43
|
+
Failed run: ${{ github.event.workflow_run.html_url }} (id ${{ github.event.workflow_run.id }})
|
|
44
|
+
Branch: ${{ github.event.workflow_run.head_branch }}
|
|
45
|
+
|
|
46
|
+
1. Read the failed job logs: `gh run view ${{ github.event.workflow_run.id }} --log-failed`.
|
|
47
|
+
2. Classify the cause as exactly one of: lint, format, types, dependencies, test-failure,
|
|
48
|
+
flaky, infrastructure, spec-mismatch, other.
|
|
49
|
+
3. If lint / format / types / dependencies:
|
|
50
|
+
- create branch `ai-fix/pr-${{ steps.pr.outputs.number }}-${{ github.event.workflow_run.id }}`,
|
|
51
|
+
- make the smallest fix; NEVER edit tests, snapshots, fixtures or openspec/ (a hook blocks it),
|
|
52
|
+
- run the failing command locally to confirm it passes,
|
|
53
|
+
- commit with trailer `Change-Id: none`, push the branch,
|
|
54
|
+
- open a PR into `${{ github.event.workflow_run.head_branch }}` with labels `ai-fix,low-risk`,
|
|
55
|
+
body: classification, root cause, the command that now passes.
|
|
56
|
+
4. Otherwise do not change code. Comment on PR #${{ steps.pr.outputs.number }}: classification,
|
|
57
|
+
evidence (log excerpt without secrets), suspected cause, suggested next step.
|
|
58
|
+
Stop after two failed attempts at the same fix and report instead.
|
|
59
|
+
claude_args: |
|
|
60
|
+
--max-turns 25
|
|
61
|
+
--allowedTools "Read,Edit,Write,Grep,Glob,Bash(gh run view:*),Bash(gh pr create:*),Bash(gh pr comment:*),Bash(git checkout:*),Bash(git switch:*),Bash(git add:*),Bash(git commit:*),Bash(git push:*),Bash(git diff:*),Bash(git status:*),Bash(npm:*),Bash(pnpm:*),Bash(npx:*),Bash(yarn:*)"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Managed by specjig. After a change is archived (specs/ updated on main), publish a read-only
|
|
2
|
+
# slice of openspec/specs/ to Confluence. Edits happen only through a new OpenSpec change.
|
|
3
|
+
name: sdd / confluence sync
|
|
4
|
+
on:
|
|
5
|
+
push:
|
|
6
|
+
branches: [main]
|
|
7
|
+
paths: ["openspec/specs/**"]
|
|
8
|
+
workflow_dispatch:
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
jobs:
|
|
12
|
+
sync:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
timeout-minutes: 10
|
|
15
|
+
env:
|
|
16
|
+
CONFLUENCE_BASE_URL: ${{ vars.CONFLUENCE_BASE_URL }}
|
|
17
|
+
CONFLUENCE_USER: ${{ vars.CONFLUENCE_USER }}
|
|
18
|
+
CONFLUENCE_TOKEN: ${{ secrets.CONFLUENCE_TOKEN }}
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v4
|
|
21
|
+
- if: env.CONFLUENCE_BASE_URL == '' || env.CONFLUENCE_TOKEN == ''
|
|
22
|
+
run: echo "::notice::Confluence sync not configured (vars.CONFLUENCE_BASE_URL, secrets.CONFLUENCE_TOKEN); skipping."
|
|
23
|
+
- if: env.CONFLUENCE_BASE_URL != '' && env.CONFLUENCE_TOKEN != ''
|
|
24
|
+
run: node .sdd/scripts/confluence-sync.mjs
|