@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,83 @@
1
+ #!/usr/bin/env bash
2
+ # PreToolUse hook (matcher: Bash) — block clearly dangerous shell commands.
3
+ #
4
+ # This is a deterministic guardrail, not a policy debate. It catches the
5
+ # common-and-catastrophic class of mistakes; nuanced cases are the human's call.
6
+ #
7
+ # Block list focuses on irreversible / system-destructive / supply-chain shapes.
8
+ # It is intentionally conservative — false positives cost less than false negatives here.
9
+
10
+ set -euo pipefail
11
+
12
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
13
+ # shellcheck source=../lib/common.sh
14
+ source "$SCRIPT_DIR/../lib/common.sh"
15
+
16
+ somi::read_payload
17
+
18
+ CMD="$(somi::field '.tool_input.command')"
19
+ [[ -z "$CMD" ]] && exit 0
20
+
21
+ # Case-sensitive patterns (filesystem paths, exact tools, exact flags).
22
+ DANGEROUS_PATTERNS=(
23
+ # filesystem nukes
24
+ 'rm[[:space:]]+-rf?[[:space:]]+/([[:space:]]|$)'
25
+ 'rm[[:space:]]+-rf?[[:space:]]+~([[:space:]]|/|$)'
26
+ 'rm[[:space:]]+-rf?[[:space:]]+\*'
27
+ 'rm[[:space:]]+-rf?[[:space:]]+\$HOME'
28
+ ':\(\)\{[[:space:]]*:\|:&[[:space:]]*\};:' # fork bomb
29
+
30
+ # device / partition writes
31
+ '>[[:space:]]*/dev/(sd[a-z]|nvme|hd[a-z]|disk)'
32
+ 'dd[[:space:]]+if=.*[[:space:]]+of=/dev/(sd[a-z]|nvme|hd[a-z]|disk)'
33
+ 'mkfs(\.|[[:space:]])'
34
+
35
+ # supply-chain / remote-exec one-liners
36
+ 'curl[[:space:]]+[^|]*\|[[:space:]]*(sudo[[:space:]]+)?(ba)?sh'
37
+ 'wget[[:space:]]+[^|]*\|[[:space:]]*(sudo[[:space:]]+)?(ba)?sh'
38
+ 'curl[[:space:]]+[^|]*\|[[:space:]]*python[0-9]*'
39
+ 'wget[[:space:]]+[^|]*\|[[:space:]]*python[0-9]*'
40
+
41
+ # destructive git ops on protected branches
42
+ # Covers --force, -f, --force-with-lease (with or without =value), and refspec form (origin HEAD:main).
43
+ 'git[[:space:]]+push[[:space:]]+(-{1,2}force|-f)([[:space:]=]|$).*[[:space:]:](main|master|trunk|release)([[:space:]]|$)'
44
+ 'git[[:space:]]+push[[:space:]]+--force-with-lease([[:space:]=][^[:space:]]*)?[[:space:]].*[[:space:]:](main|master|trunk|release)([[:space:]]|$)'
45
+ 'git[[:space:]]+branch[[:space:]]+-D[[:space:]]+(main|master|trunk)'
46
+ 'git[[:space:]]+reset[[:space:]]+--hard[[:space:]]+(origin/)?(main|master|trunk)'
47
+ 'git[[:space:]]+clean[[:space:]]+-[fdx]+[[:space:]]'
48
+
49
+ # process / permission ops
50
+ 'chmod[[:space:]]+-R[[:space:]]+777[[:space:]]+/'
51
+ 'chown[[:space:]]+-R[[:space:]]+.*[[:space:]]+/'
52
+
53
+ # skipping safety checks (only block when used in commit/push context)
54
+ 'git[[:space:]]+commit[[:space:]]+.*--no-verify'
55
+ 'git[[:space:]]+push[[:space:]]+.*--no-verify'
56
+ )
57
+
58
+ # Case-insensitive patterns (SQL keywords arrive in lowercase from ORM logs, mixed case from REPLs).
59
+ DANGEROUS_PATTERNS_NOCASE=(
60
+ 'DROP[[:space:]]+DATABASE'
61
+ 'DROP[[:space:]]+SCHEMA[[:space:]]+(public|prod|production)'
62
+ 'DROP[[:space:]]+TABLE[[:space:]]+[a-zA-Z_]+'
63
+ 'TRUNCATE[[:space:]]+(TABLE[[:space:]]+)?[a-zA-Z_]+'
64
+ 'DELETE[[:space:]]+FROM[[:space:]]+[a-zA-Z_]+[[:space:]]*;'
65
+ )
66
+
67
+ for pattern in "${DANGEROUS_PATTERNS[@]}"; do
68
+ if [[ "$CMD" =~ $pattern ]]; then
69
+ somi::deny_pretool "somi refused this command: it matches a dangerous-shell pattern (\`${BASH_REMATCH[0]}\`).
70
+ If this is genuinely intended, stop and ask the human to run it themselves — never work around this hook silently."
71
+ fi
72
+ done
73
+
74
+ shopt -s nocasematch
75
+ for pattern in "${DANGEROUS_PATTERNS_NOCASE[@]}"; do
76
+ if [[ "$CMD" =~ $pattern ]]; then
77
+ somi::deny_pretool "somi refused this command: it matches a destructive-SQL pattern (\`${BASH_REMATCH[0]}\`).
78
+ If this is genuinely intended, stop and ask the human to run it themselves — never work around this hook silently."
79
+ fi
80
+ done
81
+ shopt -u nocasematch
82
+
83
+ exit 0
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env bash
2
+ # PreToolUse hook (matcher: Write|Edit) — block writes to secret-bearing paths.
3
+ #
4
+ # We block any attempt to write/edit files that are likely to hold real secrets.
5
+ # If the user genuinely needs to bootstrap a `.env`, they can do it themselves
6
+ # or explicitly add an override in their settings.local.json.
7
+
8
+ set -euo pipefail
9
+
10
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
11
+ # shellcheck source=../lib/common.sh
12
+ source "$SCRIPT_DIR/../lib/common.sh"
13
+
14
+ somi::read_payload
15
+
16
+ TOOL="$(somi::field '.tool_name')"
17
+ PATH_INPUT="$(somi::field '.tool_input.file_path')"
18
+ [[ -z "$PATH_INPUT" ]] && exit 0
19
+
20
+ # Normalise to basename + path for pattern matching.
21
+ BASENAME="$(basename "$PATH_INPUT")"
22
+
23
+ SECRET_PATTERNS=(
24
+ # env files (allow .env.example, .env.sample, .env.template explicitly)
25
+ '^\.env$'
26
+ '^\.env\.local$'
27
+ '^\.env\.production$'
28
+ '^\.env\.prod$'
29
+ '^\.env\.staging$'
30
+ '^\.env\.secret$'
31
+
32
+ # private keys and certs
33
+ '\.pem$'
34
+ '\.key$'
35
+ '\.p12$'
36
+ '\.pfx$'
37
+ '\.jks$'
38
+ '^id_rsa$'
39
+ '^id_ed25519$'
40
+ '^id_ecdsa$'
41
+ '^id_dsa$'
42
+
43
+ # cloud credentials
44
+ '^credentials$' # ~/.aws/credentials
45
+ '^config$' # ~/.aws/config (usually contains profile refs but no secrets)
46
+
47
+ # service-account keys
48
+ '-key\.json$'
49
+ '-credentials\.json$'
50
+ 'service-account.*\.json$'
51
+
52
+ # shell rc files (may contain export STATEMENTS with secrets)
53
+ '\.netrc$'
54
+ '\.pgpass$'
55
+
56
+ # vault / secret tool files
57
+ '\.kdbx$'
58
+ 'secrets?\.ya?ml$'
59
+ 'secrets?\.json$'
60
+ )
61
+
62
+ # Allow explicit example/template files.
63
+ EXAMPLE_BASENAMES=(
64
+ '.env.example'
65
+ '.env.sample'
66
+ '.env.template'
67
+ '.env.dist'
68
+ )
69
+
70
+ for ex in "${EXAMPLE_BASENAMES[@]}"; do
71
+ if [[ "$BASENAME" == "$ex" ]]; then
72
+ exit 0
73
+ fi
74
+ done
75
+
76
+ for pattern in "${SECRET_PATTERNS[@]}"; do
77
+ if [[ "$BASENAME" =~ $pattern ]]; then
78
+ somi::deny_pretool "somi refused to ${TOOL} \`${PATH_INPUT}\`: this path is in the secret-bearing allowlist.
79
+ Bootstrap secret files by hand, or commit only \`.env.example\`-style templates."
80
+ fi
81
+ done
82
+
83
+ exit 0
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env bash
2
+ # PreToolUse hook (matcher: Bash) — gate dependency-adding commands.
3
+ #
4
+ # Adding a runtime dependency crosses a trust boundary: it imports unreviewed code,
5
+ # expands attack surface, and creates a long-term maintenance obligation. The
6
+ # coder should not add deps as a drive-by — they belong in `decisions.md` or at
7
+ # minimum in the iteration summary so a human can sign off.
8
+ #
9
+ # This hook denies adding a *new* dep without an explicit acknowledgement
10
+ # (SOMI_ALLOW_DEP_INSTALL=1 in the env, set by the human for the session).
11
+ # Lockfile-respecting reinstalls (bare `npm install`, `yarn install`, etc.)
12
+ # are allowed — those don't add deps, they materialize what's already declared.
13
+
14
+ set -euo pipefail
15
+
16
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
17
+ # shellcheck source=../lib/common.sh
18
+ source "$SCRIPT_DIR/../lib/common.sh"
19
+
20
+ somi::read_payload
21
+
22
+ CMD="$(somi::field '.tool_input.command')"
23
+ [[ -z "$CMD" ]] && exit 0
24
+
25
+ # Explicit opt-in: human acknowledged this session may add deps.
26
+ if [[ "${SOMI_ALLOW_DEP_INSTALL:-0}" == "1" ]]; then
27
+ exit 0
28
+ fi
29
+
30
+ # Patterns for "add a new dependency". A trailing package argument is required;
31
+ # bare `<pm> install` (no package) is the lockfile-respecting form and is fine.
32
+ DEP_ADD_PATTERNS=(
33
+ # npm / yarn / pnpm / bun: install with at least one positional package
34
+ 'npm[[:space:]]+(install|i|add)[[:space:]]+([^-][^[:space:]]*|--save[[:space:]]+[^[:space:]]+|--save-dev[[:space:]]+[^[:space:]]+)'
35
+ 'yarn[[:space:]]+add[[:space:]]+[^-][^[:space:]]*'
36
+ 'pnpm[[:space:]]+(add|install)[[:space:]]+[^-][^[:space:]]*'
37
+ 'bun[[:space:]]+(add|install)[[:space:]]+[^-][^[:space:]]*'
38
+
39
+ # python: pip / pipx / uv / poetry / conda
40
+ 'pip[0-9]*[[:space:]]+install[[:space:]]+([^-][^[:space:]]*|-r[[:space:]]+[^[:space:]]+\.txt)'
41
+ 'pip[0-9]*[[:space:]]+install[[:space:]]+--upgrade[[:space:]]+[^-][^[:space:]]*'
42
+ 'pipx[[:space:]]+install[[:space:]]+[^-][^[:space:]]*'
43
+ 'uv[[:space:]]+(add|pip[[:space:]]+install)[[:space:]]+[^-][^[:space:]]*'
44
+ 'poetry[[:space:]]+add[[:space:]]+[^-][^[:space:]]*'
45
+ 'conda[[:space:]]+install[[:space:]]+[^-][^[:space:]]*'
46
+
47
+ # rust / go / ruby / php
48
+ 'cargo[[:space:]]+(add|install)[[:space:]]+[^-][^[:space:]]*'
49
+ 'go[[:space:]]+get[[:space:]]+[^-][^[:space:]]*'
50
+ 'go[[:space:]]+install[[:space:]]+[^-][^[:space:]]*'
51
+ 'gem[[:space:]]+install[[:space:]]+[^-][^[:space:]]*'
52
+ 'bundle[[:space:]]+add[[:space:]]+[^-][^[:space:]]*'
53
+ 'composer[[:space:]]+(require|install)[[:space:]]+[^-][^[:space:]]*'
54
+
55
+ # generic curl-to-installer (`brew install` is borderline; install scripts often add tools).
56
+ 'brew[[:space:]]+install[[:space:]]+[^-][^[:space:]]*'
57
+ 'apt[[:space:]]+(install|add)[[:space:]]+[^-][^[:space:]]*'
58
+ 'apt-get[[:space:]]+install[[:space:]]+[^-][^[:space:]]*'
59
+ )
60
+
61
+ for pattern in "${DEP_ADD_PATTERNS[@]}"; do
62
+ if [[ "$CMD" =~ $pattern ]]; then
63
+ somi::deny_pretool "somi refused this command: it would add a new dependency (\`${BASH_REMATCH[0]}\`).
64
+ Adding a dep is a decision — record it in \`.somi/plans/<slug>/decisions.md\` (or surface it in
65
+ the iteration summary for the human) and re-run with \`SOMI_ALLOW_DEP_INSTALL=1\` in the
66
+ environment for this session, or have the human run the install themselves.
67
+ Lockfile-respecting reinstalls (bare \`npm install\` / \`pip install -r requirements.txt\`-less,
68
+ \`bundle install\`, etc.) are allowed without acknowledgement."
69
+ fi
70
+ done
71
+
72
+ exit 0
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env bash
2
+ # PreToolUse hook (matcher: Write|Edit) — block writes to paths the agent shouldn't be editing.
3
+ #
4
+ # Targets the most common "agent overstep" cases: .git internals, vendored deps,
5
+ # build outputs, and the SOMI plugin install (so an agent doesn't rewrite its
6
+ # own ruleset under your feet).
7
+ #
8
+ # Lockfile writes are blocked by default (use `npm install <pkg>` etc instead),
9
+ # but a project can opt out via SOMI_ALLOW_LOCKFILES=1.
10
+
11
+ set -euo pipefail
12
+
13
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
14
+ # shellcheck source=../lib/common.sh
15
+ source "$SCRIPT_DIR/../lib/common.sh"
16
+
17
+ somi::read_payload
18
+
19
+ TOOL="$(somi::field '.tool_name')"
20
+ PATH_INPUT="$(somi::field '.tool_input.file_path')"
21
+ [[ -z "$PATH_INPUT" ]] && exit 0
22
+
23
+ PROTECTED_GLOBS=(
24
+ # Source-control internals.
25
+ '*/.git/*'
26
+
27
+ # SOMI plugin install — never let an agent rewrite the ruleset under itself.
28
+ '*/.claude/plugins/somi/*'
29
+
30
+ # Vendored deps & build outputs.
31
+ '*/node_modules/*'
32
+ '*/vendor/*'
33
+ '*/dist/*'
34
+ '*/build/*'
35
+ '*/target/*'
36
+ '*/.next/*'
37
+ '*/.nuxt/*'
38
+ '*/__pycache__/*'
39
+ )
40
+
41
+ LOCKFILES=(
42
+ 'package-lock.json'
43
+ 'yarn.lock'
44
+ 'pnpm-lock.yaml'
45
+ 'Cargo.lock'
46
+ 'Gemfile.lock'
47
+ 'poetry.lock'
48
+ 'uv.lock'
49
+ 'composer.lock'
50
+ 'go.sum'
51
+ )
52
+
53
+ # Protected glob match (uses bash extglob).
54
+ shopt -s extglob
55
+ for glob in "${PROTECTED_GLOBS[@]}"; do
56
+ # shellcheck disable=SC2053
57
+ if [[ "$PATH_INPUT" == $glob ]]; then
58
+ somi::deny_pretool "somi refused to ${TOOL} \`${PATH_INPUT}\`: this path matches a protected glob (\`${glob}\`).
59
+ These paths are owned by tooling (git / package managers / SOMI itself); changes belong in their respective workflows."
60
+ fi
61
+ done
62
+
63
+ # Lockfile gate.
64
+ if [[ "${SOMI_ALLOW_LOCKFILES:-0}" != "1" ]]; then
65
+ BASENAME="$(basename "$PATH_INPUT")"
66
+ for lock in "${LOCKFILES[@]}"; do
67
+ if [[ "$BASENAME" == "$lock" ]]; then
68
+ somi::deny_pretool "somi refused to ${TOOL} \`${PATH_INPUT}\`: lockfiles should be regenerated by the package manager, not hand-edited.
69
+ If you genuinely need to hand-edit this lockfile, set SOMI_ALLOW_LOCKFILES=1 in your environment for this session."
70
+ fi
71
+ done
72
+ fi
73
+
74
+ exit 0
@@ -0,0 +1,143 @@
1
+ #!/usr/bin/env bash
2
+ # UserPromptSubmit hook — inject SOMI context on relevant turns.
3
+ #
4
+ # Two responsibilities:
5
+ # 1. Remind the agent of the priority stack and active work-item state.
6
+ # 2. Surface end-of-turn loose ends (TODO(claude) markers, scratch files) on
7
+ # the NEXT user turn — this replaces the old Stop hook, which used an
8
+ # additionalContext channel that Stop events don't actually have.
9
+ #
10
+ # To avoid double-loading content that's already always-on, the reminder block
11
+ # only fires on the first turn of a session OR when work-item state has changed
12
+ # since the last turn. The loose-end nudges fire whenever there is something
13
+ # to nudge about.
14
+
15
+ set -euo pipefail
16
+
17
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
18
+ # shellcheck source=../lib/common.sh
19
+ source "$SCRIPT_DIR/../lib/common.sh"
20
+
21
+ somi::read_payload
22
+
23
+ PROJECT_ROOT="${CLAUDE_PROJECT_DIR:-$PWD}"
24
+ STATE_DIR="${PROJECT_ROOT}/.claude/somi-state"
25
+ STATE_FILE="${STATE_DIR}/last-context-signature"
26
+ mkdir -p "$STATE_DIR"
27
+
28
+ # Compute a signature for "current SOMI state" — first turn writes it; subsequent
29
+ # turns only re-inject the reminder if the signature changed.
30
+ compute_signature() {
31
+ local plans_state=""
32
+ if [[ -d "$PROJECT_ROOT/.somi/plans" ]]; then
33
+ plans_state="$(find "$PROJECT_ROOT/.somi/plans" -maxdepth 2 -name 'progress.md' -printf '%T@ %p\n' 2>/dev/null | sort | sha256sum | cut -d' ' -f1)"
34
+ fi
35
+ local reviews_state=""
36
+ if [[ -d "$PROJECT_ROOT/.somi/reviews" ]]; then
37
+ reviews_state="$(find "$PROJECT_ROOT/.somi/reviews" -maxdepth 3 -name '*.md' -printf '%T@ %p\n' 2>/dev/null | sort | sha256sum | cut -d' ' -f1)"
38
+ fi
39
+ local rd_state=""
40
+ if [[ -d "$PROJECT_ROOT/.somi/rd" ]]; then
41
+ rd_state="$(find "$PROJECT_ROOT/.somi/rd" -maxdepth 2 -name 'README.md' -printf '%T@ %p\n' 2>/dev/null | sort | sha256sum | cut -d' ' -f1)"
42
+ fi
43
+ printf '%s:%s:%s' "$plans_state" "$reviews_state" "$rd_state"
44
+ }
45
+
46
+ CURRENT_SIG="$(compute_signature)"
47
+ LAST_SIG=""
48
+ if [[ -f "$STATE_FILE" ]]; then
49
+ LAST_SIG="$(cat "$STATE_FILE" 2>/dev/null || true)"
50
+ fi
51
+ echo "$CURRENT_SIG" > "$STATE_FILE"
52
+
53
+ # Active work-item state pulled from .somi/plans/<slug>/progress.md (if present).
54
+ PLAN_HINT=""
55
+ if [[ -d "$PROJECT_ROOT/.somi/plans" ]]; then
56
+ in_progress=()
57
+ while IFS= read -r progress_file; do
58
+ [[ -z "$progress_file" ]] && continue
59
+ if grep -qiE '^[[:space:]]*<?in-progress>?[[:space:]]*$' "$progress_file" 2>/dev/null \
60
+ || grep -qiE 'status:[[:space:]]*`?in-progress`?' "$progress_file" 2>/dev/null; then
61
+ slug="$(basename "$(dirname "$progress_file")")"
62
+ in_progress+=("$slug")
63
+ fi
64
+ done < <(find "$PROJECT_ROOT/.somi/plans" -maxdepth 2 -name 'progress.md' 2>/dev/null)
65
+ if (( ${#in_progress[@]} == 1 )); then
66
+ PLAN_HINT=$'\n- Active work item: `.somi/plans/'"${in_progress[0]}"$'/`. Follow its `spec.md` and active iteration in `phases/`; update `progress.md` / `diary.md` as work proceeds.'
67
+ elif (( ${#in_progress[@]} > 1 )); then
68
+ PLAN_HINT=$'\n- Multiple in-progress work items in `.somi/plans/`: '"$(IFS=,; echo "${in_progress[*]}")"$'. Confirm with the user which one applies before coding.'
69
+ fi
70
+ fi
71
+
72
+ # Active discovery state pulled from .somi/rd/<slug>/README.md (if present).
73
+ RD_HINT=""
74
+ if [[ -d "$PROJECT_ROOT/.somi/rd" ]]; then
75
+ rd_active=()
76
+ rd_ready=()
77
+ while IFS= read -r rd_readme; do
78
+ [[ -z "$rd_readme" ]] && continue
79
+ slug="$(basename "$(dirname "$rd_readme")")"
80
+ if grep -qiE 'status:[[:space:]]*`?(researching|drafting|awaiting-verification)`?' "$rd_readme" 2>/dev/null; then
81
+ rd_active+=("$slug")
82
+ elif grep -qiE 'status:[[:space:]]*`?ready-for-planning`?' "$rd_readme" 2>/dev/null; then
83
+ rd_ready+=("$slug")
84
+ fi
85
+ done < <(find "$PROJECT_ROOT/.somi/rd" -maxdepth 2 -name 'README.md' 2>/dev/null)
86
+ if (( ${#rd_active[@]} >= 1 )); then
87
+ RD_HINT=$'\n- Active discovery in `.somi/rd/`: '"$(IFS=,; echo "${rd_active[*]}")"$'. This is requirements-engineering work (`/discover`): research the competition, author the R&D doc set, verify crossroads, before handing to `/plan`.'
88
+ elif (( ${#rd_ready[@]} == 1 )); then
89
+ RD_HINT=$'\n- R&D foundation ready in `.somi/rd/'"${rd_ready[0]}"$'/`. `/plan '"${rd_ready[0]}"$'` will consume its SRS/FRD as the requirements source and SDD/TDD as architectural direction.'
90
+ fi
91
+ fi
92
+
93
+ # Loose-end detection (runs every turn; cheap and only fires when something to nudge).
94
+ NUDGES=()
95
+ if command -v git >/dev/null 2>&1 && [[ -d "$PROJECT_ROOT/.git" ]]; then
96
+ # TODO(claude) / FIXME(claude) markers in working tree or staged changes.
97
+ if git -C "$PROJECT_ROOT" diff --no-color --unified=0 HEAD 2>/dev/null \
98
+ | grep -E '^\+.*(TODO\(claude\)|TODO\(agent\)|FIXME\(claude\))' -q; then
99
+ NUDGES+=("Detected new TODO(claude)/FIXME(claude) markers in the diff against HEAD. List them explicitly as 'not done' in your next summary.")
100
+ fi
101
+ # Stray .bak / scratch files in working tree.
102
+ if git -C "$PROJECT_ROOT" status --porcelain 2>/dev/null \
103
+ | grep -E '^\?\? .*(\.bak|\.orig|scratch_)' -q; then
104
+ NUDGES+=("Detected scratch / .bak files in working tree. Clean them up before declaring done.")
105
+ fi
106
+ fi
107
+
108
+ # Decide whether to emit the reminder block.
109
+ EMIT_REMINDER="no"
110
+ if [[ -z "$LAST_SIG" ]] || [[ "$LAST_SIG" != "$CURRENT_SIG" ]]; then
111
+ EMIT_REMINDER="yes"
112
+ fi
113
+
114
+ # Build the final context payload.
115
+ PARTS=()
116
+ if [[ "$EMIT_REMINDER" == "yes" ]]; then
117
+ PARTS+=("somi is active. Reminders:
118
+ - Follow rules/CLAUDE.md priorities: security > correctness > maintainability > performance > convenience.
119
+ - Plan before coding non-trivial work. Code from the plan, not around it.
120
+ - Surface tradeoffs and shortcuts in plain text; never silently compromise.
121
+ - Hooks may deny dangerous bash, secret writes, protected paths, and unsanctioned dep installs — do not work around them.${PLAN_HINT}${RD_HINT}")
122
+ fi
123
+
124
+ if (( ${#NUDGES[@]} > 0 )); then
125
+ NUDGE_BLOCK="somi loose-end check:"
126
+ for n in "${NUDGES[@]}"; do
127
+ NUDGE_BLOCK+=$'\n - '"$n"
128
+ done
129
+ PARTS+=("$NUDGE_BLOCK")
130
+ fi
131
+
132
+ if (( ${#PARTS[@]} > 0 )); then
133
+ CONTEXT=""
134
+ for p in "${PARTS[@]}"; do
135
+ if [[ -n "$CONTEXT" ]]; then
136
+ CONTEXT+=$'\n\n'
137
+ fi
138
+ CONTEXT+="$p"
139
+ done
140
+ somi::context "UserPromptSubmit" "$CONTEXT"
141
+ fi
142
+
143
+ exit 0
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@skathio/somi",
3
+ "version": "1.0.0",
4
+ "scripts": {
5
+ "test": "bash scripts/validate.sh"
6
+ },
7
+ "description": "SoMi — multi-agent engineering workflow system: plan, code, review — with SOLID/OWASP guardrails, deterministic hooks, and a global ruleset.",
8
+ "keywords": [
9
+ "workflow",
10
+ "agents",
11
+ "planning",
12
+ "code-review",
13
+ "security",
14
+ "owasp",
15
+ "solid",
16
+ "clean-code",
17
+ "engineering",
18
+ "claude-code",
19
+ "copilot"
20
+ ],
21
+ "author": {
22
+ "name": "SoMi contributors",
23
+ "url": "https://github.com/skathio/somi"
24
+ },
25
+ "license": "MIT",
26
+ "homepage": "https://github.com/skathio/somi",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "https://github.com/skathio/somi.git"
30
+ },
31
+ "bugs": {
32
+ "url": "https://github.com/skathio/somi/issues"
33
+ },
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "files": [
38
+ "agents/",
39
+ "commands/",
40
+ "skills/",
41
+ "rules/",
42
+ "hooks/",
43
+ "templates/",
44
+ "examples/",
45
+ ".claude-plugin/",
46
+ ".copilot-extension/",
47
+ ".claude/",
48
+ "VERSION",
49
+ "LICENSE"
50
+ ]
51
+ }
@@ -0,0 +1,48 @@
1
+ # 00 — Priorities
2
+
3
+ The order in which you resolve tension between competing concerns. Memorize this list; refer to it explicitly
4
+ when documenting tradeoffs.
5
+
6
+ ## The priority stack
7
+
8
+ 1. **Security** — the system must not become more attackable.
9
+ 2. **Correctness** — the system must do what it claims, under expected and edge inputs.
10
+ 3. **Maintainability** — future humans must be able to read, change, and reason about it.
11
+ 4. **Performance & cost** — within the envelope the system needs; not abstract micro-optimization.
12
+ 5. **Convenience** — developer ergonomics, brevity, "clean-looking" diffs.
13
+
14
+ Higher items can override lower items. Lower items **cannot** override higher items without explicit human
15
+ sign-off captured in the artifact (PR description, ADR, plan).
16
+
17
+ ## Uncertainty handling
18
+
19
+ - If you don't know, say so. Use language like "I'm not sure whether X — I'd need to verify by Y."
20
+ - Do not generate code that depends on a fact you have not verified. The cost of pausing to check
21
+ is small; the cost of wrong-but-plausible code in production is large.
22
+ - When you propose a fact ("this library handles X by Y"), include how you know — file path, doc URL,
23
+ or "by reading the source". If you can't justify it, mark it as an assumption.
24
+
25
+ ## Escalation
26
+
27
+ Escalate to the human (stop work, ask) when any of these are true:
28
+
29
+ - A required change touches **auth, authorization, crypto, secret handling, or PII**.
30
+ - A required change crosses a **service boundary**, contract, or public API.
31
+ - The work would require a **destructive or irreversible operation** (data deletion, schema drop, force-push).
32
+ - The plan does not exist, the request is ambiguous, **and** the cost of going wrong is more than ~1 hour
33
+ of rework.
34
+ - The change would silently break **backward compatibility** for a published interface.
35
+
36
+ ## Reversibility
37
+
38
+ Prefer reversible actions. When asked to do something irreversible:
39
+
40
+ - **Pause and confirm scope** in writing, even if previously approved at a high level.
41
+ - **Stage** in a way that can be aborted (feature flag, dark-launched, copy-then-cut, rather than cut).
42
+ - **Record** the action in the artifact so a future human can find out *what* changed and *why*.
43
+
44
+ ## Speed is a side effect
45
+
46
+ Going fast is the **result** of getting (1)–(3) right, not a competing axis. Cutting maintainability to
47
+ ship sooner usually slows the next ten changes. When you are tempted to take a shortcut, name it explicitly
48
+ and let the human decide.
@@ -0,0 +1,87 @@
1
+ # 10 — SOLID, operationalized
2
+
3
+ The point of SOLID is not "five things to recite" — it is "five questions to ask before a design ossifies".
4
+ Use these questions during planning, while coding, and during review.
5
+
6
+ ## S — Single Responsibility
7
+
8
+ > A module should have one reason to change.
9
+
10
+ **Ask:** Who is the user of this module, and what would make *that user* want it modified?
11
+
12
+ **Smells:**
13
+ - A class whose method names cluster into two unrelated themes (e.g., `parseInput` + `sendEmail`).
14
+ - A function with an "and" in a one-sentence description.
15
+ - A file whose imports come from two unrelated layers (HTTP + database driver in the same file).
16
+
17
+ **Fix:** Split along the **axis of change**, not along noun categories. "Authentication" and "User profile"
18
+ are two reasons to change, even though both are about users.
19
+
20
+ ## O — Open/Closed
21
+
22
+ > Open for extension, closed for modification.
23
+
24
+ **Ask:** When the next requirement lands, can I add behavior **without** editing existing code?
25
+
26
+ **Smells:**
27
+ - A growing `switch`/`if-else` that adds a branch every time a new variant is introduced.
28
+ - "Just one more `if`" in a function that already has five.
29
+
30
+ **Fix:** Polymorphism, strategy pattern, registry pattern, or table-driven dispatch — only when the variation
31
+ is real, not speculative. **Do not** introduce a strategy interface for a single concrete case.
32
+
33
+ **Anti-pattern to avoid:** Open/Closed at the cost of readability. Three `if` branches are fine.
34
+
35
+ ## L — Liskov Substitution
36
+
37
+ > Subtypes must be usable wherever their base type is expected, without breaking invariants.
38
+
39
+ **Ask:** Does the subclass strengthen preconditions or weaken postconditions of the parent?
40
+
41
+ **Smells:**
42
+ - A subclass that throws `NotSupportedException` for a parent's method.
43
+ - A subclass that requires extra setup callers can't know about.
44
+ - "It's-a" relationships that are actually "is-implemented-using".
45
+
46
+ **Fix:** Prefer composition. If `Square extends Rectangle` makes you want to override `setWidth`, the
47
+ relationship is wrong.
48
+
49
+ ## I — Interface Segregation
50
+
51
+ > Clients should not depend on methods they don't use.
52
+
53
+ **Ask:** What does each caller actually need? Is the interface they depend on shaped like *their* need
54
+ or like the implementer's convenience?
55
+
56
+ **Smells:**
57
+ - A 12-method interface where most callers use 2 methods.
58
+ - "God" interfaces (`IService`, `IManager`) with grab-bag method lists.
59
+ - Tests that have to mock five methods to exercise one path.
60
+
61
+ **Fix:** Smaller, role-shaped interfaces. Compose them at the implementation site.
62
+
63
+ ## D — Dependency Inversion
64
+
65
+ > High-level policy should not depend on low-level mechanism. Both should depend on abstractions.
66
+
67
+ **Ask:** Does the business rule know about Postgres, S3, or HTTP? It shouldn't.
68
+
69
+ **Smells:**
70
+ - Domain logic imports a database driver.
71
+ - Use-cases instantiate adapters directly with `new`.
72
+ - Tests can't run without a real network or filesystem.
73
+
74
+ **Fix:** Inject collaborators. The domain defines the interface (in the domain's language), and the
75
+ infrastructure layer implements it. **Do not** invert dependencies that don't need to vary —
76
+ abstractions you never swap are just extra indirection.
77
+
78
+ ---
79
+
80
+ ## Meta-rules
81
+
82
+ - **YAGNI beats SOLID** when the variation is hypothetical. SOLID is a response to *actual* change pressure,
83
+ not a preemptive design tax.
84
+ - **Three is the magic number.** Don't abstract until you have three concrete cases. Two cases is a
85
+ coincidence; three is a pattern.
86
+ - **Refactoring under green** — when you spot a SOLID violation in code you're touching, raise it.
87
+ If the fix is small and the tests cover it, do it now. If it isn't, log it as follow-up work in the plan.