@dzhechkov/p-replicator 1.2.0 → 1.5.2
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/README.md +55 -0
- package/bin/cli.js +0 -0
- package/package.json +10 -3
- package/src/cli.js +23 -6
- package/src/commands/doctor.js +46 -29
- package/src/commands/init.js +61 -8
- package/src/commands/list.js +5 -26
- package/src/commands/update.js +73 -7
- package/src/commands/verify.js +111 -0
- package/src/utils.js +275 -4
- package/templates/.claude/commands/deploy.md +100 -0
- package/templates/.claude/commands/docs.md +79 -0
- package/templates/.claude/commands/feature.md +134 -0
- package/templates/.claude/commands/go.md +115 -0
- package/templates/.claude/commands/myinsights.md +72 -0
- package/templates/.claude/commands/next.md +110 -0
- package/templates/.claude/commands/plan.md +88 -0
- package/templates/.claude/commands/replicate.md +103 -17
- package/templates/.claude/commands/run.md +151 -0
- package/templates/.claude/commands/start.md +88 -0
- package/templates/.claude/hooks/autocommit-insights.cjs +39 -0
- package/templates/.claude/hooks/autocommit-plans.cjs +39 -0
- package/templates/.claude/hooks/autocommit-roadmap.cjs +44 -0
- package/templates/.claude/hooks/session-insights.cjs +28 -0
- package/templates/.claude/hooks/state-update.cjs +79 -0
- package/templates/.claude/hooks/statusline.cjs +399 -0
- package/templates/.claude/rules/feature-lifecycle.md +145 -0
- package/templates/.claude/rules/git-workflow.md +74 -0
- package/templates/.claude/rules/insights-capture.md +77 -0
- package/templates/.claude/rules/replicate-pipeline.md +97 -20
- package/templates/.claude/settings.json +44 -0
- package/templates/.claude/skills/brutal-honesty-review/SKILL.md +43 -0
- package/templates/.claude/skills/brutal-honesty-review/scripts/assess-code.sh +0 -0
- package/templates/.claude/skills/brutal-honesty-review/scripts/assess-tests.sh +0 -0
- package/templates/.claude/skills/cc-toolkit-generator-enhanced/SKILL.md +8 -0
- package/templates/.claude/skills/cc-toolkit-generator-enhanced/modules/03-generate-p0.md +46 -0
- package/templates/.claude/skills/cc-toolkit-generator-enhanced/modules/04-generate-p1.md +9 -0
- package/templates/.claude/skills/cc-toolkit-generator-enhanced/modules/05-generate-p2p3.md +11 -0
- package/templates/.claude/skills/cc-toolkit-generator-enhanced/modules/06-package-deliver.md +46 -0
- package/templates/.claude/skills/cc-toolkit-generator-enhanced/references/security-patterns-library.md +196 -0
- package/templates/.claude/skills/cc-toolkit-generator-enhanced/references/templates/automation-commands.md +15 -0
- package/templates/.claude/skills/cc-toolkit-generator-enhanced/references/templates/ddd-agents.md +39 -0
- package/templates/.claude/skills/cc-toolkit-generator-enhanced/references/templates/feature-lifecycle.md +8 -0
- package/templates/.claude/skills/goap-research-ed25519/scripts/ed25519_verifier.py +0 -0
- package/templates/.claude/skills/goap-research-ed25519/scripts/goap_planner.py +0 -0
- package/templates/.claude/skills/requirements-validator/SKILL.md +25 -1
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
# Security Patterns Library
|
|
2
|
+
|
|
3
|
+
Reference library of security patterns extracted from real-project harvest insights.
|
|
4
|
+
Used by toolkit generator modules (03, 04, 05) when generating security.md rules,
|
|
5
|
+
secrets-management.md, security-patterns/ skill, and code-reviewer agent.
|
|
6
|
+
|
|
7
|
+
## Critical Patterns (Must-Have for Multi-Tenant Systems)
|
|
8
|
+
|
|
9
|
+
### S-01: RLS Bypass Prevention — Pool vs Client Query
|
|
10
|
+
|
|
11
|
+
**Problem:** Tenant middleware sets `app.tenant_id` via `SET LOCAL` on a dedicated
|
|
12
|
+
PoolClient (`req.dbClient`), but repositories use `pool.query()` (shared pool).
|
|
13
|
+
The query runs on a different connection without tenant context — RLS is bypassed.
|
|
14
|
+
|
|
15
|
+
**Pattern:**
|
|
16
|
+
```
|
|
17
|
+
RULE: NEVER use pool.query() in multi-tenant systems with RLS.
|
|
18
|
+
ALWAYS pass the tenant-scoped dbClient from middleware through service layer to repository.
|
|
19
|
+
Every database query MUST use the same connection where SET LOCAL was executed.
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**Detection:** Search for `pool.query()` in repository files when RLS is enabled.
|
|
23
|
+
|
|
24
|
+
**Generated Rule (security.md):**
|
|
25
|
+
```markdown
|
|
26
|
+
- Multi-tenant RLS: All database queries MUST use tenant-scoped connection (req.dbClient),
|
|
27
|
+
NEVER the shared pool. Verify by grepping for pool.query() — any hit is a security bug.
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
### S-02: SQL Injection via SET LOCAL
|
|
33
|
+
|
|
34
|
+
**Problem:** String interpolation in `SET LOCAL app.tenant_id = '${tenantId}'`
|
|
35
|
+
is an SQL injection vector even with UUID validation.
|
|
36
|
+
|
|
37
|
+
**Pattern:**
|
|
38
|
+
```
|
|
39
|
+
RULE: NEVER use string interpolation for SET LOCAL.
|
|
40
|
+
ALWAYS use parameterized set_config():
|
|
41
|
+
SELECT set_config('app.tenant_id', $1, true)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
**Detection:** Search for `SET LOCAL` with template literals or string concatenation.
|
|
45
|
+
|
|
46
|
+
**Generated Rule (security.md):**
|
|
47
|
+
```markdown
|
|
48
|
+
- Parameterized config: Use `set_config('key', $1, true)` instead of
|
|
49
|
+
`SET LOCAL key = '${value}'`. Applies to all session-level config.
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
### S-03: Fail-Fast Secret Validation at Startup
|
|
55
|
+
|
|
56
|
+
**Problem:** Service A falls back to `'dev-secret-change-me'` when JWT_SECRET is
|
|
57
|
+
missing, while Service B uses `process.env.JWT_SECRET!`. Creates split-brain:
|
|
58
|
+
signing uses weak fallback, verification uses undefined.
|
|
59
|
+
|
|
60
|
+
**Pattern:**
|
|
61
|
+
```
|
|
62
|
+
RULE: NEVER provide fallback values for security-critical secrets.
|
|
63
|
+
ALWAYS validate at startup and exit with process.exit(1) if missing or too short.
|
|
64
|
+
|
|
65
|
+
Required checks:
|
|
66
|
+
- JWT_SECRET: exists AND length >= 32 characters
|
|
67
|
+
- DATABASE_URL: exists AND not localhost in production
|
|
68
|
+
- API keys: exist AND not placeholder values
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**Generated Rule (security.md):**
|
|
72
|
+
```markdown
|
|
73
|
+
- Startup secret guard: All security secrets (JWT_SECRET, API keys, encryption keys)
|
|
74
|
+
MUST be validated at application startup. Missing or weak secrets MUST cause
|
|
75
|
+
immediate process.exit(1). NEVER use fallback defaults for secrets.
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
### S-04: Cross-Tenant Entity Ownership
|
|
81
|
+
|
|
82
|
+
**Problem:** API endpoint accepts an entity ID (e.g., operatorId) without
|
|
83
|
+
verifying that the entity belongs to the requesting tenant. RLS on the target
|
|
84
|
+
table may not cover this cross-reference.
|
|
85
|
+
|
|
86
|
+
**Pattern:**
|
|
87
|
+
```
|
|
88
|
+
RULE: Before using any entity ID from request params in a cross-table operation,
|
|
89
|
+
verify the entity belongs to the same tenant:
|
|
90
|
+
1. Load entity by ID
|
|
91
|
+
2. Check entity.tenantId === request.tenantId
|
|
92
|
+
3. Return 403 if mismatch
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**Generated Rule (security.md):**
|
|
96
|
+
```markdown
|
|
97
|
+
- Cross-tenant ownership: When an API accepts entity IDs (operatorId, userId, etc.),
|
|
98
|
+
ALWAYS verify entity.tenantId matches the requesting tenant before any operation.
|
|
99
|
+
RLS alone may not protect cross-table references.
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
### S-05: Webhook Signature Verification
|
|
105
|
+
|
|
106
|
+
**Problem:** Webhook endpoints accept any POST without HMAC/signature verification.
|
|
107
|
+
Attackers can inject fake messages if webhook URLs are discovered.
|
|
108
|
+
|
|
109
|
+
**Pattern:**
|
|
110
|
+
```
|
|
111
|
+
RULE: Every webhook endpoint MUST verify the request signature:
|
|
112
|
+
- Telegram: verify X-Telegram-Bot-Api-Secret-Token header
|
|
113
|
+
- Stripe: verify Stripe-Signature header with webhook secret
|
|
114
|
+
- GitHub: verify X-Hub-Signature-256 header
|
|
115
|
+
- Generic: verify HMAC-SHA256 of body with shared secret
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
**Generated Rule (security.md):**
|
|
119
|
+
```markdown
|
|
120
|
+
- Webhook HMAC: Every webhook endpoint MUST verify request signature/HMAC.
|
|
121
|
+
NEVER accept unsigned webhook requests. Log and reject unsigned payloads.
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## High-Priority Patterns
|
|
127
|
+
|
|
128
|
+
### S-06: Singleton Service Instances
|
|
129
|
+
|
|
130
|
+
**Problem:** Creating service instances per-request (e.g., `Service.fromEnv()` in
|
|
131
|
+
route handler) means stateful components like circuit breakers never accumulate
|
|
132
|
+
failure state and never trigger protection.
|
|
133
|
+
|
|
134
|
+
**Pattern:**
|
|
135
|
+
```
|
|
136
|
+
RULE: Services with stateful protection mechanisms (circuit breakers, rate limiters,
|
|
137
|
+
connection pools) MUST be created as singletons at application startup.
|
|
138
|
+
NEVER create per-request instances of stateful services.
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
**Impact on Generated Code:**
|
|
142
|
+
- In architect.md agent: include singleton pattern for infrastructure services
|
|
143
|
+
- In coding-style.md rule: "stateful services are singletons, injected at startup"
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
### S-07: Environment-Specific Security Posture
|
|
148
|
+
|
|
149
|
+
**Pattern:**
|
|
150
|
+
```
|
|
151
|
+
RULE: Security posture MUST match environment:
|
|
152
|
+
- Development: relaxed CORS, verbose errors, debug logging
|
|
153
|
+
- Staging: production-like security, sanitized test data
|
|
154
|
+
- Production: strict CORS, generic errors, structured logging only
|
|
155
|
+
|
|
156
|
+
NEVER: same security config across all environments
|
|
157
|
+
NEVER: expose stack traces in production error responses
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## Integration Patterns for Generated Toolkit
|
|
163
|
+
|
|
164
|
+
### How Patterns Map to Generated Files
|
|
165
|
+
|
|
166
|
+
| Pattern | security.md | secrets-management.md | code-reviewer.md | architect.md |
|
|
167
|
+
|---------|------------|----------------------|-------------------|--------------|
|
|
168
|
+
| S-01 RLS Bypass | Rule | — | Check | Architecture note |
|
|
169
|
+
| S-02 SQL Injection | Rule | — | Check | — |
|
|
170
|
+
| S-03 Secret Validation | Rule | Primary content | Check | Startup validation |
|
|
171
|
+
| S-04 Cross-Tenant | Rule | — | Check | — |
|
|
172
|
+
| S-05 Webhook HMAC | Rule | Secret storage | Check | — |
|
|
173
|
+
| S-06 Singleton | — | — | Check | Architecture pattern |
|
|
174
|
+
| S-07 Env Security | Rule | Env-specific rules | — | Environment guide |
|
|
175
|
+
|
|
176
|
+
### Usage in Module 03 (Generate P0)
|
|
177
|
+
|
|
178
|
+
When generating `security.md` rule (Item 2), include applicable patterns:
|
|
179
|
+
- IF multi-tenant detected: S-01, S-02, S-04
|
|
180
|
+
- IF has_external_apis: S-03, S-05
|
|
181
|
+
- IF has_database: S-01, S-02
|
|
182
|
+
- ALWAYS: S-03, S-07
|
|
183
|
+
|
|
184
|
+
### Usage in Module 04 (Generate P1)
|
|
185
|
+
|
|
186
|
+
When generating `code-reviewer.md` agent (Step 2b), add security review checklist
|
|
187
|
+
from applicable patterns to the agent's review criteria.
|
|
188
|
+
|
|
189
|
+
When generating `architect.md` agent (Step 2c), include S-06 singleton pattern
|
|
190
|
+
and S-07 environment posture in architecture guidelines.
|
|
191
|
+
|
|
192
|
+
### Usage in brutal-honesty-review
|
|
193
|
+
|
|
194
|
+
When reviewing code in Linus Mode, check for violations of all S-01 through S-07
|
|
195
|
+
patterns as CRITICAL findings. Security violations should always trigger
|
|
196
|
+
Level 3 (Brutal) calibration.
|
|
@@ -27,6 +27,13 @@ description: Intelligent feature implementation pipeline. Analyzes complexity an
|
|
|
27
27
|
One-command feature implementation that automatically selects the right pipeline
|
|
28
28
|
based on feature complexity, then executes it without manual confirmations.
|
|
29
29
|
|
|
30
|
+
> **PROCESS COMPLIANCE — BLOCKING RULES:**
|
|
31
|
+
> - MUST use /plan, /feature, or /feature-ent commands — NEVER launch raw Agent tools directly
|
|
32
|
+
> - MUST follow the skill chain: /next -> /go -> /plan|/feature|/feature-ent
|
|
33
|
+
> - FORBIDDEN: Bypassing the skill chain by spawning parallel agents without commands
|
|
34
|
+
> - FORBIDDEN: Batching multiple features into a single commit wave
|
|
35
|
+
> - CRITICAL: Each feature MUST get its own plan, validation, and commit sequence
|
|
36
|
+
|
|
30
37
|
## Step 1: Determine Target Feature
|
|
31
38
|
|
|
32
39
|
IF $ARGUMENTS is provided:
|
|
@@ -186,6 +193,14 @@ description: Autonomous project build loop. Bootstraps project and implements fe
|
|
|
186
193
|
End-to-end autonomous project build: bootstrap → implement features in loop → done.
|
|
187
194
|
Combines `/start`, `/next`, and `/go` into a single continuous pipeline.
|
|
188
195
|
|
|
196
|
+
> **AUTONOMOUS EXECUTION — BLOCKING RULES:**
|
|
197
|
+
> - MUST execute features ONE AT A TIME through the full /go pipeline
|
|
198
|
+
> - MUST create 1 plan per feature, 1 validation per feature, 1 commit per feature
|
|
199
|
+
> - NEVER batch features into parallel waves without individual plans
|
|
200
|
+
> - NEVER skip the /next -> /go pipeline by launching raw implementation agents
|
|
201
|
+
> - CRITICAL: If a feature fails 3 times, skip it and log — NEVER retry indefinitely
|
|
202
|
+
> - MUST push state after each feature completion (independent commits)
|
|
203
|
+
|
|
189
204
|
## Step 0: Parse Scope
|
|
190
205
|
|
|
191
206
|
```
|
package/templates/.claude/skills/cc-toolkit-generator-enhanced/references/templates/ddd-agents.md
CHANGED
|
@@ -194,6 +194,44 @@ Proposed
|
|
|
194
194
|
[What was rejected and why?]
|
|
195
195
|
```
|
|
196
196
|
|
|
197
|
+
## Architecture Patterns
|
|
198
|
+
|
|
199
|
+
### Singleton Services (Infrastructure)
|
|
200
|
+
|
|
201
|
+
Services with stateful protection mechanisms MUST be created as singletons at
|
|
202
|
+
application startup. NEVER create per-request instances of stateful services.
|
|
203
|
+
|
|
204
|
+
**Why:** Per-request instances of circuit breakers, rate limiters, or connection pools
|
|
205
|
+
bypass protection — the breaker never accumulates failure state and never opens.
|
|
206
|
+
|
|
207
|
+
**Pattern:**
|
|
208
|
+
```
|
|
209
|
+
CORRECT:
|
|
210
|
+
const mcpService = MCPService.fromEnv() // at startup, once
|
|
211
|
+
app.use((req, res, next) => {
|
|
212
|
+
req.mcpService = mcpService // inject singleton
|
|
213
|
+
next()
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
WRONG:
|
|
217
|
+
app.get('/api', (req, res) => {
|
|
218
|
+
const mcpService = MCPService.fromEnv() // new instance per request!
|
|
219
|
+
// circuit breaker resets every request — never trips
|
|
220
|
+
})
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
**Applies to:** circuit breakers, rate limiters, connection pools, MCP clients,
|
|
224
|
+
external service adapters, cache managers.
|
|
225
|
+
|
|
226
|
+
### Security-by-Environment
|
|
227
|
+
|
|
228
|
+
Security posture MUST match environment:
|
|
229
|
+
- **Development:** relaxed CORS, verbose errors, debug logging
|
|
230
|
+
- **Staging:** production-like security, sanitized test data
|
|
231
|
+
- **Production:** strict CORS, generic errors, structured logging only
|
|
232
|
+
|
|
233
|
+
NEVER use the same security configuration across all environments.
|
|
234
|
+
|
|
197
235
|
## Fitness Functions
|
|
198
236
|
|
|
199
237
|
{{ARCHITECTURE_FITNESS_FUNCTIONS}}
|
|
@@ -206,6 +244,7 @@ For architecture questions:
|
|
|
206
244
|
- Explain bounded context impact
|
|
207
245
|
- List trade-offs explicitly
|
|
208
246
|
- Suggest ADR if recording needed
|
|
247
|
+
- Check singleton pattern for infrastructure services
|
|
209
248
|
```
|
|
210
249
|
|
|
211
250
|
---
|
|
@@ -65,6 +65,14 @@ description: Full feature lifecycle — from idea to reviewed implementation.
|
|
|
65
65
|
Four-phase feature development lifecycle with quality gates between each phase.
|
|
66
66
|
All documentation goes to `docs/features/<feature-name>/sparc/`.
|
|
67
67
|
|
|
68
|
+
> **SKILL CHAIN — BLOCKING RULES:**
|
|
69
|
+
> - MUST execute Phase 0 (pre-flight check) before ANY generation
|
|
70
|
+
> - MUST use sparc-prd-mini skill for planning — NEVER generate SPARC docs from memory
|
|
71
|
+
> - MUST use requirements-validator for validation — NEVER skip validation phase
|
|
72
|
+
> - MUST use brutal-honesty-review for review — NEVER self-review
|
|
73
|
+
> - FORBIDDEN: Skipping any phase without explicit user permission
|
|
74
|
+
> - CRITICAL: Each phase MUST complete and commit before the next phase starts
|
|
75
|
+
|
|
68
76
|
## Phase 0: PRE-FLIGHT CHECK
|
|
69
77
|
|
|
70
78
|
Before starting, verify all required skills exist:
|
|
File without changes
|
|
File without changes
|
|
@@ -103,13 +103,37 @@ Always flag these terms and suggest specific replacements:
|
|
|
103
103
|
- Add AC: "Given X, when Y, then Z within 200ms"
|
|
104
104
|
```
|
|
105
105
|
|
|
106
|
+
### Security Acceptance Criteria (10% bonus weight)
|
|
107
|
+
|
|
108
|
+
When requirements involve authentication, data storage, external APIs, or multi-tenancy,
|
|
109
|
+
apply additional security validation:
|
|
110
|
+
|
|
111
|
+
| Criterion | Check | Red Flags |
|
|
112
|
+
|-----------|-------|-----------|
|
|
113
|
+
| Input Validation | All user inputs sanitized? | No validation mentioned, "trust client" |
|
|
114
|
+
| Authentication | Auth mechanism specified? | "users can access", no auth context |
|
|
115
|
+
| Authorization | Access control defined? | No role/permission model |
|
|
116
|
+
| Data Protection | Sensitive data handling specified? | PII without encryption rules |
|
|
117
|
+
| Multi-Tenant Isolation | Tenant boundary enforced? | Shared queries, no tenant context |
|
|
118
|
+
| Secret Management | Secrets externalized? | Hardcoded keys, fallback defaults |
|
|
119
|
+
| Webhook Security | Signature verification? | "Accept POST", no HMAC |
|
|
120
|
+
|
|
121
|
+
**Scoring Bonus:** +5 points if security criteria present and specific, +0 if not applicable,
|
|
122
|
+
-10 if security-relevant requirement lacks any security criteria (BLOCKED if score drops below 50).
|
|
123
|
+
|
|
124
|
+
**Security BDD Scenarios:** For security-relevant requirements, ALWAYS generate:
|
|
125
|
+
- Auth bypass attempt scenario
|
|
126
|
+
- Input injection scenario (SQL, XSS, command)
|
|
127
|
+
- Cross-tenant access attempt (if multi-tenant)
|
|
128
|
+
- Rate limiting / brute force scenario (if auth endpoint)
|
|
129
|
+
|
|
106
130
|
### BDD Scenario Generation
|
|
107
131
|
|
|
108
132
|
For each requirement, generate scenarios covering:
|
|
109
133
|
1. **Happy path** (1-2 scenarios) — Primary success flow
|
|
110
134
|
2. **Error handling** (2-3 scenarios) — Validation, network, server errors
|
|
111
135
|
3. **Edge cases** (1-2 scenarios) — Boundaries, concurrent access
|
|
112
|
-
4. **Security** (
|
|
136
|
+
4. **Security** (1-3 scenarios) — Auth bypass, injection, cross-tenant, rate limiting
|
|
113
137
|
|
|
114
138
|
See `references/bdd-patterns.md` for Gherkin templates and examples.
|
|
115
139
|
|