@skathio/somi 1.1.1 → 2.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 +8 -8
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.copilot-extension/extension.json +11 -2
- package/.copilot-extension/marketplace.json +1 -1
- package/README.md +21 -4
- package/VERSION +1 -1
- package/agents/coder.md +8 -3
- package/agents/designer.md +22 -7
- package/agents/discovery-analyst.md +11 -0
- package/agents/planner.md +69 -9
- package/agents/refactorer.md +3 -1
- package/agents/reviewer.md +4 -0
- package/commands/adopt.md +77 -0
- package/commands/atlas.md +83 -0
- package/commands/code-loop.md +70 -44
- package/commands/code-parallel.md +3 -1
- package/commands/code.md +8 -2
- package/commands/debug.md +136 -0
- package/commands/design.md +17 -7
- package/commands/discover.md +23 -18
- package/commands/impact.md +74 -0
- package/commands/incident.md +83 -0
- package/commands/plan-loop.md +44 -19
- package/commands/plan.md +38 -26
- package/commands/pr.md +82 -0
- package/commands/release-readiness.md +70 -0
- package/commands/review-panel.md +5 -0
- package/commands/review.md +19 -0
- package/commands/ship-loop.md +18 -10
- package/commands/ship.md +4 -2
- package/commands/somi.md +85 -0
- package/commands/upgrade.md +81 -0
- package/hooks/hooks.json +8 -8
- package/hooks/lib/common.mjs +328 -0
- package/hooks/post-tool/audit-log.mjs +93 -0
- package/hooks/post-tool/lint-changed-files.mjs +212 -0
- package/hooks/pre-tool/block-dangerous-bash.mjs +382 -0
- package/hooks/pre-tool/block-secret-writes.mjs +96 -0
- package/hooks/pre-tool/gate-dep-install.mjs +229 -0
- package/hooks/pre-tool/guard-protected-paths.mjs +157 -0
- package/hooks/session-start/detect-repo-instructions.mjs +264 -0
- package/hooks/user-prompt-submit/inject-workflow-context.mjs +432 -0
- package/package.json +6 -1
- package/rules/50-collaboration.md +4 -1
- package/scripts/somi-check.mjs +243 -0
- package/scripts/somi-findings.mjs +307 -0
- package/scripts/somi-loop.mjs +354 -0
- package/scripts/validate.sh +120 -0
- package/skills/clean-code/SKILL.md +1 -1
- package/templates/ATLAS.md.tmpl +75 -0
- package/templates/BRIEF.md.tmpl +20 -4
- package/templates/DOD.md.tmpl +2 -2
- package/templates/PHASE.md.tmpl +1 -1
- package/templates/RCA.md.tmpl +53 -0
- package/templates/RD-README.md.tmpl +2 -2
- package/templates/SDD.md.tmpl +4 -4
- package/templates/SOMI-README.md.tmpl +20 -3
- package/templates/SRS.md.tmpl +1 -1
- package/templates/TDD.md.tmpl +5 -5
- package/tests/hooks/cases/audit-log.json +21 -0
- package/tests/hooks/cases/block-dangerous-bash.json +166 -0
- package/tests/hooks/cases/block-secret-writes.json +22 -0
- package/tests/hooks/cases/detect-repo-instructions.json +84 -0
- package/tests/hooks/cases/gate-dep-install.json +42 -0
- package/tests/hooks/cases/guard-protected-paths.json +30 -0
- package/tests/hooks/cases/inject-workflow-context.json +126 -0
- package/tests/hooks/cases/lint-changed-files.json +120 -0
- package/tests/hooks/run.sh +362 -0
- package/tests/scripts/goldens/somi-findings.json +336 -0
- package/tests/scripts/goldens/somi-loop.json +168 -0
- package/tests/scripts/run.sh +389 -0
- package/hooks/lib/common.sh +0 -120
- package/hooks/post-tool/audit-log.sh +0 -40
- package/hooks/post-tool/lint-changed-files.sh +0 -80
- package/hooks/pre-tool/block-dangerous-bash.sh +0 -83
- package/hooks/pre-tool/block-secret-writes.sh +0 -83
- package/hooks/pre-tool/gate-dep-install.sh +0 -72
- package/hooks/pre-tool/guard-protected-paths.sh +0 -74
- package/hooks/session-start/detect-repo-instructions.sh +0 -73
- package/hooks/user-prompt-submit/inject-workflow-context.sh +0 -143
|
@@ -1,83 +0,0 @@
|
|
|
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
|
|
@@ -1,83 +0,0 @@
|
|
|
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
|
|
@@ -1,72 +0,0 @@
|
|
|
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
|
|
@@ -1,74 +0,0 @@
|
|
|
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
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# SessionStart hook — detect repo-local agent/instruction files and surface them.
|
|
3
|
-
#
|
|
4
|
-
# SoMi's MAX→ECO economy is "respect repo conventions as context": when a project
|
|
5
|
-
# ships its own instructions (CLAUDE.md / AGENTS.md / copilot-instructions /
|
|
6
|
-
# .cursorrules) or its own subagents (.claude/agents/), SoMi's MAX actions should
|
|
7
|
-
# read them once and fold the relevant conventions into the work-item brief.md, so
|
|
8
|
-
# the ECO tier inherits them without re-reading. Repo-local instructions WIN over
|
|
9
|
-
# SoMi defaults where they conflict; SoMi does NOT auto-invoke foreign agents.
|
|
10
|
-
#
|
|
11
|
-
# This hook only *surfaces* what exists (paths + a one-line directive) — it does not
|
|
12
|
-
# read or ingest file contents (that's the MAX agent's job, and keeps this cheap).
|
|
13
|
-
# It fires once per session and stays silent when nothing repo-local is present.
|
|
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
|
-
# Some hosts pass an unexpanded literal; fall back to the resolvable cwd.
|
|
25
|
-
[[ "$PROJECT_ROOT" == *'${'* ]] && PROJECT_ROOT="$PWD"
|
|
26
|
-
|
|
27
|
-
FOUND=()
|
|
28
|
-
|
|
29
|
-
# Root-level instruction files the consumer repo may ship.
|
|
30
|
-
for f in "CLAUDE.md" "AGENTS.md" ".cursorrules" ".github/copilot-instructions.md"; do
|
|
31
|
-
[[ -f "$PROJECT_ROOT/$f" ]] && FOUND+=("$f")
|
|
32
|
-
done
|
|
33
|
-
|
|
34
|
-
# Nested CLAUDE.md / AGENTS.md (cap depth and count so this stays cheap and never
|
|
35
|
-
# wanders into .git / node_modules / .somi).
|
|
36
|
-
while IFS= read -r nested; do
|
|
37
|
-
[[ -z "$nested" ]] && continue
|
|
38
|
-
rel="${nested#"$PROJECT_ROOT"/}"
|
|
39
|
-
FOUND+=("$rel")
|
|
40
|
-
done < <(
|
|
41
|
-
find "$PROJECT_ROOT" -maxdepth 3 \
|
|
42
|
-
\( -path "$PROJECT_ROOT/.git" -o -path "$PROJECT_ROOT/node_modules" \
|
|
43
|
-
-o -path "$PROJECT_ROOT/.somi" -o -path "$PROJECT_ROOT/vendor" \) -prune -o \
|
|
44
|
-
-mindepth 2 -type f \( -name 'CLAUDE.md' -o -name 'AGENTS.md' \) -print 2>/dev/null \
|
|
45
|
-
| head -n 10
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
# Repo-local subagents (note presence only — never auto-invoke them).
|
|
49
|
-
REPO_AGENTS=""
|
|
50
|
-
if [[ -d "$PROJECT_ROOT/.claude/agents" ]]; then
|
|
51
|
-
count="$(find "$PROJECT_ROOT/.claude/agents" -maxdepth 1 -name '*.md' -type f 2>/dev/null | wc -l | tr -d ' ')"
|
|
52
|
-
[[ "${count:-0}" -gt 0 ]] && REPO_AGENTS=".claude/agents/ (${count} repo-local subagent definition(s))"
|
|
53
|
-
fi
|
|
54
|
-
|
|
55
|
-
if (( ${#FOUND[@]} == 0 )) && [[ -z "$REPO_AGENTS" ]]; then
|
|
56
|
-
exit 0
|
|
57
|
-
fi
|
|
58
|
-
|
|
59
|
-
MSG="somi repo-awareness — this repository ships its own instructions/agents. Respect them as context:"
|
|
60
|
-
if (( ${#FOUND[@]} > 0 )); then
|
|
61
|
-
# De-duplicate while preserving order.
|
|
62
|
-
seen=""
|
|
63
|
-
for f in "${FOUND[@]}"; do
|
|
64
|
-
case " $seen " in *" $f "*) continue;; esac
|
|
65
|
-
seen+=" $f"
|
|
66
|
-
MSG+=$'\n - '"$f"
|
|
67
|
-
done
|
|
68
|
-
fi
|
|
69
|
-
[[ -n "$REPO_AGENTS" ]] && MSG+=$'\n - '"$REPO_AGENTS"
|
|
70
|
-
MSG+=$'\nMAX actions (/discover, /design, /refactor analysis, and /plan on a cold start) should read these once and distil the relevant conventions into the work item'\''s brief.md / context.md so the ECO tier inherits them without re-reading. Repo-local instructions WIN over SoMi defaults where they conflict. Do NOT auto-invoke the repo'\''s own agents — surface them for the user to opt into.'
|
|
71
|
-
|
|
72
|
-
somi::context "SessionStart" "$MSG"
|
|
73
|
-
exit 0
|
|
@@ -1,143 +0,0 @@
|
|
|
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
|