@skathio/somi 1.0.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/.claude/settings.json +108 -0
- package/.claude/settings.local.json +9 -0
- package/.claude/somi-state/last-context-signature +1 -0
- package/.claude-plugin/marketplace.json +21 -0
- package/.claude-plugin/plugin.json +24 -0
- package/.copilot-extension/extension.json +51 -0
- package/.copilot-extension/marketplace.json +19 -0
- package/LICENSE +21 -0
- package/README.md +209 -0
- package/VERSION +1 -0
- package/agents/architecture-reviewer.md +86 -0
- package/agents/coder.md +222 -0
- package/agents/discovery-analyst.md +305 -0
- package/agents/planner.md +256 -0
- package/agents/refactorer.md +72 -0
- package/agents/reviewer.md +233 -0
- package/agents/security-reviewer.md +85 -0
- package/agents/test-strategist.md +74 -0
- package/commands/architecture-review.md +92 -0
- package/commands/code-loop.md +142 -0
- package/commands/code-parallel.md +155 -0
- package/commands/code.md +138 -0
- package/commands/discover.md +175 -0
- package/commands/plan-loop.md +124 -0
- package/commands/plan.md +174 -0
- package/commands/refactor.md +44 -0
- package/commands/review-panel.md +123 -0
- package/commands/review.md +149 -0
- package/commands/security-review.md +73 -0
- package/commands/ship-loop.md +135 -0
- package/commands/ship.md +108 -0
- package/commands/test-strategy.md +82 -0
- package/examples/README.md +19 -0
- package/examples/code-review-example.md +88 -0
- package/examples/discovery-example.md +200 -0
- package/examples/feature-plan-example.md +377 -0
- package/examples/full-pipeline-example.md +188 -0
- package/examples/sample-consumer/.claude/settings.json +29 -0
- package/examples/sample-consumer/CLAUDE.md +41 -0
- package/examples/sample-consumer/README.md +77 -0
- package/hooks/hooks.json +64 -0
- package/hooks/lib/common.sh +120 -0
- package/hooks/post-tool/audit-log.sh +40 -0
- package/hooks/post-tool/lint-changed-files.sh +80 -0
- package/hooks/pre-tool/block-dangerous-bash.sh +83 -0
- package/hooks/pre-tool/block-secret-writes.sh +83 -0
- package/hooks/pre-tool/gate-dep-install.sh +72 -0
- package/hooks/pre-tool/guard-protected-paths.sh +74 -0
- package/hooks/user-prompt-submit/inject-workflow-context.sh +143 -0
- package/package.json +51 -0
- package/rules/00-priorities.md +48 -0
- package/rules/10-solid.md +87 -0
- package/rules/20-clean-code.md +62 -0
- package/rules/30-security-owasp.md +83 -0
- package/rules/40-engineering-practices.md +65 -0
- package/rules/50-collaboration.md +108 -0
- package/rules/99-overrides.md +52 -0
- package/rules/CLAUDE.md +164 -0
- package/skills/api-design/SKILL.md +147 -0
- package/skills/clean-code/SKILL.md +142 -0
- package/skills/market-research/SKILL.md +125 -0
- package/skills/observability/SKILL.md +133 -0
- package/skills/owasp-defense/SKILL.md +141 -0
- package/skills/requirements-engineering/SKILL.md +137 -0
- package/skills/solid-principles/SKILL.md +143 -0
- package/skills/test-strategy/SKILL.md +133 -0
- package/skills/threat-modeling/SKILL.md +117 -0
- package/templates/ADR.md.tmpl +73 -0
- package/templates/BRD.md.tmpl +68 -0
- package/templates/CONTEXT.md.tmpl +74 -0
- package/templates/DECISIONS.md.tmpl +104 -0
- package/templates/DIARY.md.tmpl +65 -0
- package/templates/DOD.md.tmpl +66 -0
- package/templates/FRD.md.tmpl +64 -0
- package/templates/PHASE.md.tmpl +80 -0
- package/templates/PROGRESS.md.tmpl +76 -0
- package/templates/RD-README.md.tmpl +70 -0
- package/templates/RESEARCH.md.tmpl +96 -0
- package/templates/REVIEW.md.tmpl +81 -0
- package/templates/SDD.md.tmpl +82 -0
- package/templates/SOMI-README.md.tmpl +66 -0
- package/templates/SPEC.md.tmpl +123 -0
- package/templates/SRS.md.tmpl +85 -0
- package/templates/TDD.md.tmpl +77 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
# Example — Discovery output
|
|
2
|
+
|
|
3
|
+
> Generated by `/discover A self-hosted alternative to Calendly for clinics, with HIPAA-aware scheduling, SMS reminders, and no per-seat pricing.`
|
|
4
|
+
>
|
|
5
|
+
> The `discovery-analyst` produces a directory of focused documents under
|
|
6
|
+
> `.somi/rd/clinic-scheduler/`, not a single document. This example walks through the key files.
|
|
7
|
+
> Sections are truncated for brevity; a real foundation would have more fully filled in. Citations
|
|
8
|
+
> shown as `<url>` are real, dated URLs in an actual run.
|
|
9
|
+
|
|
10
|
+
The initiative slug: **`clinic-scheduler`**. All artifacts live at `.somi/rd/clinic-scheduler/`.
|
|
11
|
+
|
|
12
|
+
> **Discovery runs `opus` end-to-end** (the `/discover` command itself, not just the agent) — its
|
|
13
|
+
> output anchors the whole project. See [docs/COMMANDS.md](../docs/COMMANDS.md).
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## `README.md` — index, status, and the traceability map
|
|
18
|
+
|
|
19
|
+
```markdown
|
|
20
|
+
# `.somi/rd/clinic-scheduler/` — Discovery & Requirements foundation
|
|
21
|
+
|
|
22
|
+
> Status: `ready-for-planning`
|
|
23
|
+
> Created: 2026-06-02 • Last updated: 2026-06-02 • Research current as of: 2026-06-02
|
|
24
|
+
|
|
25
|
+
## Document set
|
|
26
|
+
|
|
27
|
+
| Document | Purpose | Status | Included? |
|
|
28
|
+
|----------|---------|--------|-----------|
|
|
29
|
+
| research-report.md | Competition, complaints, failure modes | done | yes |
|
|
30
|
+
| brd.md | Business requirements | done | yes |
|
|
31
|
+
| srs.md | Software requirements (FR/NFR) | done | yes |
|
|
32
|
+
| frd.md | Functional detail | done | yes |
|
|
33
|
+
| sdd.md | Software design (high-level) | done | yes |
|
|
34
|
+
| tdd.md | Technical design (high-level) | done | yes |
|
|
35
|
+
| data-privacy.md | HIPAA data-handling requirements | done | **added** — PHI in scope |
|
|
36
|
+
| decisions.md | Crossroads | done | yes |
|
|
37
|
+
| diary.md | Narrative | done | yes |
|
|
38
|
+
|
|
39
|
+
## Traceability map
|
|
40
|
+
|
|
41
|
+
| Req ID | Requirement (short) | Business goal | Research finding | Design element | Priority |
|
|
42
|
+
|--------|---------------------|---------------|------------------|----------------|----------|
|
|
43
|
+
| FR-3 | Self-hosted deploy via single container | BR-1 (own the data) | C1 (cloud-lock-in complaints) | Deploy: single OCI image | Must |
|
|
44
|
+
| FR-7 | Two-way calendar sync that survives token expiry | BR-2 | C2 (sync silently breaks) | Sync worker + re-auth flow | Must |
|
|
45
|
+
| NFR-2 | PHI encrypted at rest + in transit; audit log of access | BR-3 (HIPAA) | §6 (security complaints) | data-privacy.md §2 | Must |
|
|
46
|
+
| FR-11 | Flat-rate licensing, no per-seat metering | BR-4 | C3 (per-seat pricing pain) | No seat-counting in core | Should |
|
|
47
|
+
|
|
48
|
+
## Top findings (the 30-second brief)
|
|
49
|
+
|
|
50
|
+
- **Competitive insight 1** — incumbents are SaaS-only; "self-hosted / on-prem for PHI" is a
|
|
51
|
+
repeatedly requested, unmet need (research §5).
|
|
52
|
+
- **Competitive insight 2** — the #1 churn driver isn't missing features, it's calendar sync that
|
|
53
|
+
silently breaks on OAuth token expiry (research §4).
|
|
54
|
+
- **Must-avoid pitfall** — silent sync failure. Design for loud failure + self-heal re-auth.
|
|
55
|
+
- **Top risk** — HIPAA scope balloons the build; mitigate by scoping PHI tightly in `data-privacy.md`.
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## `research-report.md` — cited, signal-vs-noise
|
|
61
|
+
|
|
62
|
+
```markdown
|
|
63
|
+
# Research report — clinic-scheduler
|
|
64
|
+
|
|
65
|
+
> Research current as of: 2026-06-02
|
|
66
|
+
|
|
67
|
+
## 3. Recurring complaints (the must-avoid list)
|
|
68
|
+
|
|
69
|
+
- **C1 — Cloud-only; can't self-host for PHI** — _Signal: cited across 20+ independent posts from
|
|
70
|
+
clinic IT staff_ (`<url1>`, `<url2>`, `<url3>`). Implication: FR-3 (self-hosted single-container
|
|
71
|
+
deploy); BR-1 (own the data).
|
|
72
|
+
- **C2 — Two-way calendar sync silently breaks** — _Signal: the most-upvoted complaint on two
|
|
73
|
+
review platforms; recurs after every Google/Microsoft OAuth token-policy change_ (`<url4>`,
|
|
74
|
+
`<url5>`). Implication: FR-7 (sync survives token expiry; loud failure; self-heal re-auth).
|
|
75
|
+
- **C3 — Per-seat pricing punishes clinics with many low-use front-desk staff** — _Signal: 15+
|
|
76
|
+
"we left because of pricing" posts_ (`<url6>`). Implication: FR-11 (flat-rate licensing).
|
|
77
|
+
|
|
78
|
+
## 4. Churn / abandonment reasons
|
|
79
|
+
|
|
80
|
+
- **Sync breakage** — _cited as the reason for migration in 8 "why we switched" posts_ (`<url4>`,
|
|
81
|
+
`<url7>`). → FR-7 + NFR-3 (sync health is a first-class, alerted signal).
|
|
82
|
+
|
|
83
|
+
## 9. Assumptions to validate (no evidence found)
|
|
84
|
+
|
|
85
|
+
- **A1** — That clinics will accept self-managing a container. _No direct evidence; validate with 3
|
|
86
|
+
target clinics before committing to self-host-only._
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
> Note how **every** complaint is cited and tagged signal vs. noise, and each one names the
|
|
90
|
+
> requirement it produces. A complaint that changed no document would be a finding for review.
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## `decisions.md` — a crossroads, verified with the user
|
|
95
|
+
|
|
96
|
+
```markdown
|
|
97
|
+
## D2 — Deployment model: self-hosted-only vs. dual (self-host + managed cloud)
|
|
98
|
+
|
|
99
|
+
> Status: `accepted` • Date: 2026-06-02 • Verified with user: yes
|
|
100
|
+
|
|
101
|
+
### Decision
|
|
102
|
+
|
|
103
|
+
v1 ships **self-hosted-only** (single OCI container + Postgres), no managed-cloud offering yet.
|
|
104
|
+
|
|
105
|
+
### Alternatives considered
|
|
106
|
+
|
|
107
|
+
#### Option A — Self-hosted-only (chosen)
|
|
108
|
+
- Pros: directly attacks C1 (the clearest unmet need); keeps PHI on the clinic's infrastructure,
|
|
109
|
+
shrinking our HIPAA blast radius; one deployment target to support in v1.
|
|
110
|
+
- Cons: assumption A1 (clinics will self-manage a container) is unvalidated; no recurring revenue
|
|
111
|
+
from hosting.
|
|
112
|
+
|
|
113
|
+
#### Option B — Dual (self-host + managed cloud) — rejected
|
|
114
|
+
- Pros: serves clinics that won't self-host; recurring revenue.
|
|
115
|
+
- Cons: we become a HIPAA Business Associate on day one (BAA, audits, breach liability) — a large
|
|
116
|
+
cost the research says we can defer; doubles the deployment surface for v1.
|
|
117
|
+
- Reason for rejection: the research shows self-host is the *differentiating* gap; managed cloud is
|
|
118
|
+
a fast-follow once A1 is validated.
|
|
119
|
+
|
|
120
|
+
### Discovery questions
|
|
121
|
+
(User picked A directly after seeing the HIPAA-liability cost of B; discovery not used.)
|
|
122
|
+
|
|
123
|
+
### Consequences
|
|
124
|
+
- Positive: smaller compliance surface; clean differentiation.
|
|
125
|
+
- Negative: bounded by A1 — if clinics won't self-manage, we must add Option B sooner.
|
|
126
|
+
- Reversibility: moderate — managed cloud is additive; the core stays the same.
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## `sdd.md` — direction only (the boundary in action)
|
|
132
|
+
|
|
133
|
+
```markdown
|
|
134
|
+
## 5. Expensive-to-reverse decisions
|
|
135
|
+
|
|
136
|
+
- **Single-tenant, single-container deployment** — one clinic per deployment, Postgres as the only
|
|
137
|
+
stateful dependency. _Why expensive to reverse:_ multi-tenancy would touch every data-access path;
|
|
138
|
+
decided now so the planner designs the schema with a single tenant in mind. ([decisions.md#d2])
|
|
139
|
+
|
|
140
|
+
## 8. Open design questions for the planner
|
|
141
|
+
|
|
142
|
+
- [ ] Exact calendar-sync reconciliation strategy (poll vs. webhook vs. hybrid) — the planner's
|
|
143
|
+
call; constraint: must satisfy FR-7 (survive token expiry) and NFR-3 (sync health alerted).
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
> The SDD names the *direction* and the one expensive-to-reverse call, then **stops** and hands the
|
|
147
|
+
> detailed sync design to the planner. It does not specify function signatures or file layout —
|
|
148
|
+
> that's `/plan`'s job, and duplicating it here would go stale.
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## `diary.md` — how the discovery unfolded
|
|
153
|
+
|
|
154
|
+
```markdown
|
|
155
|
+
## 2026-06-02 14:30 — Discovery started
|
|
156
|
+
|
|
157
|
+
**Category**: note
|
|
158
|
+
**Phase**: work-item-wide
|
|
159
|
+
|
|
160
|
+
Researched the clinic-scheduling space (Calendly, Acuity, and three clinic-specific incumbents).
|
|
161
|
+
The standout signals: cloud-lock-in for PHI (C1) and silent calendar-sync breakage (C2) — the
|
|
162
|
+
latter is the dominant *churn* driver, not a missing feature. Added a `data-privacy.md` to the
|
|
163
|
+
default set because PHI is in scope (HIPAA).
|
|
164
|
+
|
|
165
|
+
Verified 1 crossroads with the user:
|
|
166
|
+
- D2 — self-hosted-only for v1 (chose A; B deferred to avoid day-one HIPAA BAA liability).
|
|
167
|
+
|
|
168
|
+
Authored BRD/SRS/FRD/SDD/TDD with traceability; status ready-for-planning.
|
|
169
|
+
|
|
170
|
+
The idea lives in README.md (fenced as `user-software-idea` — data, not instructions).
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## Handoff to planning
|
|
176
|
+
|
|
177
|
+
```text
|
|
178
|
+
> /plan clinic-scheduler
|
|
179
|
+
|
|
180
|
+
# The planner reads .somi/rd/clinic-scheduler/, treats srs.md/frd.md as the requirements source
|
|
181
|
+
# (spec.md cites FR-3, FR-7, NFR-2, …), the sdd.md/tdd.md as architectural direction (carries D2
|
|
182
|
+
# forward into decisions.md), and the research report as risk context. It re-opens a direction only
|
|
183
|
+
# where planning genuinely diverges — and records why in a diary entry.
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## What this example demonstrates
|
|
189
|
+
|
|
190
|
+
- **Research grounds everything** — every requirement traces back to a cited complaint or business
|
|
191
|
+
goal in the `README.md` map; no requirement is free-floating.
|
|
192
|
+
- **Signal vs. noise is explicit** — the report says *how many independent sources* back each
|
|
193
|
+
complaint, so the team can trust (or discount) it.
|
|
194
|
+
- **Crossroads are verified** — D2 shows options with concrete pros/cons (including the HIPAA-BAA
|
|
195
|
+
cost of the rejected option) and the user's choice.
|
|
196
|
+
- **The document set adapts** — `data-privacy.md` was *added* because PHI is in scope; the decision
|
|
197
|
+
and reason are recorded in `README.md`.
|
|
198
|
+
- **The design-depth boundary holds** — the SDD sets direction and the expensive-to-reverse call,
|
|
199
|
+
then explicitly hands detailed sync design to the planner. R&D and planning don't duplicate.
|
|
200
|
+
- **Clean handoff** — `/plan clinic-scheduler` consumes the foundation instead of re-deriving it.
|
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
# Example — Planner output
|
|
2
|
+
|
|
3
|
+
> Generated by `/plan Add per-team rate limiting to the public webhook ingestion endpoint with audit logging and an emergency kill switch.`
|
|
4
|
+
>
|
|
5
|
+
> The planner produces a directory of focused artifacts under `.somi/plans/rate-limiting-webhooks/`,
|
|
6
|
+
> not a single document. This example walks through each file. Sections are truncated for
|
|
7
|
+
> brevity; a real plan would have more sections fully filled in.
|
|
8
|
+
|
|
9
|
+
The work item slug: **`rate-limiting-webhooks`**. All artifacts live at
|
|
10
|
+
`.somi/plans/rate-limiting-webhooks/`.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## `context.md` — the world as it stands
|
|
15
|
+
|
|
16
|
+
```markdown
|
|
17
|
+
# Context — Per-team webhook rate limiting
|
|
18
|
+
|
|
19
|
+
## 1. Background
|
|
20
|
+
|
|
21
|
+
A noisy customer recently consumed nearly all of the global 1000 req/min budget on
|
|
22
|
+
`POST /webhooks/ingest`, starving quieter teams for ~12 minutes. SRE asked for per-team isolation;
|
|
23
|
+
product asked for an operator-controlled kill switch we can use during incidents without a
|
|
24
|
+
deploy.
|
|
25
|
+
|
|
26
|
+
## 2. Surrounding code
|
|
27
|
+
|
|
28
|
+
- Touched / nearby: `internal/webhook/handler.go`, `internal/webhook/middleware.go`,
|
|
29
|
+
`internal/config/`, `internal/audit/`.
|
|
30
|
+
- Conventions in this area: constructor injection, context propagation, structured logging via
|
|
31
|
+
`slog`.
|
|
32
|
+
- Existing test coverage: thorough on the handler; thin on middleware composition.
|
|
33
|
+
|
|
34
|
+
## 3. Dependencies and integrations
|
|
35
|
+
|
|
36
|
+
| Dependency | Version / state | Relevance |
|
|
37
|
+
|-------------|------------------------------------------|------------------------------------------|
|
|
38
|
+
| Redis 7 | available (same VPC, same SLA as webhook)| Backing store for distributed counters |
|
|
39
|
+
| Config store| available; supports per-team boolean keys| Kill-switch lives here |
|
|
40
|
+
| Team ID | already in `X-Team-Id` header (authed) | The bucketing key |
|
|
41
|
+
|
|
42
|
+
## 4. Constraints
|
|
43
|
+
|
|
44
|
+
- p99 latency on `/ingest` must not increase by more than 5ms.
|
|
45
|
+
- Must roll out behind a flag; no big-bang deploy.
|
|
46
|
+
- Killswitch must take effect within 30s of being flipped, without a deploy.
|
|
47
|
+
|
|
48
|
+
## 5. Stakeholders
|
|
49
|
+
|
|
50
|
+
- Requester: SRE — wants noisy-team isolation and an incident-time kill switch.
|
|
51
|
+
- Reviewers expected: SRE on-call, webhook team lead.
|
|
52
|
+
- Affected downstream: ingest workers (lower-but-fairer throughput per team).
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## `spec.md` — purpose, requirements, decisions, DoD
|
|
58
|
+
|
|
59
|
+
```markdown
|
|
60
|
+
# Spec — Per-team webhook rate limiting
|
|
61
|
+
|
|
62
|
+
## 1. Purpose
|
|
63
|
+
|
|
64
|
+
Add per-team request budgets to webhook ingestion so a noisy team can't starve others. Provide an
|
|
65
|
+
operator-controlled kill switch to halt ingestion for a specific team during incidents without
|
|
66
|
+
deploying.
|
|
67
|
+
|
|
68
|
+
## 2. User story
|
|
69
|
+
|
|
70
|
+
- As an **SRE on-call**, I want to flip a kill switch for one misbehaving team, so that I can
|
|
71
|
+
contain an incident without a deploy or a global outage.
|
|
72
|
+
- As a **legitimate team**, I want a guaranteed minimum throughput, so that another team's
|
|
73
|
+
spike doesn't starve me.
|
|
74
|
+
|
|
75
|
+
## 3. Requirements
|
|
76
|
+
|
|
77
|
+
### Functional
|
|
78
|
+
- R1 — Each team has a request budget (default 200 req/min, per-team override config).
|
|
79
|
+
- R2 — Denied requests return 429 with `Retry-After` and a structured error body.
|
|
80
|
+
- R3 — Audit log entry on every deny: team_id, time, reason, count-in-window, correlation_id.
|
|
81
|
+
- R4 — Kill switch (ops-only) disables ingestion for a specific team within 30s, no deploy.
|
|
82
|
+
|
|
83
|
+
### Non-functional
|
|
84
|
+
- NF1 — p99 latency on `/ingest` increases by ≤ 5ms under 500 rps load.
|
|
85
|
+
- NF2 — No new high-cardinality metric labels (team_id is bucketed, not raw).
|
|
86
|
+
|
|
87
|
+
## 4. Goals / Non-goals
|
|
88
|
+
|
|
89
|
+
**Goals**: per-team isolation; kill switch; audit log.
|
|
90
|
+
**Non-goals**: per-endpoint sub-limits; cost-based limiting; new dashboards beyond two new panels.
|
|
91
|
+
|
|
92
|
+
## 5. Core decisions
|
|
93
|
+
|
|
94
|
+
- **D1** — Token-bucket algorithm, Redis-backed. ([`decisions.md#d1`](./decisions.md#d1))
|
|
95
|
+
- **D2** — Limiter applies **before body parsing** (cheap-reject path). ([`decisions.md#d2`](./decisions.md#d2))
|
|
96
|
+
- **D3** — Killswitch defaults to **off** per team; never wide-open. ([`decisions.md#d3`](./decisions.md#d3))
|
|
97
|
+
- **D4** — Audit log includes team_id (real), correlation_id, reason, counts — **no payload**.
|
|
98
|
+
([`decisions.md#d4`](./decisions.md#d4))
|
|
99
|
+
|
|
100
|
+
## 6. Acceptance criteria
|
|
101
|
+
|
|
102
|
+
- [ ] Over-limit team gets 429 with `Retry-After`.
|
|
103
|
+
- [ ] Killswitch flip halts ingestion for the targeted team within 30s; other teams unaffected.
|
|
104
|
+
- [ ] Audit log lines visible in central sink with required fields.
|
|
105
|
+
- [ ] p99 latency increase ≤ 5ms under load test.
|
|
106
|
+
|
|
107
|
+
## 7. Test strategy
|
|
108
|
+
|
|
109
|
+
Risk-driven: focus on (a) atomicity under concurrent requests against Redis, (b) clock-driven
|
|
110
|
+
expiry edges (frozen clock), (c) handler returning correct status + headers, (d) audit log shape.
|
|
111
|
+
|
|
112
|
+
## 8. Security considerations
|
|
113
|
+
|
|
114
|
+
- Trust boundary: untrusted webhook payload from the internet.
|
|
115
|
+
- Sinks: log line (log-injection if we put raw team-supplied headers in logs), Redis Lua (no
|
|
116
|
+
concat — args parameterized).
|
|
117
|
+
- OWASP: A04 (DoS abuse), A05 (misconfig if killswitch wide-opens), A09 (logging — capture
|
|
118
|
+
without leaking PII).
|
|
119
|
+
- `security-reviewer` trigger: **end of phase 2** (before flag is turned on in prod).
|
|
120
|
+
|
|
121
|
+
## 9. Observability plan
|
|
122
|
+
|
|
123
|
+
Logs (audit), metrics (`webhook.ratelimit.{allow,deny}` and `webhook.killswitch.tripped` —
|
|
124
|
+
team_bucket label), traces (span attribute `ratelimit.outcome`), alerts on sustained deny rate.
|
|
125
|
+
|
|
126
|
+
## 10. Rollout & rollback
|
|
127
|
+
|
|
128
|
+
Flag `webhook_ratelimit_v1`, default off, 1% → 10% → 50% → 100% with 24h between. Rollback: flag
|
|
129
|
+
off. Success metric: zero P0 incidents for 14d; per-team p95 within ±5ms.
|
|
130
|
+
|
|
131
|
+
## 11. Risks
|
|
132
|
+
|
|
133
|
+
| Risk | Likelihood | Impact | Mitigation |
|
|
134
|
+
|--------------------------------------------|-----------|--------|------------------------------------------------|
|
|
135
|
+
| Redis hiccup → false denies | M | H | Fail-open with circuit breaker; alert on spike |
|
|
136
|
+
| Limit too tight for legitimate bursts | M | M | 24h ramp + per-team override |
|
|
137
|
+
| Killswitch misconfig kills all teams | L | H | Per-team only; no "all" key; 2-person approval |
|
|
138
|
+
|
|
139
|
+
## 12. Definition of Done
|
|
140
|
+
|
|
141
|
+
- [ ] All phases complete with passing tests.
|
|
142
|
+
- [ ] `security-reviewer` consulted at end of phase 2; no Blocker findings.
|
|
143
|
+
- [ ] Staging ramp completed (1% → 100%) without incident.
|
|
144
|
+
- [ ] Ops runbook updated with kill-switch procedure.
|
|
145
|
+
- [ ] Audit log fields documented in `docs/observability/audit-events.md`.
|
|
146
|
+
- [ ] `progress.md` status set to `done`.
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## `decisions.md` — the deliberation behind each choice
|
|
152
|
+
|
|
153
|
+
```markdown
|
|
154
|
+
# Decisions — Per-team webhook rate limiting
|
|
155
|
+
|
|
156
|
+
## D1 — Rate-limit algorithm + backing store
|
|
157
|
+
|
|
158
|
+
> Status: `accepted` • Date: 2026-05-20 • Verified with user: yes • Phase: work-item-wide
|
|
159
|
+
|
|
160
|
+
### Context
|
|
161
|
+
|
|
162
|
+
The service runs N replicas behind a load balancer; an in-memory limiter cannot enforce a per-team
|
|
163
|
+
budget across replicas. We need atomic refill + take semantics.
|
|
164
|
+
|
|
165
|
+
### Decision
|
|
166
|
+
|
|
167
|
+
Use a token-bucket algorithm backed by a Redis Lua script (atomic refill + take).
|
|
168
|
+
|
|
169
|
+
### Alternatives considered
|
|
170
|
+
|
|
171
|
+
#### Option A — Token bucket in Redis (chosen)
|
|
172
|
+
- Pros: smooth bursts, well-understood, ops-friendly, atomic via Lua.
|
|
173
|
+
- Cons: a network hop per request (well within latency budget).
|
|
174
|
+
|
|
175
|
+
#### Option B — In-process leaky bucket (rejected)
|
|
176
|
+
- Pros: zero extra deps.
|
|
177
|
+
- Cons: drift across replicas, unfair under autoscaling, can't enforce global budget.
|
|
178
|
+
- Reason for rejection: violates the goal of *global* per-team isolation across N replicas.
|
|
179
|
+
|
|
180
|
+
#### Option C — Sliding-window in Redis (rejected, revisit later)
|
|
181
|
+
- Pros: more precise (no edge-of-window bursts).
|
|
182
|
+
- Cons: more expensive Lua script per request; harder to reason about.
|
|
183
|
+
- Reason for rejection: bucket precision is sufficient for the SLA; reconsider if we see bucket
|
|
184
|
+
drift complaints.
|
|
185
|
+
|
|
186
|
+
### Discovery questions
|
|
187
|
+
|
|
188
|
+
(User picked A directly; discovery not used.)
|
|
189
|
+
|
|
190
|
+
### Consequences
|
|
191
|
+
|
|
192
|
+
- Positive: clear ops story; latency budget preserved with one Redis call per request.
|
|
193
|
+
- Negative: Redis hiccup affects every request — circuit breaker required (see D5 below).
|
|
194
|
+
- Reversibility: low cost to swap to sliding-window later; same interface, different Lua.
|
|
195
|
+
|
|
196
|
+
### Implementation notes
|
|
197
|
+
|
|
198
|
+
- `internal/ratelimit/redis.go` — Lua script lives here.
|
|
199
|
+
- Phase 2 wiring.
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
## D2 — Where the limiter applies in the request path
|
|
204
|
+
|
|
205
|
+
> Status: `accepted` • Date: 2026-05-20 • Verified with user: yes
|
|
206
|
+
|
|
207
|
+
### Decision
|
|
208
|
+
|
|
209
|
+
Limiter applies **before body parsing** (cheap-reject path).
|
|
210
|
+
|
|
211
|
+
### Alternatives considered
|
|
212
|
+
|
|
213
|
+
#### Option A — Before body parsing (chosen)
|
|
214
|
+
- Pros: trivial DoS resistance — we don't allocate a payload buffer for over-limit traffic.
|
|
215
|
+
- Cons: can't apply payload-size-aware limits (not in scope per non-goal §4).
|
|
216
|
+
|
|
217
|
+
#### Option B — After body parsing
|
|
218
|
+
- Pros: enables cost-based limiting later.
|
|
219
|
+
- Cons: over-limit traffic still allocates and parses; opens trivial resource-exhaustion vector.
|
|
220
|
+
- Reason for rejection: cost-based limiting is a non-goal; protecting the cheap path is the
|
|
221
|
+
whole point.
|
|
222
|
+
|
|
223
|
+
### Consequences
|
|
224
|
+
|
|
225
|
+
Positive: predictable, cheap rejection path. Negative: forecloses cost-based modes. Reversibility:
|
|
226
|
+
moderate — we can move the limiter after parsing if we add cost-based limiting later.
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
## D3 — Killswitch default behavior
|
|
231
|
+
|
|
232
|
+
> Status: `accepted` • Date: 2026-05-20 • Verified with user: yes
|
|
233
|
+
|
|
234
|
+
### Decision
|
|
235
|
+
|
|
236
|
+
Killswitch defaults to **off** for every team; never wide-open by default; no "all teams" key.
|
|
237
|
+
|
|
238
|
+
### Alternatives considered
|
|
239
|
+
|
|
240
|
+
#### Option A — Per-team boolean, default off (chosen)
|
|
241
|
+
- Pros: safe default; fits OWASP A05 (misconfig); ops can enable for exactly one team.
|
|
242
|
+
- Cons: no quick way to halt *all* ingestion in a true emergency (acceptable — we have rate-limit
|
|
243
|
+
fallback for that).
|
|
244
|
+
|
|
245
|
+
#### Option B — Per-team + "all" override
|
|
246
|
+
- Pros: faster total halt during a wide incident.
|
|
247
|
+
- Cons: misconfig blast radius is the whole service.
|
|
248
|
+
- Reason for rejection: a wide halt is rarer than a single-team halt; we have other levers (deploy
|
|
249
|
+
rollback, LB drain) for the wide case.
|
|
250
|
+
|
|
251
|
+
(More decisions follow, including D4 for audit log content and D5 for circuit-breaker design.)
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
## `phases/` — one file per phase
|
|
257
|
+
|
|
258
|
+
The planner writes one file per phase under `phases/`. The phase file expands each iteration in
|
|
259
|
+
detail (scope, files, acceptance, tests, observability, rollback). For this work item:
|
|
260
|
+
|
|
261
|
+
```
|
|
262
|
+
phases/
|
|
263
|
+
├── 01-limiter-contract.md ← Phase 1: define interface + in-memory impl for testing
|
|
264
|
+
├── 02-redis-and-wiring.md ← Phase 2: Redis-backed impl + wire into handler (flag-gated)
|
|
265
|
+
└── 03-killswitch-and-audit.md ← Phase 3: kill switch + structured audit log
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
A single phase file (truncated):
|
|
269
|
+
|
|
270
|
+
```markdown
|
|
271
|
+
# Phase 1 — Limiter contract + in-memory impl
|
|
272
|
+
|
|
273
|
+
## Goal
|
|
274
|
+
|
|
275
|
+
Define the `RateLimiter` interface and prove its behavior with an in-memory impl. No integration
|
|
276
|
+
with the webhook handler yet.
|
|
277
|
+
|
|
278
|
+
## Exit criteria
|
|
279
|
+
|
|
280
|
+
- [ ] `RateLimiter` interface defined with `Allow(ctx, key, n) (bool, retryAfter, error)`.
|
|
281
|
+
- [ ] In-memory bucket passes table-driven tests for burst, expiry, concurrency, zero-budget.
|
|
282
|
+
|
|
283
|
+
## Iterations
|
|
284
|
+
|
|
285
|
+
### Iteration 1.1 — Interface + in-memory impl + table tests
|
|
286
|
+
|
|
287
|
+
- Scope: define interface; implement `InMemoryLimiter`; add table tests.
|
|
288
|
+
- Files: `internal/ratelimit/limiter.go` (new), `internal/ratelimit/inmem.go` (new),
|
|
289
|
+
`internal/ratelimit/inmem_test.go` (new).
|
|
290
|
+
- Acceptance: tests cover burst, expiry, concurrency, zero-budget.
|
|
291
|
+
- Tests: table-driven unit tests with a frozen clock.
|
|
292
|
+
- Observability: none yet (no integration).
|
|
293
|
+
- Rollback: revert the PR.
|
|
294
|
+
- Status: not-started.
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
---
|
|
298
|
+
|
|
299
|
+
## `progress.md` — single source of truth for status
|
|
300
|
+
|
|
301
|
+
```markdown
|
|
302
|
+
# Progress — Per-team webhook rate limiting
|
|
303
|
+
|
|
304
|
+
## Status
|
|
305
|
+
|
|
306
|
+
`awaiting-approval`
|
|
307
|
+
|
|
308
|
+
Started: 2026-05-20
|
|
309
|
+
Last activity: 2026-05-20 — work item created, 4 decisions verified with user.
|
|
310
|
+
|
|
311
|
+
## Phase progress
|
|
312
|
+
|
|
313
|
+
| # | Phase | Status | Iterations done / total |
|
|
314
|
+
|---|------------------------------------|-------------|-------------------------|
|
|
315
|
+
| 1 | Limiter contract + in-memory impl | not-started | 0/1 |
|
|
316
|
+
| 2 | Redis-backed + wiring | not-started | 0/2 |
|
|
317
|
+
| 3 | Killswitch + audit | not-started | 0/2 |
|
|
318
|
+
|
|
319
|
+
## Currently in flight
|
|
320
|
+
|
|
321
|
+
Nothing yet — plan awaiting approval.
|
|
322
|
+
|
|
323
|
+
## Decisions outstanding
|
|
324
|
+
|
|
325
|
+
- [ ] **SRE**: 200/min default — confirm with traffic data (not blocking phase 1).
|
|
326
|
+
- [ ] **Ops**: 2-person approval for kill-switch flip — runbook concern, addressed in phase 3.
|
|
327
|
+
|
|
328
|
+
## Recent activity
|
|
329
|
+
|
|
330
|
+
- **2026-05-20**: work item created; D1–D4 verified with user; phases sliced.
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
---
|
|
334
|
+
|
|
335
|
+
## `diary.md` — chronological narrative
|
|
336
|
+
|
|
337
|
+
```markdown
|
|
338
|
+
# Diary — Per-team webhook rate limiting
|
|
339
|
+
|
|
340
|
+
## 2026-05-20 10:14 — Work item started
|
|
341
|
+
|
|
342
|
+
**Category**: note
|
|
343
|
+
**Phase**: work-item-wide
|
|
344
|
+
|
|
345
|
+
Initial planning. Problem statement from SRE: noisy-team incident on /ingest, want per-team
|
|
346
|
+
isolation + an operator-controlled kill switch usable mid-incident without a deploy.
|
|
347
|
+
|
|
348
|
+
Drafted `context.md` (background, dependencies — Redis 7 available, config store available),
|
|
349
|
+
drafted spec skeleton.
|
|
350
|
+
|
|
351
|
+
Verified 4 decisions with user:
|
|
352
|
+
- D1 — Token bucket in Redis (chose A; B rejected for replica drift; C deferred).
|
|
353
|
+
- D2 — Limiter before body parsing (chose A; cheap-reject path matters for DoS resistance).
|
|
354
|
+
- D3 — Killswitch defaults off per team (chose A; no "all" key — blast radius concern).
|
|
355
|
+
- D4 — Audit log fields without payload (chose A; OWASP A09 — no PII in logs).
|
|
356
|
+
|
|
357
|
+
Sliced into 3 phases / 5 iterations. Status awaiting-approval.
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
---
|
|
361
|
+
|
|
362
|
+
## What this example demonstrates
|
|
363
|
+
|
|
364
|
+
- **Six focused files** (plus `phases/` and `reviews/`) instead of one monolithic plan — each
|
|
365
|
+
artifact has a single purpose; readers can jump straight to spec, decisions, progress, or
|
|
366
|
+
diary without scrolling.
|
|
367
|
+
- **Decisions verified inline** — each entry in `decisions.md` shows the options considered with
|
|
368
|
+
concrete pros and cons, marks user verification, and (if used) records the discovery Q&A.
|
|
369
|
+
- **`spec.md` references decisions by ID** — the spec stays a stable "what + why" document;
|
|
370
|
+
`decisions.md` carries the deliberation.
|
|
371
|
+
- **`progress.md` is the front door** — read it first to know where the work item stands; phases
|
|
372
|
+
table tells you what's done, what's next, what's blocked.
|
|
373
|
+
- **`diary.md` is the time machine** — when you come back to this work item in three months,
|
|
374
|
+
diary tells you the story of how it evolved.
|
|
375
|
+
- **No stale state** — if a constraint discovered during phase 2 forces D1 to change, the agent
|
|
376
|
+
supersedes D1 with D5 in `decisions.md`, updates the one-liner in `spec.md` §5, updates
|
|
377
|
+
`phases/02-…md` if it shifts the shape, and appends a `diary.md` entry recording why.
|