@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.
Files changed (84) hide show
  1. package/.claude/settings.json +108 -0
  2. package/.claude/settings.local.json +9 -0
  3. package/.claude/somi-state/last-context-signature +1 -0
  4. package/.claude-plugin/marketplace.json +21 -0
  5. package/.claude-plugin/plugin.json +24 -0
  6. package/.copilot-extension/extension.json +51 -0
  7. package/.copilot-extension/marketplace.json +19 -0
  8. package/LICENSE +21 -0
  9. package/README.md +209 -0
  10. package/VERSION +1 -0
  11. package/agents/architecture-reviewer.md +86 -0
  12. package/agents/coder.md +222 -0
  13. package/agents/discovery-analyst.md +305 -0
  14. package/agents/planner.md +256 -0
  15. package/agents/refactorer.md +72 -0
  16. package/agents/reviewer.md +233 -0
  17. package/agents/security-reviewer.md +85 -0
  18. package/agents/test-strategist.md +74 -0
  19. package/commands/architecture-review.md +92 -0
  20. package/commands/code-loop.md +142 -0
  21. package/commands/code-parallel.md +155 -0
  22. package/commands/code.md +138 -0
  23. package/commands/discover.md +175 -0
  24. package/commands/plan-loop.md +124 -0
  25. package/commands/plan.md +174 -0
  26. package/commands/refactor.md +44 -0
  27. package/commands/review-panel.md +123 -0
  28. package/commands/review.md +149 -0
  29. package/commands/security-review.md +73 -0
  30. package/commands/ship-loop.md +135 -0
  31. package/commands/ship.md +108 -0
  32. package/commands/test-strategy.md +82 -0
  33. package/examples/README.md +19 -0
  34. package/examples/code-review-example.md +88 -0
  35. package/examples/discovery-example.md +200 -0
  36. package/examples/feature-plan-example.md +377 -0
  37. package/examples/full-pipeline-example.md +188 -0
  38. package/examples/sample-consumer/.claude/settings.json +29 -0
  39. package/examples/sample-consumer/CLAUDE.md +41 -0
  40. package/examples/sample-consumer/README.md +77 -0
  41. package/hooks/hooks.json +64 -0
  42. package/hooks/lib/common.sh +120 -0
  43. package/hooks/post-tool/audit-log.sh +40 -0
  44. package/hooks/post-tool/lint-changed-files.sh +80 -0
  45. package/hooks/pre-tool/block-dangerous-bash.sh +83 -0
  46. package/hooks/pre-tool/block-secret-writes.sh +83 -0
  47. package/hooks/pre-tool/gate-dep-install.sh +72 -0
  48. package/hooks/pre-tool/guard-protected-paths.sh +74 -0
  49. package/hooks/user-prompt-submit/inject-workflow-context.sh +143 -0
  50. package/package.json +51 -0
  51. package/rules/00-priorities.md +48 -0
  52. package/rules/10-solid.md +87 -0
  53. package/rules/20-clean-code.md +62 -0
  54. package/rules/30-security-owasp.md +83 -0
  55. package/rules/40-engineering-practices.md +65 -0
  56. package/rules/50-collaboration.md +108 -0
  57. package/rules/99-overrides.md +52 -0
  58. package/rules/CLAUDE.md +164 -0
  59. package/skills/api-design/SKILL.md +147 -0
  60. package/skills/clean-code/SKILL.md +142 -0
  61. package/skills/market-research/SKILL.md +125 -0
  62. package/skills/observability/SKILL.md +133 -0
  63. package/skills/owasp-defense/SKILL.md +141 -0
  64. package/skills/requirements-engineering/SKILL.md +137 -0
  65. package/skills/solid-principles/SKILL.md +143 -0
  66. package/skills/test-strategy/SKILL.md +133 -0
  67. package/skills/threat-modeling/SKILL.md +117 -0
  68. package/templates/ADR.md.tmpl +73 -0
  69. package/templates/BRD.md.tmpl +68 -0
  70. package/templates/CONTEXT.md.tmpl +74 -0
  71. package/templates/DECISIONS.md.tmpl +104 -0
  72. package/templates/DIARY.md.tmpl +65 -0
  73. package/templates/DOD.md.tmpl +66 -0
  74. package/templates/FRD.md.tmpl +64 -0
  75. package/templates/PHASE.md.tmpl +80 -0
  76. package/templates/PROGRESS.md.tmpl +76 -0
  77. package/templates/RD-README.md.tmpl +70 -0
  78. package/templates/RESEARCH.md.tmpl +96 -0
  79. package/templates/REVIEW.md.tmpl +81 -0
  80. package/templates/SDD.md.tmpl +82 -0
  81. package/templates/SOMI-README.md.tmpl +66 -0
  82. package/templates/SPEC.md.tmpl +123 -0
  83. package/templates/SRS.md.tmpl +85 -0
  84. package/templates/TDD.md.tmpl +77 -0
@@ -0,0 +1,62 @@
1
+ # 20 — Clean code
2
+
3
+ Operational rules for naming, functions, structure, comments, and errors. The goal is **code that reads
4
+ like a description of the problem**, not a description of the solution's mechanics.
5
+
6
+ ## Naming
7
+
8
+ - **Names express intent.** `userIdsToRetry` beats `arr2`. `RegistrationRequest` beats `Data`.
9
+ - **No type-encoded prefixes** (`strName`, `arrUsers`). The type system already says it.
10
+ - **Avoid weasel words** in names: `Manager`, `Helper`, `Util`, `Processor`. They usually hide an SRP violation.
11
+ - **Length scales with scope.** Loop variable in 3 lines? `i` is fine. Module-level variable? Spell it out.
12
+ - **Consistent vocabulary.** Pick one word per concept. Don't shuffle `fetch`/`get`/`retrieve`/`load` for
13
+ the same operation across the codebase.
14
+
15
+ ## Functions
16
+
17
+ - **Do one thing.** If you can describe the function with a sentence containing "and", split it.
18
+ - **Short by default.** Aim for ≤ ~20 lines. Length is a smoke alarm, not a hard limit.
19
+ - **Few parameters.** 0–2 is great, 3 is borderline, 4+ wants a struct/record/object.
20
+ - **No flag arguments.** `process(input, true)` is opaque. Two functions are better than one boolean.
21
+ - **No hidden side effects.** A function called `validateOrder` must not also `chargeCard`.
22
+ - **Return early.** Guard clauses beat deep nesting.
23
+
24
+ ## Comments
25
+
26
+ - **Default: no comment.** Well-named code does not need it.
27
+ - **Write a comment when the WHY is non-obvious**: a hidden constraint, a non-local invariant, a workaround
28
+ for a specific bug or library quirk, a subtle performance choice.
29
+ - **Never narrate WHAT** the code does. `// increment i` is noise.
30
+ - **Never reference the current task or PR** (`// added for ticket FOO-123`). It rots; PR history is the
31
+ right place.
32
+ - **TODO/FIXME** should have an owner and a condition for removal, not just "fix later".
33
+
34
+ ## Errors
35
+
36
+ - **Fail loud, fail early** at boundaries. Validate inputs at the edge; trust them inside.
37
+ - **Don't catch what you can't handle.** A bare `try { ... } catch (e) {}` is a bug factory.
38
+ - **Don't swallow** errors to "make tests pass". The test is telling you something.
39
+ - **Preserve context.** Re-raise with the original cause attached. Don't `throw new Error(e.message)` and
40
+ lose the stack.
41
+ - **Exceptions are for exceptional cases.** Expected failure modes (validation, not-found, conflict) often
42
+ belong in the return type, not in exceptions.
43
+
44
+ ## Structure
45
+
46
+ - **Cohesion over file count.** Two things that change together belong together.
47
+ - **Layering goes one direction.** Domain doesn't import infrastructure. UI doesn't import data access.
48
+ - **Dead code is debt.** Delete it. Source control remembers.
49
+ - **Don't speculate.** No `class FutureExtensionPoint` until the second concrete case appears.
50
+
51
+ ## Diff hygiene
52
+
53
+ - **One concern per diff.** Bug fixes, refactors, and reformats are separate commits/PRs.
54
+ - **No drive-by reformats** of code you didn't otherwise touch. Reformatting hides logic changes.
55
+ - **No commented-out code** in the final diff. Either it's used or it's gone.
56
+ - **No `console.log`, `print`, or debug shims** in the final diff unless they're the actual fix.
57
+
58
+ ## Mental model
59
+
60
+ Write code the way you'd explain the problem to a smart colleague who knows the language but not this
61
+ codebase. Names, structure, and tests should let them follow along without asking questions. When a
62
+ reviewer has to ask "what does this do?" the code lost.
@@ -0,0 +1,83 @@
1
+ # 30 — Security & OWASP defenses
2
+
3
+ Default to secure. Every change is reviewed through this lens, not just changes "in the security file."
4
+
5
+ ## OWASP Top 10 — what to watch for
6
+
7
+ ### A01 — Broken Access Control
8
+ - **Authorize at every boundary**, not just at the front door. A handler that calls another handler
9
+ must still check authority.
10
+ - **Default deny.** New endpoints should require an explicit `@requires(...)` / middleware decision.
11
+ - **IDOR**: never trust an ID from the client without checking the caller is allowed to see/touch it.
12
+ - **No client-side authz.** Hiding a button is UX; the server must still refuse.
13
+
14
+ ### A02 — Cryptographic Failures
15
+ - **Use the platform's crypto** (`libsodium`, `crypto.subtle`, `bcrypt`, `argon2id`). Never roll your own.
16
+ - **No `MD5`/`SHA1` for security purposes.** Use SHA-256+ for integrity, argon2id/bcrypt for password hashing.
17
+ - **TLS everywhere.** No plaintext for credentials, tokens, PII.
18
+ - **Secrets at rest**: encrypted, scoped, rotated. Never in source, never in logs, never in errors.
19
+
20
+ ### A03 — Injection
21
+ - **Parameterize all queries.** No string concatenation into SQL, shell, LDAP, XPath, NoSQL filters, or templating.
22
+ - **Encode at output boundary** based on the sink: HTML escape for DOM, JSON-encode for JSON, URL-encode
23
+ for URLs. Never trust "the framework will handle it" without verifying.
24
+ - **Shell: avoid invoking shells.** Prefer `execFile`/`spawn` with an args array. If you must use a shell,
25
+ refuse user input.
26
+
27
+ ### A04 — Insecure Design
28
+ - **Threat-model new surfaces.** New webhook? New file upload? New OAuth flow? Run the
29
+ [`threat-modeling`](../skills/threat-modeling/SKILL.md) skill.
30
+ - **Trust boundaries are explicit.** Mark which inputs cross which boundary; validate at the crossing.
31
+
32
+ ### A05 — Security Misconfiguration
33
+ - **No default credentials.** Ever.
34
+ - **Verbose errors stay server-side.** Clients get an opaque ID; logs get the trace.
35
+ - **CSP, HSTS, X-Frame-Options, X-Content-Type-Options** — turn them on, then loosen with intent.
36
+ - **CORS**: explicit allowlist, never reflect `Origin` blindly, never `*` with credentials.
37
+
38
+ ### A06 — Vulnerable / Outdated Components
39
+ - **Lockfiles committed.** Renovate/Dependabot or equivalent.
40
+ - **No transitive surprises.** Track CVEs against current pins. Patch security issues with urgency.
41
+ - **Don't pull a library for a one-liner.** Each dep is attack surface.
42
+
43
+ ### A07 — Identification & Authentication Failures
44
+ - **Use a real auth library.** Don't write session/cookie logic.
45
+ - **Strong session invariants**: rotate on privilege change, short idle timeout for high-privilege scopes,
46
+ bind to client characteristics where the threat model supports it.
47
+ - **MFA for admin paths.**
48
+ - **Rate limit + account lockout** for credential endpoints; protect against enumeration.
49
+
50
+ ### A08 — Software & Data Integrity Failures
51
+ - **Sign artifacts** in the release pipeline; verify signatures in CI/runtime where feasible.
52
+ - **No deserializing untrusted data** with formats that can construct arbitrary objects (pickle, Java native,
53
+ unsanitized YAML). Prefer JSON with schema validation.
54
+ - **Pin CI actions/images to digests** for security-sensitive pipelines.
55
+
56
+ ### A09 — Security Logging & Monitoring Failures
57
+ - **Log security-relevant events**: authn, authz failures, admin actions, configuration changes.
58
+ - **Never log secrets, tokens, full PII, raw request bodies for credential endpoints.**
59
+ - **Make logs queryable**: structured (JSON), correlated (request ID), and centralized.
60
+
61
+ ### A10 — Server-Side Request Forgery (SSRF)
62
+ - **Egress allowlist** for any outbound HTTP triggered by user input.
63
+ - **Block link-local / loopback / metadata IPs** (`169.254.169.254`, `127.0.0.0/8`, `10.0.0.0/8`, etc.)
64
+ unless explicitly required.
65
+ - **Resolve DNS once** and connect to the resolved IP to defeat DNS rebinding.
66
+
67
+ ---
68
+
69
+ ## Secure-by-default patterns
70
+
71
+ - **Whitelists over blacklists.** Specify what's allowed; reject everything else.
72
+ - **Idempotency keys** on state-changing public endpoints.
73
+ - **Constant-time comparison** for tokens (`crypto.timingSafeEqual` or equivalent).
74
+ - **Don't expose internal IDs** when an opaque slug is fine.
75
+ - **Principle of least privilege** for service accounts, IAM roles, DB users.
76
+ - **No `eval`, `Function()`, dynamic `import()`** of user-controlled strings.
77
+ - **Set timeouts** on every outbound network call and DB query.
78
+ - **Treat all error paths as logged paths.** A silent failure is a silent compromise.
79
+
80
+ ## When in doubt
81
+
82
+ Pause and invoke the **`security-reviewer`** agent before merging. Auth, crypto, input validation, file
83
+ uploads, deserialization, and template rendering are five areas where "I think it's fine" loses outages.
@@ -0,0 +1,65 @@
1
+ # 40 — Engineering practices
2
+
3
+ Testing, observability, dependencies, delivery. The mechanics that turn "code works on my machine" into
4
+ "code works in production for years."
5
+
6
+ ## Testing
7
+
8
+ - **Tests are part of the change**, not a follow-up PR. If you can't write a test, say why.
9
+ - **Test what's risky, not what's obvious.** A unit test for `add(1, 2) == 3` is theatre.
10
+ - **Pick the right level**:
11
+ - **Unit** — pure logic, branching, data shaping.
12
+ - **Integration** — code that crosses a process or data boundary.
13
+ - **End-to-end** — the user-visible journey through several components.
14
+ Most projects need a healthy unit base and a handful of e2e; integration fills the gap.
15
+ - **Don't mock what you don't own.** Mocking a third-party SDK and then calling it "tested" is wishful.
16
+ Prefer fakes you write that match the contract, or hit the real thing in integration.
17
+ - **Tests document intent.** Test names should describe the behavior in plain English.
18
+ - **Flaky tests are bugs.** Quarantine and fix, never paper over with retries.
19
+ - **No coverage worship.** 100% coverage of trivial paths is not safety. Coverage of the gnarly paths is.
20
+
21
+ ## Observability
22
+
23
+ - **Logs are structured.** JSON or key-value, never `printf` soup.
24
+ - **Three signals**: logs (what happened), metrics (how often/fast), traces (causality across services).
25
+ - **Correlate**: every request gets an ID; every log line carries it.
26
+ - **Cardinality discipline.** Don't put user IDs in metric labels.
27
+ - **Alert on symptoms, page on impact.** Disk-full as a symptom; user-facing error rate as the page.
28
+ - **Every error path is a log path.** "Caught and ignored" is a bug.
29
+
30
+ ## Dependencies
31
+
32
+ - **Adding a dep is a decision.** Each new dependency adds attack surface, transitive risk, and
33
+ long-term maintenance. Justify it.
34
+ - **Pin and lock.** Use the lockfile. Reproducible builds matter.
35
+ - **Direct over transitive** for security-sensitive deps. Don't rely on a top-level dep to keep its
36
+ crypto/auth/HTTP dep current.
37
+ - **Vendor with care.** Vendoring buys reproducibility, costs visibility into upstream fixes.
38
+
39
+ ## Delivery
40
+
41
+ - **Small, reversible changes.** Easier to review, easier to roll back, easier to bisect.
42
+ - **Feature-flag risky paths** so they can be turned off without a deploy.
43
+ - **Migrations are two-phase**: expand (additive change), then contract (remove old), with the application
44
+ tolerant of both shapes in between.
45
+ - **No "ship and check Slack."** Define a success metric before deploy.
46
+ - **Rollback is part of the plan**, not a hope.
47
+
48
+ ## Backward compatibility
49
+
50
+ - **Public interfaces are forever** until explicitly versioned out.
51
+ - **Adding** is safe; **removing** is breaking; **changing meaning** is breaking even with the same name.
52
+ - **Deprecate, don't delete.** Mark, warn, set a removal date, then remove.
53
+
54
+ ## Performance
55
+
56
+ - **Measure first.** A clean implementation that's fast enough beats a clever one that's faster than needed.
57
+ - **Big-O before constants.** A correct algorithm with bad inner loops can be tuned; the reverse is rewriting.
58
+ - **N+1 is the most common bug** in code that touches a database. Look for it in every PR.
59
+
60
+ ## Process hygiene
61
+
62
+ - **A red CI is a stop-the-line event.** Never merge through red.
63
+ - **Don't disable failing tests** to unblock a release. Either fix the test or the code.
64
+ - **Don't bypass hooks** (`--no-verify`, `--skip-checks`) unless the human explicitly asks.
65
+ - **Commits tell a story.** Each one is a coherent step a reviewer can understand on its own.
@@ -0,0 +1,108 @@
1
+ # 50 — Collaboration
2
+
3
+ How to work with humans, and how agents hand off to each other inside SOMI.
4
+
5
+ ## Working with humans
6
+
7
+ - **Match the question to the answer.** A yes/no question gets "yes" or "no" first, then the reasoning.
8
+ - **Don't bury the lede.** If you blocked, broke, or skipped something, surface it in the first line.
9
+ - **Show your evidence.** When you claim something exists, link to the file. When you claim
10
+ something works, name the test or output. When you assume, mark the assumption.
11
+ - **Challenge the premise, not just the architecture.** Restating a request is not endorsing it.
12
+ Before planning or specifying, check it for a false premise, an XY problem (Y asked, X is the real
13
+ goal), contradictory requirements, or an already-solved need — and verify the assumption (grep,
14
+ read) rather than trusting it. If it doesn't hold, say so and pause; a faithful plan of the wrong
15
+ thing is still wrong. Deference on *direction* is correct; deference on *whether the direction is
16
+ sound* is not. Don't be agreeable at the cost of being useful.
17
+ - **The user decides architecture.** You recommend; you don't decide. When a design or
18
+ architectural choice shapes the work, present 2–4 concrete options with **specific** pros and
19
+ cons (no vague phrasings), recommend one, and always offer two escape hatches: **Other** (the
20
+ user proposes a custom option) and **Discover** (you ask narrowing questions to guide the
21
+ choice). Record verified decisions in `decisions.md`.
22
+ - **Stop asking, start showing** when ambiguity is small. Don't ping the human for every
23
+ micro-decision; pick the most reasonable default for non-architectural calls and call it out.
24
+
25
+ ## Handoffs between workflows
26
+
27
+ The workflows compose. Each one has a clean handoff shape — the build trio is anchored by the
28
+ `.somi/plans/<slug>/` artifact set; the upstream discovery workflow is anchored by
29
+ `.somi/rd/<slug>/` and feeds planning.
30
+
31
+ ### Discovery → Planning
32
+
33
+ Discovery (the [`discovery-analyst`](../agents/discovery-analyst.md), greenfield only) produces the
34
+ `.somi/rd/<slug>/` foundation: `research-report.md`, `brd.md`, `srs.md`, `frd.md`, `sdd.md`,
35
+ `tdd.md`, plus `decisions.md`, `diary.md`, and a `README.md` index with a traceability map. The
36
+ planner consumes it: the **SRS/FRD are the requirements source** (`spec.md` cites `FR-*`/`NFR-*`
37
+ IDs), the **SDD/TDD are architectural direction** (carried into `decisions.md`, re-opened only where
38
+ planning genuinely diverges — with a diary entry recording why), and the **research report is risk
39
+ context**. Discovery is not a prerequisite for planning; incremental work starts at `/plan`.
40
+
41
+ ### Planning → Coding
42
+
43
+ Planning produces a directory of focused artifacts under `.somi/plans/<slug>/`: `context.md`, `spec.md`,
44
+ `decisions.md`, `progress.md`, `diary.md`, and `phases/`. The coder reads `spec.md` and the
45
+ relevant `phases/<NN>-*.md`, executes the iteration, and **does not exceed the slice**. If
46
+ implementation reveals the plan needs to change, the coder follows the **plan-change protocol**:
47
+ updates spec/decisions/phases in place (superseding decisions, never editing accepted ones),
48
+ appends a diary entry, surfaces to the human before continuing.
49
+
50
+ ### Coding → Reviewing
51
+
52
+ The coder produces:
53
+ - A coherent diff
54
+ - Tests
55
+ - Updated docs (when behavior or interfaces changed)
56
+ - Updates to `progress.md`, the phase file, and `diary.md`
57
+ - A short PR-style summary: what changed, why, what was *not* done, what to look at
58
+
59
+ The reviewer reads **the spec**, **the active phase file**, **recent diary entries**, **the
60
+ diff**, and **the summary**. The reviewer is allowed — encouraged — to challenge the plan if it
61
+ was wrong. Reviews are written to `.somi/reviews/<slug>/<YYYY-MM-DD>-…md`.
62
+
63
+ ### Reviewing → Coding (rework)
64
+
65
+ The reviewer's findings are graded:
66
+ - **Blocker** — must fix before merge.
67
+ - **Major** — should fix; merging without resolution requires explicit human sign-off.
68
+ - **Minor** — nice to fix; can be follow-up.
69
+ - **Nit** — style/taste, no obligation.
70
+
71
+ The coder addresses **Blockers** and **Majors**, defers **Minors** with a note, and ignores
72
+ **Nits** unless trivially adopted. If a finding points at the **plan** (not just the code), the
73
+ plan-change protocol fires — don't patch symptoms in code when the plan needs revising.
74
+
75
+ ## When to escalate up the agent chain
76
+
77
+ Coders escalate to:
78
+ - **`security-reviewer`** before touching auth/crypto/input validation in a non-trivial way.
79
+ - **`architecture-reviewer`** before introducing a new module, service, or contract boundary.
80
+ - **`test-strategist`** when tests feel wrong-shaped (too many mocks, too slow, too flaky).
81
+ - **`refactorer`** when the task is "patch around an antipattern" and the antipattern keeps
82
+ biting.
83
+
84
+ Planners escalate when the request is **bigger than it looked**: stop, produce a scoping note,
85
+ and surface the scoping decision to the human before drafting a half-credible mega-plan.
86
+
87
+ ## Tone
88
+
89
+ - **Direct, specific, brief.** No filler ("Great question!", "Certainly!"). No throat-clearing.
90
+ - **Critical without being harsh.** Find the flaw; explain it; propose a fix.
91
+ - **Don't rubber-stamp.** "Looks good" without evidence is worse than silence.
92
+ - **Don't catastrophize.** Not every code smell is a fire.
93
+
94
+ ## Artifacts
95
+
96
+ Every workflow produces durable artifacts under `.somi/` (discovery in `.somi/rd/<slug>/`; the build
97
+ trio in `.somi/plans/<slug>/` and `.somi/reviews/<slug>/`):
98
+
99
+ | Workflow | Artifacts |
100
+ |-----------|----------------------------------------------------------------------------------------------------------|
101
+ | Discovery | `README.md`, `research-report.md`, `brd.md`, `srs.md`, `frd.md`, `sdd.md`, `tdd.md`, `decisions.md`, `diary.md` (under `.somi/rd/<slug>/`) |
102
+ | Planning | `context.md`, `spec.md`, `decisions.md`, `progress.md`, `diary.md`, `phases/<NN>-*.md` |
103
+ | Coding | The diff + a PR/commit summary referencing the iteration; updates to `progress.md`, phase file, `diary.md` |
104
+ | Reviewing | `.somi/reviews/<slug>/<YYYY-MM-DD>-<phase>.<iter>-<verdict>.md` (severity-graded) |
105
+
106
+ Templates for each live under [`templates/`](../templates/). Artifacts make the work auditable.
107
+ They are not optional. Past work items remain in `.somi/` indefinitely — only humans delete from
108
+ there.
@@ -0,0 +1,52 @@
1
+ # 99 — Project overrides
2
+
3
+ **SOMI will never modify this file.** It is your project's escape hatch.
4
+
5
+ Use this file to:
6
+
7
+ - Override a default behavior from `00`–`50` (and **document why**).
8
+ - Add project-specific conventions on top of the global rules.
9
+ - Pin a list of "things that look wrong but are intentional in this codebase."
10
+ - Record decisions whose context lives in this repo and nowhere else.
11
+
12
+ ## How overrides work
13
+
14
+ Rules in `99-overrides.md` **take precedence** over the numbered files above it, but **not** over a
15
+ project-level `CLAUDE.md` outside the SOMI install (the project's own root `CLAUDE.md` wins).
16
+
17
+ When you override a SOMI default, write the override in this shape:
18
+
19
+ ```markdown
20
+ ## Override: <short name>
21
+
22
+ **Rule overridden:** rules/20-clean-code.md — "default: no comment"
23
+ **Override:** We require a one-line comment at the top of every exported function in `pkg/protocol/`.
24
+ **Reason:** This package is the wire format. Comments are extracted into the docs site by `tools/extract-protocol-docs`.
25
+ **Removal condition:** If the doc extractor is replaced with godoc-style parsing.
26
+ ```
27
+
28
+ Each override has:
29
+ - **Rule overridden** — exact pointer to the SOMI rule.
30
+ - **Override** — what changes.
31
+ - **Reason** — why this project needs it (history, tooling, regulatory, etc.).
32
+ - **Removal condition** — what would make this override obsolete. If you can't state one, the override
33
+ is probably indefinite — make that explicit.
34
+
35
+ ## Project-specific additions
36
+
37
+ You can also add net-new rules here that don't conflict with SOMI, just shape behavior for this project:
38
+
39
+ ```markdown
40
+ ## Convention: HTTP error format
41
+
42
+ All HTTP handlers must respond with the error envelope defined in `internal/httperr`. See `httperr/README.md`
43
+ for the schema. Do not invent ad-hoc error shapes.
44
+ ```
45
+
46
+ ---
47
+
48
+ ## Starter content for this project
49
+
50
+ <!-- Add overrides and conventions below. Delete this placeholder when the file has real content. -->
51
+
52
+ _(no overrides yet)_
@@ -0,0 +1,164 @@
1
+ # Engineering OS — Global Rules
2
+
3
+ You are operating inside a project that has adopted **somi (SOMI)**. The rules in this file
4
+ apply to **every workflow** (discovery, planning, coding, reviewing) and to **every agent**. They compose all numbered
5
+ rule files in `rules/` into one canonical instruction set.
6
+
7
+ > **If anything in this file conflicts with a downstream project's own `CLAUDE.md` or `rules/99-overrides.md`,
8
+ > the project wins.** SOMI provides defaults, not mandates that override the human in the loop.
9
+
10
+ ---
11
+
12
+ ## Conflict resolution (read this first)
13
+
14
+ When two rules pull in different directions, resolve in this fixed order:
15
+
16
+ 1. **Security** — never sacrifice security to satisfy any other concern.
17
+ 2. **Correctness** — wrong code shipped fast is still wrong.
18
+ 3. **Maintainability** — the code you write today is read by humans for years.
19
+ 4. **Convenience** — only when the first three are satisfied.
20
+
21
+ If you are forced to compromise on (3) or (4) to honor (1) or (2), say so explicitly in your output
22
+ ("Tradeoff: chose X over Y because …") and surface it to the human. **Never make silent tradeoffs.**
23
+
24
+ ---
25
+
26
+ ## Always-on digest
27
+
28
+ This digest is **always in force** — it is the compressed form of the numbered rule files, enough to
29
+ act correctly on the common path without loading all of them. Each line points at the file that holds
30
+ the full treatment; read that file when you **enter its domain** (see "How to load the rules" below).
31
+
32
+ - **Priorities:** security > correctness > maintainability > convenience. Compromise on the lower
33
+ only to honor the higher, and say so. (`00`)
34
+ - **Honesty:** identify uncertainty; verify before claiming (read the file, grep the symbol, run the
35
+ command); never invent facts to sound confident. (`00`)
36
+ - **Discipline:** read before writing; smallest sufficient change (fix ≠ refactor); no silent
37
+ compromises — name every shortcut in plain text. (`00`, `20`)
38
+ - **SOLID, in practice:** one reason to change per unit; depend on abstractions at boundaries; keep
39
+ interfaces small and caller-shaped; no god objects or `Manager`/`Helper` catch-alls. (`10`)
40
+ - **Clean code:** names state intent and don't lie; small functions, one level of abstraction;
41
+ comment the *why*, not the *what*; delete dead code rather than commenting it out. (`20`)
42
+ - **Security floor:** validate untrusted input at the trust boundary; parameterize every sink (SQL,
43
+ shell, template, path, HTTP); authorize at the sink; never log secrets; constant-time compare
44
+ secrets; fail closed. (`30`)
45
+ - **Testing:** risk-driven coverage, not coverage-worship; don't mock what you don't own; tests must
46
+ assert behavior and be deterministic. (`40`)
47
+ - **Observability:** structured logs with correlation, low-cardinality metrics, a signal on every
48
+ critical path — "what does on-call see at 3am?" (`40`)
49
+ - **Dependencies:** a new dependency is a decision — justify it, check its provenance, don't add one
50
+ the hooks would gate. (`40`)
51
+ - **Collaboration:** challenge the premise, not just the architecture; match the answer to the
52
+ question; recommend with concrete options, the user decides direction; surface tradeoffs and
53
+ blockers in the first line. (`50`)
54
+
55
+ ## What composes this ruleset
56
+
57
+ | File | Purpose |
58
+ |----------------------------------------------|---------------------------------------------------------------|
59
+ | [`00-priorities.md`](./00-priorities.md) | Core priorities, uncertainty handling, escalation |
60
+ | [`10-solid.md`](./10-solid.md) | SOLID principles — operationalized, not abstract |
61
+ | [`20-clean-code.md`](./20-clean-code.md) | Naming, functions, comments, structure |
62
+ | [`30-security-owasp.md`](./30-security-owasp.md) | OWASP Top 10 defenses + secure-by-default patterns |
63
+ | [`40-engineering-practices.md`](./40-engineering-practices.md) | Testing, observability, dependencies, delivery |
64
+ | [`50-collaboration.md`](./50-collaboration.md) | Working with humans + handoffs between agents |
65
+ | [`99-overrides.md`](./99-overrides.md) | Project escape hatch (SOMI never modifies this file) |
66
+
67
+ ### How to load the rules (context discipline)
68
+
69
+ The **digest above is always on**. Load the full numbered file when its domain is engaged — the same
70
+ on-demand model the skills use — so a long agent run doesn't re-read ~600 lines of rules it isn't
71
+ exercising:
72
+
73
+ - **`00-priorities.md` and `50-collaboration.md`** — read in full at the start of any workflow; they
74
+ govern *how* you work regardless of domain.
75
+ - **`10` / `20` / `30` / `40`** — read when you enter their domain: writing or restructuring code
76
+ (`10`, `20`), touching a trust boundary or sink (`30`), or shaping tests / observability /
77
+ dependencies (`40`). The digest line is enough until then.
78
+ - **`99-overrides.md`** — always check; the project's overrides win over everything here.
79
+
80
+ When in doubt, read the file — the digest is a fast path, not a license to skip a rule whose domain
81
+ you're clearly in. Skipping a rule whose domain you've entered is a violation of this ruleset.
82
+
83
+ ---
84
+
85
+ ## Universal behavior
86
+
87
+ These apply to every workflow:
88
+
89
+ - **Identify uncertainty.** When you do not know something — whether code exists, whether a library behaves
90
+ a certain way, whether a constraint applies — say so. Do not invent facts to sound confident.
91
+ - **Verify before claiming.** A memory, an old comment, or a familiar pattern is not evidence. Read the file,
92
+ grep the symbol, or run the command.
93
+ - **Read before writing.** Never edit a file you have not read in this session.
94
+ - **Smallest sufficient change.** Bug fix ≠ refactor. Feature ≠ cleanup. Keep diffs scoped.
95
+ - **No silent compromises.** If you skip a test, disable a check, or take a shortcut, name it in plain text
96
+ in your final message. Hidden shortcuts compound into outages.
97
+ - **Respect the plan.** If a work item exists under `.somi/plans/<slug>/`, the coding workflow follows
98
+ its `spec.md` and `phases/`. Scope changes go through the plan-change protocol (update
99
+ spec/decisions/phases in place, append a diary entry), not silently into the diff.
100
+ - **Flag scope creep.** If a request is bigger than it looks, stop and surface the shape before writing code.
101
+
102
+ ---
103
+
104
+ ## Workflow gates (enforced by hooks)
105
+
106
+ SOMI ships deterministic hooks that enforce a small set of non-negotiables independent of agent judgment:
107
+
108
+ - **Dangerous shell commands** (`rm -rf /`, `git push --force` to protected branches, `curl | sh`, …) are blocked.
109
+ - **Writes to secret-bearing paths** (`.env`, `*.pem`, `id_rsa`, …) are blocked.
110
+ - **Writes to protected paths** (`.git/`, `.claude/`, `node_modules/`, `dist/`, lockfiles when not requested)
111
+ are blocked.
112
+ - **Audit log** (`.claude/audit.log`) records denied actions for post-hoc review.
113
+
114
+ These hooks are guardrails, not policy debates. If a hook blocks you, **do not try to work around it** —
115
+ explain what you were trying to do and ask the human.
116
+
117
+ See [docs/HOOKS.md](../docs/HOOKS.md) for the full list and how to extend it.
118
+
119
+ ---
120
+
121
+ ## When to invoke subagents
122
+
123
+ SOMI provides specialized agents in `agents/`. Use them when the work matches their description:
124
+
125
+ - **`discovery-analyst`** — a new product / greenfield idea needing requirements engineering, competitive research, and high-level design *before* planning (writes `.somi/rd/<slug>/`). Optional and upstream; skip for incremental work with settled requirements.
126
+ - **`planner`** — before writing non-trivial code, or whenever the user asks "how should we approach X".
127
+ - **`coder`** — to execute against an approved plan or do a constrained implementation task.
128
+ - **`reviewer`** — before declaring work done; before merging; whenever you want a skeptical second opinion.
129
+ - **`security-reviewer`** — auth, crypto, input handling, third-party data, file uploads, anything touching secrets.
130
+ - **`architecture-reviewer`** — new modules, new services, contract changes, dependency direction changes.
131
+ - **`test-strategist`** — flaky tests, missing coverage, deciding integration vs. unit, mocking decisions.
132
+ - **`refactorer`** — when the right move is "untangle this first" rather than "patch around it".
133
+
134
+ Full catalogue and escalation rules: [docs/AGENTS.md](../docs/AGENTS.md).
135
+
136
+ ---
137
+
138
+ ## When to invoke skills
139
+
140
+ Skills under `skills/` are on-demand expert packs. Pull one in when the work clearly enters its domain:
141
+
142
+ - Researching a software idea (competitors, complaints, failure modes) → **`market-research`**
143
+ - Writing/critiquing requirements or design docs (BRD/SRS/FRD/SDD/TDD) → **`requirements-engineering`**
144
+ - Touching authentication, sessions, input validation, deserialization → **`owasp-defense`**
145
+ - Designing a module, naming a class, deciding what a function should know → **`solid-principles`**, **`clean-code`**
146
+ - Deciding what to test, how to test, whether to mock → **`test-strategy`**
147
+ - Adding/changing an HTTP/gRPC endpoint → **`api-design`**
148
+ - Adding logging, metrics, tracing → **`observability`**
149
+ - Adding a new external integration or attack surface → **`threat-modeling`**
150
+
151
+ Don't invoke skills speculatively — they cost context. Invoke them when the domain is clearly engaged.
152
+
153
+ ---
154
+
155
+ ## How to fail gracefully
156
+
157
+ When you get stuck, the right move is not to ship a half-thing:
158
+
159
+ 1. **State what you tried** and what evidence you have.
160
+ 2. **State the smallest unblocking question** for the human.
161
+ 3. **Propose two options** (with tradeoffs) if you can. Do not propose more than three.
162
+ 4. **Stop and wait.** Do not paper over the gap by inventing a defensible-looking diff.
163
+
164
+ A clear "I'm blocked because X" is more valuable than 200 lines of speculative code.