@skathio/somi 4.1.0 → 5.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-plugin/icon.png +0 -0
- package/.claude-plugin/marketplace.json +8 -3
- package/.claude-plugin/plugin.json +9 -10
- package/.copilot-extension/extension.json +32 -40
- package/.copilot-extension/marketplace.json +8 -3
- package/README.md +83 -228
- package/VERSION +1 -1
- package/agents/somi-reviewer.md +21 -40
- package/agents/somi-security-reviewer.md +16 -90
- package/agents/somi-worker-high.md +11 -0
- package/agents/somi-worker-low.md +11 -0
- package/agents/somi-worker-medium.md +11 -0
- package/agents/somi.md +8 -75
- package/commands/somi-config.md +5 -14
- package/commands/somi-deliver.md +11 -0
- package/commands/somi-quality.md +10 -0
- package/commands/somi-review.md +10 -0
- package/commands/somi-status.md +11 -0
- package/commands/somi.md +10 -0
- package/hooks/hooks.json +28 -23
- package/hooks/lib/common.mjs +45 -34
- package/hooks/pre-tool/apply-tier.mjs +31 -0
- package/hooks/pre-tool/block-dangerous-bash.mjs +15 -0
- package/hooks/pre-tool/gate-dep-install.mjs +2 -2
- package/hooks/pre-tool/guard-protected-paths.mjs +9 -16
- package/hooks/pre-tool/guard-tier-config.mjs +17 -0
- package/hooks/pre-tool/reviewers-read-only.mjs +11 -0
- package/hooks/session-start/inject-digest.mjs +51 -0
- package/hooks/stop/review-due.mjs +40 -0
- package/hooks/user-prompt/capture-prompt.mjs +17 -0
- package/library/lenses/architecture.md +1 -0
- package/library/lenses/test-strategy.md +1 -0
- package/library/roles/accessibility.md +1 -0
- package/library/roles/answer.md +1 -0
- package/library/roles/atlas.md +1 -0
- package/library/roles/build.md +1 -0
- package/library/roles/debug.md +6 -0
- package/library/roles/design.md +1 -0
- package/library/roles/discover.md +1 -0
- package/library/roles/incident.md +1 -0
- package/library/roles/migrate.md +1 -0
- package/library/roles/perf.md +1 -0
- package/library/roles/plan.md +1 -0
- package/library/roles/refactor.md +1 -0
- package/library/roles/review.md +1 -0
- package/library/roles/security-review.md +1 -0
- package/library/roles/upgrade.md +1 -0
- package/library/skills/accessibility.md +16 -0
- package/library/skills/ci-infra-gotchas.md +12 -0
- package/library/skills/perf-method.md +10 -0
- package/library/skills/secure-coding.md +18 -0
- package/library/skills/testing-checklist.md +16 -0
- package/library/skills/threat-modeling.md +10 -0
- package/package.json +12 -17
- package/profiles/claude.json +21 -0
- package/profiles/copilot.json +5 -0
- package/rules/digest.md +40 -0
- package/scripts/check-links.mjs +65 -76
- package/scripts/lib/advisor.mjs +207 -0
- package/scripts/lib/check.mjs +165 -0
- package/scripts/lib/copilot-workflow.mjs +41 -0
- package/scripts/lib/doctor.mjs +91 -0
- package/scripts/lib/gates.mjs +69 -0
- package/scripts/lib/git-tree.mjs +201 -0
- package/scripts/lib/init.mjs +23 -0
- package/scripts/lib/ledger.mjs +38 -0
- package/scripts/lib/mcp-project-root.mjs +63 -67
- package/scripts/lib/migrate.mjs +73 -0
- package/scripts/lib/path-facts.mjs +2 -2
- package/scripts/lib/path-safety.mjs +6 -134
- package/scripts/lib/plan.mjs +69 -0
- package/scripts/lib/policy.mjs +103 -0
- package/scripts/lib/pr.mjs +28 -0
- package/scripts/lib/prompt.mjs +72 -0
- package/scripts/lib/quality/clones.mjs +76 -0
- package/scripts/lib/quality/css.mjs +43 -0
- package/scripts/lib/quality/gate.mjs +230 -0
- package/scripts/lib/quality/limits.mjs +73 -0
- package/scripts/lib/quality/metrics.mjs +159 -0
- package/scripts/lib/quality/parse.mjs +73 -0
- package/scripts/lib/quality/repo.mjs +69 -0
- package/scripts/lib/quality/run.mjs +38 -0
- package/scripts/lib/reviews.mjs +132 -0
- package/scripts/lib/routes.mjs +108 -0
- package/scripts/lib/setup.mjs +34 -0
- package/scripts/lib/shards.mjs +166 -0
- package/scripts/lib/signals.mjs +110 -0
- package/scripts/lib/state.mjs +42 -0
- package/scripts/lib/tiers.mjs +42 -0
- package/scripts/lib/update-notice.mjs +48 -0
- package/scripts/lib/views.mjs +62 -0
- package/scripts/lib/workflows.mjs +56 -0
- package/scripts/somi-mcp.mjs +181 -323
- package/scripts/somi.mjs +208 -0
- package/scripts/vendor/tree-sitter/LICENSE.vscode-tree-sitter-wasm +21 -0
- package/scripts/vendor/tree-sitter/LICENSE.web-tree-sitter +21 -0
- package/scripts/vendor/tree-sitter/cgmanifest.vscode-tree-sitter-wasm.json +16 -0
- package/scripts/vendor/tree-sitter/manifest.json +59 -0
- package/scripts/vendor/tree-sitter/package.json +3 -0
- package/scripts/vendor/tree-sitter/tree-sitter-css.wasm +0 -0
- package/scripts/vendor/tree-sitter/tree-sitter-javascript.wasm +0 -0
- package/scripts/vendor/tree-sitter/tree-sitter-tsx.wasm +0 -0
- package/scripts/vendor/tree-sitter/tree-sitter-typescript.wasm +0 -0
- package/scripts/vendor/tree-sitter/web-tree-sitter.js +4081 -0
- package/scripts/vendor/tree-sitter/web-tree-sitter.wasm +0 -0
- package/skills/somi-expertise/SKILL.md +6 -0
- package/workflows/deliver-stages.js +81 -0
- package/.claude/settings.json +0 -131
- package/agents/somi-architecture-reviewer.md +0 -101
- package/agents/somi-atlas.md +0 -100
- package/agents/somi-coder.md +0 -60
- package/agents/somi-designer.md +0 -36
- package/agents/somi-discovery-analyst.md +0 -57
- package/agents/somi-flow.md +0 -47
- package/agents/somi-general.md +0 -36
- package/agents/somi-impact.md +0 -95
- package/agents/somi-incident.md +0 -94
- package/agents/somi-plan-reviewer.md +0 -68
- package/agents/somi-planner.md +0 -57
- package/agents/somi-pr.md +0 -99
- package/agents/somi-refactor-designer.md +0 -81
- package/agents/somi-refactorer.md +0 -99
- package/agents/somi-sdlc-reviewer.md +0 -67
- package/agents/somi-test-strategist.md +0 -87
- package/commands/adopt.md +0 -14
- package/commands/architecture-review.md +0 -19
- package/commands/atlas.md +0 -19
- package/commands/code-loop.md +0 -19
- package/commands/code-parallel.md +0 -19
- package/commands/code.md +0 -19
- package/commands/debug.md +0 -19
- package/commands/design.md +0 -19
- package/commands/discover.md +0 -19
- package/commands/impact.md +0 -19
- package/commands/incident.md +0 -19
- package/commands/plan-loop.md +0 -19
- package/commands/plan.md +0 -19
- package/commands/pr.md +0 -19
- package/commands/refactor-design.md +0 -19
- package/commands/refactor.md +0 -19
- package/commands/release-readiness.md +0 -19
- package/commands/review-panel.md +0 -19
- package/commands/review.md +0 -19
- package/commands/security-review.md +0 -19
- package/commands/ship-loop.md +0 -19
- package/commands/ship.md +0 -19
- package/commands/test-strategy.md +0 -19
- package/commands/upgrade.md +0 -19
- package/examples/README.md +0 -19
- package/examples/code-review-example.md +0 -88
- package/examples/discovery-example.md +0 -200
- package/examples/feature-plan-example.md +0 -377
- package/examples/full-pipeline-example.md +0 -188
- package/examples/sample-consumer/.claude/settings.json +0 -29
- package/examples/sample-consumer/CLAUDE.md +0 -78
- package/examples/sample-consumer/README.md +0 -102
- package/hooks/post-tool/lint-changed-files.mjs +0 -209
- package/hooks/pre-tool/guard-cost-lowering.mjs +0 -192
- package/hooks/session-start/detect-repo-instructions.mjs +0 -287
- package/hooks/session-start/ensure-default-config.mjs +0 -113
- package/hooks/user-prompt-submit/inject-workflow-context.mjs +0 -580
- package/rules/00-priorities.md +0 -48
- package/rules/10-solid.md +0 -87
- package/rules/20-clean-code.md +0 -62
- package/rules/30-security-owasp.md +0 -83
- package/rules/40-engineering-practices.md +0 -65
- package/rules/50-collaboration.md +0 -114
- package/rules/99-overrides.md +0 -52
- package/rules/CLAUDE.md +0 -200
- package/scripts/check-session-artefacts.mjs +0 -149
- package/scripts/check-size-budget.mjs +0 -137
- package/scripts/generate-digest.mjs +0 -176
- package/scripts/lib/agent-info.mjs +0 -85
- package/scripts/lib/agent-registry.mjs +0 -92
- package/scripts/lib/cost-ceiling.mjs +0 -328
- package/scripts/lib/cost-config-edit.mjs +0 -102
- package/scripts/lib/cost-config.mjs +0 -64
- package/scripts/lib/cost-defaults.mjs +0 -53
- package/scripts/lib/cost-lowering.mjs +0 -89
- package/scripts/lib/cost-model.mjs +0 -110
- package/scripts/lib/dispatch-resolver.mjs +0 -243
- package/scripts/lib/escalation-facts.mjs +0 -146
- package/scripts/lib/escalation.mjs +0 -129
- package/scripts/lib/findings-ledger.mjs +0 -241
- package/scripts/lib/install-text.mjs +0 -97
- package/scripts/lib/loop-caps.mjs +0 -140
- package/scripts/lib/loop-diff.mjs +0 -38
- package/scripts/lib/loop-dispatch.mjs +0 -19
- package/scripts/lib/loop-engine.mjs +0 -226
- package/scripts/lib/loop-escalate.mjs +0 -49
- package/scripts/lib/loop-exit.mjs +0 -47
- package/scripts/lib/loop-notes-compact.mjs +0 -72
- package/scripts/lib/loop-notes.mjs +0 -278
- package/scripts/lib/loop-review.mjs +0 -395
- package/scripts/lib/loop-state.mjs +0 -44
- package/scripts/lib/loop-step-close.mjs +0 -75
- package/scripts/lib/loop-step-kit.mjs +0 -179
- package/scripts/lib/loop-step-review.mjs +0 -140
- package/scripts/lib/loop-step-tool.mjs +0 -89
- package/scripts/lib/loop-step.mjs +0 -301
- package/scripts/lib/run-budget.mjs +0 -28
- package/scripts/lib/run-card.mjs +0 -73
- package/scripts/lib/size-tier.mjs +0 -184
- package/scripts/lib/tier-record.mjs +0 -82
- package/scripts/size-budget-overrides.json +0 -58
- package/scripts/somi-card.mjs +0 -39
- package/scripts/somi-check.mjs +0 -237
- package/scripts/somi-config.mjs +0 -421
- package/scripts/somi-dispatch.mjs +0 -141
- package/scripts/somi-findings.mjs +0 -100
- package/scripts/somi-loop.mjs +0 -128
- package/scripts/somi-tier.mjs +0 -393
- package/scripts/validate.sh +0 -653
- package/skills/api-design/SKILL.md +0 -147
- package/skills/clean-code/SKILL.md +0 -142
- package/skills/flow-adopt/SKILL.md +0 -92
- package/skills/flow-architecture-review/SKILL.md +0 -94
- package/skills/flow-atlas/SKILL.md +0 -34
- package/skills/flow-code/SKILL.md +0 -167
- package/skills/flow-code-loop/SKILL.md +0 -263
- package/skills/flow-code-parallel/SKILL.md +0 -160
- package/skills/flow-debug/SKILL.md +0 -141
- package/skills/flow-design/SKILL.md +0 -170
- package/skills/flow-discover/SKILL.md +0 -204
- package/skills/flow-impact/SKILL.md +0 -35
- package/skills/flow-incident/SKILL.md +0 -49
- package/skills/flow-plan/SKILL.md +0 -254
- package/skills/flow-plan-loop/SKILL.md +0 -254
- package/skills/flow-pr/SKILL.md +0 -34
- package/skills/flow-refactor/SKILL.md +0 -58
- package/skills/flow-refactor-design/SKILL.md +0 -97
- package/skills/flow-release-readiness/SKILL.md +0 -82
- package/skills/flow-review/SKILL.md +0 -193
- package/skills/flow-review-panel/SKILL.md +0 -154
- package/skills/flow-security-review/SKILL.md +0 -83
- package/skills/flow-ship/SKILL.md +0 -125
- package/skills/flow-ship-loop/SKILL.md +0 -274
- package/skills/flow-somi-config/SKILL.md +0 -142
- package/skills/flow-status/SKILL.md +0 -43
- package/skills/flow-test-strategy/SKILL.md +0 -83
- package/skills/flow-upgrade/SKILL.md +0 -82
- package/skills/market-research/SKILL.md +0 -125
- package/skills/observability/SKILL.md +0 -133
- package/skills/owasp-defense/SKILL.md +0 -141
- package/skills/plan-review/SKILL.md +0 -83
- package/skills/reasoning-craft/SKILL.md +0 -213
- package/skills/requirements-engineering/SKILL.md +0 -137
- package/skills/role-coder/SKILL.md +0 -247
- package/skills/role-designer/SKILL.md +0 -172
- package/skills/role-discovery-analyst/SKILL.md +0 -288
- package/skills/role-planner/SKILL.md +0 -353
- package/skills/role-reviewer/SKILL.md +0 -218
- package/skills/rules/SKILL.md +0 -47
- package/skills/sdlc-process/SKILL.md +0 -74
- package/skills/solid-principles/SKILL.md +0 -143
- package/skills/somi-checkpoint/SKILL.md +0 -95
- package/skills/somi-dispatch/SKILL.md +0 -259
- package/skills/somi-routing/SKILL.md +0 -158
- package/skills/testing-playbook/SKILL.md +0 -133
- package/skills/threat-modeling/SKILL.md +0 -117
- package/templates/ADR.md.tmpl +0 -73
- package/templates/ATLAS.md.tmpl +0 -75
- package/templates/BRD.md.tmpl +0 -68
- package/templates/BRIEF.md.tmpl +0 -119
- package/templates/CONTEXT.md.tmpl +0 -74
- package/templates/DECISIONS.md.tmpl +0 -105
- package/templates/DESIGN.md.tmpl +0 -83
- package/templates/DIARY.md.tmpl +0 -70
- package/templates/DOD.md.tmpl +0 -90
- package/templates/FRD.md.tmpl +0 -64
- package/templates/PHASE.md.tmpl +0 -80
- package/templates/PROGRESS.md.tmpl +0 -63
- package/templates/RCA.md.tmpl +0 -53
- package/templates/RD-README.md.tmpl +0 -70
- package/templates/RESEARCH.md.tmpl +0 -96
- package/templates/REVIEW.md.tmpl +0 -82
- package/templates/SDD.md.tmpl +0 -82
- package/templates/SOMI-README.md.tmpl +0 -83
- package/templates/SPEC.md.tmpl +0 -123
- package/templates/SRS.md.tmpl +0 -85
- package/templates/TDD.md.tmpl +0 -77
- package/tests/hooks/cases/audit-log.json +0 -21
- package/tests/hooks/cases/block-dangerous-bash.json +0 -166
- package/tests/hooks/cases/block-secret-writes.json +0 -140
- package/tests/hooks/cases/detect-repo-instructions.json +0 -105
- package/tests/hooks/cases/gate-dep-install.json +0 -42
- package/tests/hooks/cases/guard-protected-paths.json +0 -222
- package/tests/hooks/cases/inject-workflow-context.json +0 -239
- package/tests/hooks/cases/lint-changed-files.json +0 -120
- package/tests/hooks/run.sh +0 -392
- package/tests/scripts/agent-model-frontmatter.sh +0 -38
- package/tests/scripts/agent-names.sh +0 -77
- package/tests/scripts/check-frontmatter.sh +0 -37
- package/tests/scripts/check-links.sh +0 -105
- package/tests/scripts/check-session-artefacts.sh +0 -60
- package/tests/scripts/check-size-budget.sh +0 -71
- package/tests/scripts/checkpoint-gate.sh +0 -131
- package/tests/scripts/convergence-runner.sh +0 -1514
- package/tests/scripts/cost-ceiling.sh +0 -255
- package/tests/scripts/cost-defaults.sh +0 -130
- package/tests/scripts/cost-hardcap.sh +0 -338
- package/tests/scripts/cost-lowering.sh +0 -261
- package/tests/scripts/cost-model.sh +0 -196
- package/tests/scripts/dispatch-guard.sh +0 -108
- package/tests/scripts/dispatch-line-gate.sh +0 -61
- package/tests/scripts/dispatch-reference-gate.sh +0 -173
- package/tests/scripts/ensure-default-config.sh +0 -162
- package/tests/scripts/escalation.sh +0 -409
- package/tests/scripts/eval-runner.sh +0 -3692
- package/tests/scripts/evals-packaging.sh +0 -224
- package/tests/scripts/fact-sheet.sh +0 -296
- package/tests/scripts/fixtures/legacy-shard-no-schema.json +0 -50
- package/tests/scripts/fixtures/mock-stdin-read-throw.cjs +0 -18
- package/tests/scripts/fixtures/size-tier-cases.json +0 -87
- package/tests/scripts/generate-digest.sh +0 -180
- package/tests/scripts/global-config.sh +0 -167
- package/tests/scripts/goldens/loop-state-breach.json +0 -1
- package/tests/scripts/goldens/loop-state-done.json +0 -1
- package/tests/scripts/goldens/somi-findings.json +0 -336
- package/tests/scripts/goldens/somi-loop.json +0 -168
- package/tests/scripts/lib/adr-shape.mjs +0 -41
- package/tests/scripts/lib/agent-registry-tests.mjs +0 -95
- package/tests/scripts/lib/brief-only-guard.mjs +0 -27
- package/tests/scripts/lib/checkpoint-gate.mjs +0 -91
- package/tests/scripts/lib/digest-marker-coupling.mjs +0 -52
- package/tests/scripts/lib/dispatch-reference-gate.mjs +0 -121
- package/tests/scripts/lib/escalation-facts-tests.mjs +0 -140
- package/tests/scripts/lib/escalation-tests.mjs +0 -154
- package/tests/scripts/lib/findings-ledger-tests.mjs +0 -118
- package/tests/scripts/lib/loop-engine-tests.mjs +0 -287
- package/tests/scripts/lib/loop-escalate-tests.mjs +0 -356
- package/tests/scripts/lib/loop-flow-gate.mjs +0 -173
- package/tests/scripts/lib/loop-notes-tests.mjs +0 -371
- package/tests/scripts/lib/loop-step-cli-tests.mjs +0 -141
- package/tests/scripts/lib/loop-step-close-tests.mjs +0 -351
- package/tests/scripts/lib/loop-step-lenient-tests.mjs +0 -114
- package/tests/scripts/lib/loop-step-state-tests.mjs +0 -127
- package/tests/scripts/lib/loop-step-tests.mjs +0 -499
- package/tests/scripts/lib/loop-step-unwritten-tests.mjs +0 -55
- package/tests/scripts/lib/multipass-dependence.mjs +0 -192
- package/tests/scripts/lib/multipass-source-identity.mjs +0 -243
- package/tests/scripts/lib/path-facts-tests.mjs +0 -198
- package/tests/scripts/lib/path-safety-tests.mjs +0 -201
- package/tests/scripts/lib/reference-pair.mjs +0 -61
- package/tests/scripts/lib/retirement-gate.mjs +0 -172
- package/tests/scripts/lib/run-suites.mjs +0 -139
- package/tests/scripts/lib/shell-embedded-js.mjs +0 -47
- package/tests/scripts/lib/ship-loop-sizing-guard.mjs +0 -52
- package/tests/scripts/lib/site-roadmap-gate.mjs +0 -64
- package/tests/scripts/lib/size-tier-drift.mjs +0 -74
- package/tests/scripts/lib/sizing-score-tests.mjs +0 -210
- package/tests/scripts/lib/sizing-set-tests.mjs +0 -131
- package/tests/scripts/lib/somi-mcp-client.mjs +0 -102
- package/tests/scripts/lib/somi-mcp-config-tests.mjs +0 -92
- package/tests/scripts/lib/somi-mcp-loop-tests.mjs +0 -226
- package/tests/scripts/lib/somi-mcp-tests.mjs +0 -491
- package/tests/scripts/lib/somi-mcp-tier-tests.mjs +0 -64
- package/tests/scripts/lib/somi-mcp-tool-schema.mjs +0 -38
- package/tests/scripts/loop-engine.sh +0 -22
- package/tests/scripts/loop-flow-gate.sh +0 -11
- package/tests/scripts/retirement-gate.sh +0 -306
- package/tests/scripts/review-panel-seats.sh +0 -32
- package/tests/scripts/run-card.sh +0 -57
- package/tests/scripts/run-suites.sh +0 -74
- package/tests/scripts/run.sh +0 -689
- package/tests/scripts/site-roadmap-gate.sh +0 -76
- package/tests/scripts/size-tier.sh +0 -562
- package/tests/scripts/somi-agent-dispatch-contract.sh +0 -224
- package/tests/scripts/somi-config.sh +0 -286
- package/tests/scripts/somi-dispatch.sh +0 -465
- package/tests/scripts/somi-mcp.sh +0 -15
- package/tests/scripts/suite-plan.json +0 -20
|
@@ -1,580 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// hooks/user-prompt-submit/inject-workflow-context.mjs — UserPromptSubmit hook — inject SOMI
|
|
3
|
-
// context on relevant turns.
|
|
4
|
-
//
|
|
5
|
-
// The heaviest hook in the set: several pattern lists and a signature-hash gate. Imports the
|
|
6
|
-
// shared read/context/projectRoot helpers from ../lib/common.mjs rather than reimplementing them.
|
|
7
|
-
//
|
|
8
|
-
// Two responsibilities (unchanged from the original bash hook):
|
|
9
|
-
// 1. Remind the agent of the priority stack and active work-item state.
|
|
10
|
-
// 2. Surface end-of-turn loose ends (TODO(claude) markers, scratch files) on the NEXT user
|
|
11
|
-
// turn — this replaces the old Stop hook, which used an additionalContext channel that Stop
|
|
12
|
-
// events don't actually have.
|
|
13
|
-
//
|
|
14
|
-
// To avoid double-loading content that's already always-on, the reminder block only fires on the
|
|
15
|
-
// first turn of a session OR when work-item state has changed since the last turn (the signature
|
|
16
|
-
// gate below). The loose-end nudges fire whenever there is something to nudge about, completely
|
|
17
|
-
// independent of the reminder gate (see main() — this independence is pinned by the fixture case
|
|
18
|
-
// "nudge-fires-independent-of-suppressed-reminder").
|
|
19
|
-
//
|
|
20
|
-
// === THE TIER 1 / TIER 2 DIGEST SPLIT =========================================================
|
|
21
|
-
//
|
|
22
|
-
// This hook carries rules/CLAUDE.md's always-on digest into a consuming Claude Code project —
|
|
23
|
-
// the only delivery path that reaches one (plugin.json has no `rules` key). An always-on floor and the state-change gate below want opposite behavior from the same
|
|
24
|
-
// mechanism, so emission is split into two independent tiers rather than picking one:
|
|
25
|
-
//
|
|
26
|
-
// Tier 1 — REMINDER_BODY, unconditional, every UserPromptSubmit turn, independent of the
|
|
27
|
-
// signature gate below (the same independence pattern the loose-end nudges already use).
|
|
28
|
-
//
|
|
29
|
-
// Tier 2 — the full eleven-bullet digest, extracted at RUNTIME from rules/CLAUDE.md's
|
|
30
|
-
// `<!-- digest:start/end -->` markers (never hand-copied into this hook as a fourth drift-prone
|
|
31
|
-
// copy), plus planHint/rdHint. Both hints STAY on Tier 2 rather than moving to
|
|
32
|
-
// Tier 1: they are themselves state-change signals (which plan/rd is active), so gating them
|
|
33
|
-
// here preserves their gated behavior rather than making them newly always-on. Tier 2 rides the signature gate exactly as the old single-tier reminder did.
|
|
34
|
-
//
|
|
35
|
-
// Tier 2's bullets are read via pluginRoot() (hooks/lib/common.mjs), not assumed to live at this
|
|
36
|
-
// repo's own path, because this hook also runs inside a CONSUMING project, where SoMi's rules/
|
|
37
|
-
// lives inside the plugin's install directory, not at ./rules/... relative to the consumer's
|
|
38
|
-
// project root. For the same reason, each bullet's trailing citation is rewritten to a bare
|
|
39
|
-
// `` `NN` `` numeric code before injection (stripDigestCitations() below) rather than left as
|
|
40
|
-
// whatever link form rules/CLAUDE.md's canonical file uses — an unmodified normalized link would
|
|
41
|
-
// assert six paths that ENOENT in the consumer's context, on every gated turn. Fails safe:
|
|
42
|
-
// an unresolved pluginRoot(), or a rules/CLAUDE.md missing/malformed digest markers, silently
|
|
43
|
-
// omits Tier 2 rather than throwing — Tier 1 still fires regardless (see buildTier2Digest()).
|
|
44
|
-
//
|
|
45
|
-
// === THE SIGNATURE-HASH GATE: what bash actually feeds sha256sum ================================
|
|
46
|
-
//
|
|
47
|
-
// bash's compute_signature() runs THREE independent `find ... -printf '%T@ %p\n' | sort |
|
|
48
|
-
// sha256sum | cut -d' ' -f1` pipelines (plans, reviews, rd) and joins the three resulting hex
|
|
49
|
-
// digests with `printf '%s:%s:%s'`. Two things here are easy to get subtly wrong, both verified
|
|
50
|
-
// directly against the unmodified bash hook (via `sha256sum`, `find -printf`, and staged
|
|
51
|
-
// throwaway directories) rather than assumed:
|
|
52
|
-
//
|
|
53
|
-
// 1. ABSENT DIRECTORY vs. EMPTY DIRECTORY are NOT the same segment value. If `.somi/plans`
|
|
54
|
-
// doesn't exist at all, bash's `if [[ -d ... ]]` guard is false and `plans_state` stays the
|
|
55
|
-
// shell's default empty string (`""`) — NOT a hash of anything. If `.somi/plans` exists but
|
|
56
|
-
// contains zero matching `progress.md` files, `find` produces zero lines, `sort` passes
|
|
57
|
-
// zero lines through, and `sha256sum` hashes the EMPTY STRING, producing the well-known
|
|
58
|
-
// constant `e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b85`. Verified
|
|
59
|
-
// directly: a project dir with no `.somi/*` at all writes state-file content `"::\n"` (two
|
|
60
|
-
// bare colons, zero-length segments); a project dir with an empty `.somi/plans/` writes
|
|
61
|
-
// `"e3b0c44...b7852b85::\n"`. Reproduced below via `hashSegment()`'s `isDirectory` guard
|
|
62
|
-
// returning `''` before ever calling `findMatchingPaths`, keeping the two cases distinct.
|
|
63
|
-
// 2. THE `%T@` FRACTIONAL-SECOND FORMAT is 10 digits, not 9, and the 10th digit is always `0`
|
|
64
|
-
// at any real filesystem's resolution. Verified empirically (not from documentation, which
|
|
65
|
-
// doesn't pin this precisely) by setting a file's mtime to an exact, known nanosecond value
|
|
66
|
-
// via `os.utime(..., ns=...)` and reading back `find -printf '%T@\n'` against BOTH the
|
|
67
|
-
// genuine GNU findutils binary at `/usr/bin/find` (bypassing this sandbox's own `find`→`bfs`
|
|
68
|
-
// shell-function shim, which is layered on top of the real binary and reformats output
|
|
69
|
-
// differently) and the shimmed one: mtime_ns=1712345678987654321 (987654321 ns past the
|
|
70
|
-
// second) printed as `1712345678.9876543210` — the 9-digit nanosecond remainder with a
|
|
71
|
-
// literal `0` appended, not a 9-digit value. Reproduced exactly below via
|
|
72
|
-
// `mtimeField()`: BigInt seconds/nanoseconds from `fs.statSync(p, {bigint:true}).mtimeNs`,
|
|
73
|
-
// formatted as `${seconds}.${nanos.toString().padStart(9,'0')}0`.
|
|
74
|
-
//
|
|
75
|
-
// IMPORTANT SCOPE LIMIT on point 2: this reproduces GNU findutils' specific `%T@` format
|
|
76
|
-
// (confirmed against the real `/usr/bin/find` binary on this host). It is NOT a claim that
|
|
77
|
-
// every `find` implementation formats `%T@` identically — BSD find (stock macOS) doesn't
|
|
78
|
-
// support `-printf` at all (a GNU extension), so bash's `compute_signature()` already silently
|
|
79
|
-
// produces empty segments there today (`-printf` errors, `2>/dev/null` swallows it, `find`
|
|
80
|
-
// exits non-zero, the pipeline's stdout is empty) — a pre-existing bash-only portability gap,
|
|
81
|
-
// not introduced by this port. More importantly: **the gate is self-referential.** The state
|
|
82
|
-
// file at `.somi/somi-state/last-context-signature` is only ever compared against a value
|
|
83
|
-
// THIS SAME hook previously wrote — never against an external oracle, never read by any other
|
|
84
|
-
// tool. Byte-identical hex-digest parity between a bash-computed signature and a Node-computed
|
|
85
|
-
// signature for the identical on-disk state is therefore neither achievable in general (it
|
|
86
|
-
// depends on which `find` binary happens to resolve first on PATH, which varies by host and
|
|
87
|
-
// doesn't exist at all on Windows) nor required for correctness. What IS required, and IS
|
|
88
|
-
// preserved exactly, is the gate's BEHAVIORAL contract: stable across repeated invocations when
|
|
89
|
-
// nothing changed, and different whenever the matched file set or any matched file's mtime
|
|
90
|
-
// changes — both verified by direct probe. One bounded, expected consequence:
|
|
91
|
-
// the FIRST Node-hook invocation on a host whose `.somi/somi-state/last-context-signature`
|
|
92
|
-
// was last written by the bash hook will see a "changed" signature (different hash algorithms
|
|
93
|
-
// for the same state) and re-emit the reminder ONE extra time at cutover — benign, not a bug.
|
|
94
|
-
//
|
|
95
|
-
// === THE STATUS-DETECTION DECISION (explicit and named) =============================
|
|
96
|
-
//
|
|
97
|
-
// A fixture pinned a real gap in the original bash hook: its in-progress detection recognizes a bare status line
|
|
98
|
-
// matching `^[[:space:]]*<?in-progress>?[[:space:]]*$` (optional ANGLE brackets, not backticks)
|
|
99
|
-
// or a line matching `status:[[:space:]]*`?in-progress`?` (requires a literal "status:" prefix).
|
|
100
|
-
// Neither pattern matches this project's OWN `progress.md` convention: a bare, BACKTICK-wrapped
|
|
101
|
-
// status line with no "Status:" prefix — confirmed not just by the fixture's synthetic example
|
|
102
|
-
// but by `templates/PROGRESS.md.tmpl` (`<One of: ... | in-progress | ...>` under a bare
|
|
103
|
-
// `## Status` heading, zero "Status:" prefix) — the CANONICAL template every `/plan`-generated
|
|
104
|
-
// work item's `progress.md` follows. So the narrow bash regexes miss the mainline case, not an
|
|
105
|
-
// edge case: every SoMi work item created via the documented template is invisible to this
|
|
106
|
-
// hook's plan-hint scan today.
|
|
107
|
-
//
|
|
108
|
-
// Chosen: **(b) widen** — narrowly. `PLAN_STATUS_BARE_RE` below adds backtick as a second
|
|
109
|
-
// optional wrap character alongside the existing angle bracket, preserving the ORIGINAL pattern's
|
|
110
|
-
// own already-independent (non-paired) optionality — the bash original already accepts a
|
|
111
|
-
// mismatched `<in-progress` (leading `<`, no trailing `>`) since each is independently `?`; this
|
|
112
|
-
// widening adds backtick to the same independently-optional set, not a stricter, newly-paired
|
|
113
|
-
// rule the original never had. The full-line anchor (`^...$`, tested per PHYSICAL LINE, matching
|
|
114
|
-
// grep's line-oriented semantics, not a whole-file substring search) is preserved exactly.
|
|
115
|
-
//
|
|
116
|
-
// Reasoning, weighed explicitly against reproducing the narrow detection for parity:
|
|
117
|
-
//
|
|
118
|
-
// 1. Self-inconsistency, not a deliberate choice being preserved. SoMi's OWN planning tooling
|
|
119
|
-
// generates `progress.md` files in the exact format its OWN hook fails to recognize. This
|
|
120
|
-
// is not a hypothetical third-party format difference — it is SoMi authoring content for
|
|
121
|
-
// itself that its own runtime cannot read.
|
|
122
|
-
// 2. Bounded, precisely-scoped false-positive risk — verified empirically, not assumed. Unlike
|
|
123
|
-
// the prune-list fix in detect-repo-instructions.mjs (which could only ever go quiet, never
|
|
124
|
-
// surface something new — fail-quiet in the safe direction), THIS widening is in the OPPOSITE risk direction: it can make the
|
|
125
|
-
// hook say MORE than it used to, and a badly-shaped widening could false-positive on
|
|
126
|
-
// narrative text. Checked directly: `grep -nE '^\s*[<`]?in-progress[>`]?\s*$'` against a
|
|
127
|
-
// real ~1100-line `progress.md` — which repeatedly contains the SUBSTRING
|
|
128
|
-
// "in-progress" inside narrative sentences (e.g. "Iteration left `in-progress` (pass 1);
|
|
129
|
-
// review decides `done`." appears a dozen+ times in the Recent-activity/diary prose) —
|
|
130
|
-
// matches EXACTLY ONE line: the real `## Status` field's own bare `` `in-progress` `` line.
|
|
131
|
-
// Every narrative occurrence is disqualified by the full-line anchor (surrounding text on
|
|
132
|
-
// the same physical line breaks the `^...$` match). This is the concrete evidence that a
|
|
133
|
-
// substring-anywhere widening would be dangerous (it would false-positive on nearly every
|
|
134
|
-
// real `progress.md` once it accumulates history) while the full-line-anchored
|
|
135
|
-
// widening actually chosen is not.
|
|
136
|
-
// 3. Confined blast radius: only `PLAN_STATUS_BARE_RE` changes. The R&D status scan
|
|
137
|
-
// (`researching|drafting|awaiting-verification|ready-for-planning`) already matches this
|
|
138
|
-
// repo's actual R&D README convention (`> Status: `researching``, already carrying the
|
|
139
|
-
// "Status:" prefix the regex requires) — no gap there, so it is
|
|
140
|
-
// reproduced unchanged. `PLAN_STATUS_PREFIXED_RE` (the "status:"-prefixed in-progress form)
|
|
141
|
-
// is also reproduced unchanged — it already matches its own fixture cases correctly.
|
|
142
|
-
//
|
|
143
|
-
// Consumer-observable consequence: a work item using the bare-backtick `progress.md` convention
|
|
144
|
-
// now surfaces its "Active work item:" hint on turns where it previously stayed silent. This is a
|
|
145
|
-
// real behavior change, not a bug fix to an internal-only mechanism (unlike the SessionStart
|
|
146
|
-
// prune fix, which only affected an already-informational context surface), so it belongs in
|
|
147
|
-
// the CHANGELOG.
|
|
148
|
-
//
|
|
149
|
-
// Fixture implication: `tests/hooks/cases/inject-workflow-context.json`'s
|
|
150
|
-
// `plan-hint-bare-backtick-status-not-detected` case (which pinned the bash gap as current
|
|
151
|
-
// behavior) is renamed to `plan-hint-bare-backtick-status-now-detected` and its expectation
|
|
152
|
-
// FLIPPED (`expect_context_excludes: "Active work item:"` → `expect_context: "Active work item:
|
|
153
|
-
// \`.somi/plans/demo-slug/\`."`) — the one deliberate case edit this change required.
|
|
154
|
-
//
|
|
155
|
-
// === Loose-end nudges: execFileSync argument arrays, explicit maxBuffer ==========================
|
|
156
|
-
// `git diff`/`git status` are invoked via `execFileSync` with argument ARRAYS (never a shell
|
|
157
|
-
// string), avoiding any shell-injection surface entirely (paths interpolated into a shell command
|
|
158
|
-
// string is exactly the class of bug `execFileSync(cmd, [args])` structurally forecloses). Both
|
|
159
|
-
// calls set `maxBuffer` explicitly (10 MB — the convention for every
|
|
160
|
-
// output-capturing subprocess call in the hooks), rather than relying on Node's low
|
|
161
|
-
// 1 MB default. A failed/absent `git` (ENOENT) or a non-zero exit from either command degrades to
|
|
162
|
-
// "no nudge from that check" — mirrors bash's `2>/dev/null` + `set -o pipefail`-tolerant `if
|
|
163
|
-
// pipeline; then` idiom, where either failure mode collapses to the same "condition false" outcome
|
|
164
|
-
// (a pipeline's non-zero exit inside an `if` condition does not abort under `set -e`).
|
|
165
|
-
//
|
|
166
|
-
// === Windows caveat (same class already flagged in the other path-handling hooks) ==========
|
|
167
|
-
// Paths embedded in the signature hash and extracted slugs use `path.join`/`path.basename`
|
|
168
|
-
// (platform-default separator). Purely internal (signature) or free-text-message (slugs) use —
|
|
169
|
-
// not fixed here, consistent with the other hooks' documented-not-fixed Windows path-separator gaps.
|
|
170
|
-
|
|
171
|
-
import fs from 'node:fs';
|
|
172
|
-
import path from 'node:path';
|
|
173
|
-
import crypto from 'node:crypto';
|
|
174
|
-
import { execFileSync } from 'node:child_process';
|
|
175
|
-
import { readPayload, projectRoot, pluginRoot, contextOutput, runHook } from '../lib/common.mjs';
|
|
176
|
-
|
|
177
|
-
// bash: `grep -qiE '^[[:space:]]*<?in-progress>?[[:space:]]*$'` — WIDENED per THE
|
|
178
|
-
// STATUS-DETECTION DECISION above: backtick added as a second optional wrap character alongside
|
|
179
|
-
// the original's angle bracket, independently optional on each side exactly as the original was.
|
|
180
|
-
const PLAN_STATUS_BARE_RE = /^\s*[<`]?in-progress[>`]?\s*$/i;
|
|
181
|
-
// bash: `grep -qiE 'status:[[:space:]]*`?in-progress`?'` — reproduced unchanged (already matches
|
|
182
|
-
// its fixture cases; no gap found here).
|
|
183
|
-
const PLAN_STATUS_PREFIXED_RE = /status:\s*`?in-progress`?/i;
|
|
184
|
-
|
|
185
|
-
// bash: `grep -qiE 'status:[[:space:]]*`?(researching|drafting|awaiting-verification)`?'` /
|
|
186
|
-
// `grep -qiE 'status:[[:space:]]*`?ready-for-planning`?'` — reproduced unchanged; the real R&D
|
|
187
|
-
// README.md convention already carries the required "Status:" prefix.
|
|
188
|
-
const RD_STATUS_ACTIVE_RE = /status:\s*`?(researching|drafting|awaiting-verification)`?/i;
|
|
189
|
-
const RD_STATUS_READY_RE = /status:\s*`?ready-for-planning`?/i;
|
|
190
|
-
|
|
191
|
-
// bash: `grep -E '^\+.*(TODO\(claude\)|TODO\(agent\)|FIXME\(claude\))'` against `git diff` output.
|
|
192
|
-
const TODO_MARKER_RE = /^\+.*(TODO\(claude\)|TODO\(agent\)|FIXME\(claude\))/;
|
|
193
|
-
// bash: `grep -E '^\?\? .*(\.bak|\.orig|scratch_)'` against `git status --porcelain` output.
|
|
194
|
-
const SCRATCH_FILE_RE = /^\?\? .*(\.bak|\.orig|scratch_)/;
|
|
195
|
-
|
|
196
|
-
// The convention for every output-capturing subprocess call (Node's spawnSync/execFileSync default
|
|
197
|
-
// maxBuffer is 1 MB — too small for a real `git diff`/`git status --porcelain` on a large
|
|
198
|
-
// working tree).
|
|
199
|
-
const GIT_MAX_BUFFER = 10 * 1024 * 1024;
|
|
200
|
-
|
|
201
|
-
const REMINDER_BODY =
|
|
202
|
-
'somi is active. Reminders:\n' +
|
|
203
|
-
// No `rules/...` path here, deliberately. This text is injected into a CONSUMING
|
|
204
|
-
// project's context, where SoMi's `rules/` lives inside the plugin install dir, not at
|
|
205
|
-
// `./rules/`. Naming the path asserted a file that ENOENTs there — the same defect the Tier 2
|
|
206
|
-
// digest avoids — and this block is emitted on EVERY turn, so the false assertion would be
|
|
207
|
-
// loud. Stating the priority order directly needs no path at all. Keeping
|
|
208
|
-
// Tier 1 free of `rules/` is also what lets the Tier 2 assertion be a flat "no `rules/`".
|
|
209
|
-
'- Follow SoMi\'s priority order: security > correctness > maintainability > performance > convenience.\n' +
|
|
210
|
-
'- Plan before coding non-trivial work. Code from the plan, not around it.\n' +
|
|
211
|
-
'- Surface tradeoffs and shortcuts in plain text; never silently compromise.\n' +
|
|
212
|
-
'- Hooks may deny dangerous bash, secret writes, protected paths, and unsanctioned dep installs — do not work around them.';
|
|
213
|
-
|
|
214
|
-
// Markers pinned in rules/CLAUDE.md's own "Always-on digest" section so extraction never depends
|
|
215
|
-
// on heading text staying stable — scripts/generate-digest.mjs consumes the same two markers for
|
|
216
|
-
// its own targets.
|
|
217
|
-
const DIGEST_MARKER_RE = /<!-- digest:start -->\r?\n([\s\S]*?)\r?\n<!-- digest:end -->/;
|
|
218
|
-
|
|
219
|
-
// Flattens a markdown link to its target, e.g. `[label](target)` -> `target` — the first half of
|
|
220
|
-
// rewriting each bullet's trailing citation to a bare numeric code (see stripDigestCitations()
|
|
221
|
-
// below). `.replace()` with a global regex resets its own lastIndex at the start of every call
|
|
222
|
-
// (per spec), so reusing this module-level pattern across lines carries none of the
|
|
223
|
-
// stateful-/g-regex hazard common.mjs's toRegExp()/matchesAny() guard against.
|
|
224
|
-
const DIGEST_LINK_RE = /\[([^\]]*)\]\(([^)]*)\)/g;
|
|
225
|
-
|
|
226
|
-
// Rewrites each physical line's trailing `(...)` citation to bare backtick-wrapped numeric
|
|
227
|
-
// code(s): `(`00`)` stays `(`00`)`; `([rules/00-priorities.md](./rules/00-priorities.md))`
|
|
228
|
-
// becomes `(`00`)`; `(`00`, `20`)` stays `(`00`, `20`)`. This is the required OUTPUT, not "strip
|
|
229
|
-
// back to the parenthetical it wrapped" — the latter, applied to a markdown-link source, still
|
|
230
|
-
// leaves a path assertion behind (`(rules/00-priorities.md)` still ENOENTs in a consuming
|
|
231
|
-
// project). Handles the already-bare canonical form and the
|
|
232
|
-
// full-markdown-link form identically — a markdown link is flattened to its target text before
|
|
233
|
-
// the numeric code is extracted, so this function doesn't need to know which form rules/CLAUDE.md
|
|
234
|
-
// is currently in.
|
|
235
|
-
function stripDigestCitations(block) {
|
|
236
|
-
return block
|
|
237
|
-
.split('\n')
|
|
238
|
-
.map((line) => {
|
|
239
|
-
// Match the trailing parenthetical on the ORIGINAL line — never on a pre-flattened copy
|
|
240
|
-
// Flattening the whole line first and returning that copy from the reject paths meant
|
|
241
|
-
// any line the recognizer DECLINED still had its markdown links destroyed: a bullet reading
|
|
242
|
-
// `read [the security file](./rules/30-security-owasp.md) before touching a sink` was injected
|
|
243
|
-
// as `read ./rules/30-security-owasp.md before touching a sink` — the very output this function exists
|
|
244
|
-
// to prevent, reached through the opposite door, and via the `!citationMatch` branch, which has nothing to do with
|
|
245
|
-
// citations at all. The mutation is now confined to the citation: links are flattened ONLY
|
|
246
|
-
// inside the captured body, and every reject path returns `line` byte-identical.
|
|
247
|
-
//
|
|
248
|
-
// One level of nesting is tolerated so a full markdown-link citation —
|
|
249
|
-
// `([rules/00-priorities.md](./rules/00-priorities.md))`, the form the digest generator
|
|
250
|
-
// normalizes to — is captured whole rather than truncated at its inner `)`.
|
|
251
|
-
const citationMatch = line.match(/\((?:[^()]|\([^()]*\))*\)\s*$/);
|
|
252
|
-
if (!citationMatch) return line; // no trailing parenthetical on this physical line — a
|
|
253
|
-
// bullet's citation sits on its own word-wrapped continuation line, not every line has one.
|
|
254
|
-
// Returns `line`, NOT a flattened copy: a line with no citation is none of this function's
|
|
255
|
-
// business, whatever else it contains.
|
|
256
|
-
const inner = citationMatch[0].slice(1, -1); // drop the outer parens
|
|
257
|
-
const flattenedBody = inner.replace(DIGEST_LINK_RE, (_m, label, target) => target || label);
|
|
258
|
-
// ANCHORED recognizer. An earlier form scanned the parenthetical unanchored
|
|
259
|
-
// for any two-digit run, so ANY line-final parenthetical containing two consecutive digits
|
|
260
|
-
// became a rule citation: a bullet ending `(ISO 27001)` was rewritten to (`27`, `00`) —
|
|
261
|
-
// fabricating a citation to two rule files and delivering it to the model as fact. Rewrapping or trimming this block is precisely when a non-citation
|
|
262
|
-
// parenthetical lands at end-of-line.
|
|
263
|
-
//
|
|
264
|
-
// The whole body must now BE a citation list — comma-separated `NN` / `` `NN` `` /
|
|
265
|
-
// `rules/NN-*.md` / `./rules/NN-*.md` — or the line is left untouched. Partial matches no
|
|
266
|
-
// longer leak: `ISO 27001` fails because `27001` is not a two-digit item.
|
|
267
|
-
const body = flattenedBody.trim();
|
|
268
|
-
// The `rules/` segment is OPTIONAL (widened after review). The canonical
|
|
269
|
-
// digest lives at rules/CLAUDE.md, so a link that RESOLVES from there is `./NN-*.md` with no
|
|
270
|
-
// `rules/` segment — the form the composition table in that same file already uses. Requiring
|
|
271
|
-
// `rules/` accepted only `./rules/NN-*.md`, which resolves to `rules/rules/...` and is a dead
|
|
272
|
-
// link; the round-trip appeared to pass precisely BECAUSE the canonical was broken. Both forms
|
|
273
|
-
// are accepted now so correcting the canonical cannot silently reintroduce path assertions.
|
|
274
|
-
const ITEM_RE = /^(?:`?(\d{2})`?|\.?\/?(?:rules\/)?(\d{2})-[A-Za-z0-9-]+\.md)$/;
|
|
275
|
-
const items = body === '' ? [] : body.split(',').map((s) => s.trim());
|
|
276
|
-
const codes = [];
|
|
277
|
-
let allItemsAreCitations = items.length > 0;
|
|
278
|
-
for (const item of items) {
|
|
279
|
-
const m = ITEM_RE.exec(item);
|
|
280
|
-
if (!m) {
|
|
281
|
-
allItemsAreCitations = false;
|
|
282
|
-
break;
|
|
283
|
-
}
|
|
284
|
-
const code = m[1] ?? m[2];
|
|
285
|
-
if (!codes.includes(code)) codes.push(code);
|
|
286
|
-
}
|
|
287
|
-
// Not a citation list — return `line` UNCHANGED. A rejected line keeps its original
|
|
288
|
-
// markdown links intact. If such a link points into `rules/`, a digest-wide
|
|
289
|
-
// `excludes: "rules/"` assertion goes red and forces the digest's author to use the accepted
|
|
290
|
-
// grammar rather than having the link silently mangled into a bare path. Loud beats silent.
|
|
291
|
-
if (!allItemsAreCitations || codes.length === 0) return line;
|
|
292
|
-
const rewritten = `(${codes.map((c) => `\`${c}\``).join(', ')})`;
|
|
293
|
-
return line.slice(0, citationMatch.index) + rewritten;
|
|
294
|
-
})
|
|
295
|
-
.join('\n');
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
// Tier 2's content, read fresh from rules/CLAUDE.md at runtime rather than hand-copied into this
|
|
299
|
-
// hook as a fourth drift-prone copy. Fails safe at every step — an unresolved
|
|
300
|
-
// pluginRoot(), an unreadable file, or missing/malformed digest markers all return '' (Tier 2
|
|
301
|
-
// silently omitted) rather than throwing; Tier 1 (REMINDER_BODY) fires regardless, in main().
|
|
302
|
-
function buildTier2Digest() {
|
|
303
|
-
const base = pluginRoot();
|
|
304
|
-
if (!base) return '';
|
|
305
|
-
let content;
|
|
306
|
-
try {
|
|
307
|
-
content = fs.readFileSync(path.join(base, 'rules', 'CLAUDE.md'), 'utf8');
|
|
308
|
-
} catch {
|
|
309
|
-
return '';
|
|
310
|
-
}
|
|
311
|
-
const match = DIGEST_MARKER_RE.exec(content);
|
|
312
|
-
if (!match) return '';
|
|
313
|
-
return stripDigestCitations(match[1]);
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
// The single, durable pointer that replaces the per-bullet paths stripDigestCitations() removes.
|
|
317
|
-
// Appended by main() AFTER planHint/rdHint so it is genuinely trailing: building it into
|
|
318
|
-
// buildTier2Digest() put it before the hints, leaving a hint rendered as a dangling bullet hanging
|
|
319
|
-
// off a prose sentence — readable as an elaboration of "load the rules skill" rather than as the
|
|
320
|
-
// work-item notice it is.
|
|
321
|
-
const RULES_SKILL_POINTER = 'For full detail on any of these, load the `rules` skill.';
|
|
322
|
-
|
|
323
|
-
function isDirectory(p) {
|
|
324
|
-
try {
|
|
325
|
-
return fs.statSync(p).isDirectory();
|
|
326
|
-
} catch {
|
|
327
|
-
return false;
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
// Every filesystem entry within `dir` (bounded to `maxDepth` levels below it, `dir` itself being
|
|
332
|
-
// depth 0) whose basename satisfies `isMatch`. Mirrors bash's `find "$dir" -maxdepth N -name
|
|
333
|
-
// 'X'`: EVERY visited node (the starting dir plus every descendant up to maxDepth) is tested by
|
|
334
|
-
// basename — there is no `-type f` in the bash original, so a directory can match too — and only
|
|
335
|
-
// directories are descended into further. Shared by the signature scan (mtime hashing) and the
|
|
336
|
-
// plan-hint/rd-hint scans (content grep) below, exactly as bash independently runs the SAME
|
|
337
|
-
// `find "$dir" -maxdepth N -name 'X'` shape twice for two different purposes (once with
|
|
338
|
-
// `-printf`, once without).
|
|
339
|
-
function findMatchingPaths(dir, maxDepth, isMatch) {
|
|
340
|
-
const results = [];
|
|
341
|
-
function visit(p, depth) {
|
|
342
|
-
if (isMatch(path.basename(p))) results.push(p);
|
|
343
|
-
if (depth >= maxDepth) return;
|
|
344
|
-
let entries;
|
|
345
|
-
try {
|
|
346
|
-
entries = fs.readdirSync(p, { withFileTypes: true });
|
|
347
|
-
} catch {
|
|
348
|
-
return; // matches find's `2>/dev/null` — an unreadable subtree is silently skipped.
|
|
349
|
-
}
|
|
350
|
-
for (const entry of entries) {
|
|
351
|
-
const full = path.join(p, entry.name);
|
|
352
|
-
if (entry.isDirectory()) {
|
|
353
|
-
visit(full, depth + 1);
|
|
354
|
-
} else if (isMatch(entry.name)) {
|
|
355
|
-
results.push(full);
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
visit(dir, 0);
|
|
360
|
-
return results;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
// bash: `%T@` — seconds since epoch, DOT, then a 10-digit fractional part (9-digit nanosecond
|
|
364
|
-
// remainder plus a literal trailing `0`; see the header's empirical finding). `fs.statSync(p,
|
|
365
|
-
// {bigint:true}).mtimeNs` gives nanoseconds since epoch as a BigInt, letting seconds/nanoseconds
|
|
366
|
-
// be split exactly rather than through a lossy float.
|
|
367
|
-
function mtimeField(p) {
|
|
368
|
-
const st = fs.statSync(p, { bigint: true });
|
|
369
|
-
const seconds = st.mtimeNs / 1000000000n;
|
|
370
|
-
const nanos = st.mtimeNs % 1000000000n;
|
|
371
|
-
return `${seconds}.${nanos.toString().padStart(9, '0')}0`;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
// One signature segment: `''` if `dir` doesn't exist (matches bash leaving the variable at its
|
|
375
|
-
// default empty string), else the sha256 hex digest of the sorted "`mtimeField` `path`" lines —
|
|
376
|
-
// including the digest of the EMPTY STRING when the directory exists but nothing matches (see the
|
|
377
|
-
// header's "absent vs. empty" finding; these are deliberately different values).
|
|
378
|
-
function hashSegment(dir, maxDepth, isMatch) {
|
|
379
|
-
if (!isDirectory(dir)) return '';
|
|
380
|
-
const lines = findMatchingPaths(dir, maxDepth, isMatch).map((p) => `${mtimeField(p)} ${p}`);
|
|
381
|
-
lines.sort(); // matches `sort`'s lexicographic line order (ASCII paths only in practice, same
|
|
382
|
-
// caveat class as this port series' other ASCII-only nocase/sort notes).
|
|
383
|
-
const input = lines.length > 0 ? `${lines.join('\n')}\n` : '';
|
|
384
|
-
return crypto.createHash('sha256').update(input, 'utf8').digest('hex');
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
// bash: `printf '%s:%s:%s' "$plans_state" "$reviews_state" "$rd_state"`.
|
|
388
|
-
function computeSignature(root) {
|
|
389
|
-
const plansState = hashSegment(path.join(root, '.somi', 'plans'), 2, (n) => n === 'progress.md');
|
|
390
|
-
const reviewsState = hashSegment(path.join(root, '.somi', 'reviews'), 3, (n) => n.endsWith('.md'));
|
|
391
|
-
const rdState = hashSegment(path.join(root, '.somi', 'rd'), 2, (n) => n === 'README.md');
|
|
392
|
-
return `${plansState}:${reviewsState}:${rdState}`;
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
function fileHasInProgressStatus(filePath) {
|
|
396
|
-
let content;
|
|
397
|
-
try {
|
|
398
|
-
content = fs.readFileSync(filePath, 'utf8');
|
|
399
|
-
} catch {
|
|
400
|
-
return false; // matches grep's `2>/dev/null` on an unreadable path (or a directory, EISDIR).
|
|
401
|
-
}
|
|
402
|
-
return content
|
|
403
|
-
.split(/\r?\n/)
|
|
404
|
-
.some((line) => PLAN_STATUS_BARE_RE.test(line) || PLAN_STATUS_PREFIXED_RE.test(line));
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
// 'active' | 'ready' | null — bash's `if grep -qiE active-pattern ...; then ...; elif grep -qiE
|
|
408
|
-
// ready-pattern ...; then ...; fi`: active takes precedence when a file (implausibly) matches
|
|
409
|
-
// both.
|
|
410
|
-
function readmeStatus(filePath) {
|
|
411
|
-
let content;
|
|
412
|
-
try {
|
|
413
|
-
content = fs.readFileSync(filePath, 'utf8');
|
|
414
|
-
} catch {
|
|
415
|
-
return null;
|
|
416
|
-
}
|
|
417
|
-
const lines = content.split(/\r?\n/);
|
|
418
|
-
if (lines.some((l) => RD_STATUS_ACTIVE_RE.test(l))) return 'active';
|
|
419
|
-
if (lines.some((l) => RD_STATUS_READY_RE.test(l))) return 'ready';
|
|
420
|
-
return null;
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
function computePlanHint(root) {
|
|
424
|
-
const plansDir = path.join(root, '.somi', 'plans');
|
|
425
|
-
if (!isDirectory(plansDir)) return '';
|
|
426
|
-
const inProgress = [];
|
|
427
|
-
for (const progressFile of findMatchingPaths(plansDir, 2, (n) => n === 'progress.md')) {
|
|
428
|
-
if (fileHasInProgressStatus(progressFile)) {
|
|
429
|
-
inProgress.push(path.basename(path.dirname(progressFile)));
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
if (inProgress.length === 1) {
|
|
433
|
-
return `\n- Active work item: \`.somi/plans/${inProgress[0]}/\`. Follow its \`spec.md\` and active iteration in \`phases/\`; update \`progress.md\` / \`diary.md\` as work proceeds.`;
|
|
434
|
-
}
|
|
435
|
-
if (inProgress.length > 1) {
|
|
436
|
-
return `\n- Multiple in-progress work items in \`.somi/plans/\`: ${inProgress.join(',')}. Confirm with the user which one applies before coding.`;
|
|
437
|
-
}
|
|
438
|
-
return '';
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
function computeRdHint(root) {
|
|
442
|
-
const rdDir = path.join(root, '.somi', 'rd');
|
|
443
|
-
if (!isDirectory(rdDir)) return '';
|
|
444
|
-
const rdActive = [];
|
|
445
|
-
const rdReady = [];
|
|
446
|
-
for (const readme of findMatchingPaths(rdDir, 2, (n) => n === 'README.md')) {
|
|
447
|
-
const status = readmeStatus(readme);
|
|
448
|
-
const slug = path.basename(path.dirname(readme));
|
|
449
|
-
if (status === 'active') rdActive.push(slug);
|
|
450
|
-
else if (status === 'ready') rdReady.push(slug);
|
|
451
|
-
}
|
|
452
|
-
if (rdActive.length >= 1) {
|
|
453
|
-
return `\n- Active discovery in \`.somi/rd/\`: ${rdActive.join(',')}. This is requirements-engineering work (\`/discover\`): research the competition, author the R&D doc set, verify crossroads, before handing to \`/plan\`.`;
|
|
454
|
-
}
|
|
455
|
-
if (rdReady.length === 1) {
|
|
456
|
-
return `\n- R&D foundation ready in \`.somi/rd/${rdReady[0]}/\`. \`/plan ${rdReady[0]}\` will consume its SRS/FRD as the requirements source and SDD/TDD as architectural direction.`;
|
|
457
|
-
}
|
|
458
|
-
return '';
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
// bash: `command -v git >/dev/null 2>&1`.
|
|
462
|
-
function isGitAvailable() {
|
|
463
|
-
try {
|
|
464
|
-
execFileSync('git', ['--version'], { stdio: 'ignore' });
|
|
465
|
-
return true;
|
|
466
|
-
} catch {
|
|
467
|
-
return false;
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
// bash: `git -C "$PROJECT_ROOT" diff --no-color --unified=0 HEAD 2>/dev/null | grep -E '...' -q`.
|
|
472
|
-
function hasTodoMarkerInDiff(root) {
|
|
473
|
-
let out;
|
|
474
|
-
try {
|
|
475
|
-
out = execFileSync('git', ['-C', root, 'diff', '--no-color', '--unified=0', 'HEAD'], {
|
|
476
|
-
encoding: 'utf8',
|
|
477
|
-
maxBuffer: GIT_MAX_BUFFER,
|
|
478
|
-
});
|
|
479
|
-
} catch {
|
|
480
|
-
return false; // no HEAD, git error, or non-zero exit — same "no nudge" outcome as bash's
|
|
481
|
-
// pipefail-tolerant `if pipeline; then` when either side of the pipe fails.
|
|
482
|
-
}
|
|
483
|
-
return out.split('\n').some((line) => TODO_MARKER_RE.test(line));
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
// bash: `git -C "$PROJECT_ROOT" status --porcelain 2>/dev/null | grep -E '...' -q`.
|
|
487
|
-
function hasScratchFileInStatus(root) {
|
|
488
|
-
let out;
|
|
489
|
-
try {
|
|
490
|
-
out = execFileSync('git', ['-C', root, 'status', '--porcelain'], {
|
|
491
|
-
encoding: 'utf8',
|
|
492
|
-
maxBuffer: GIT_MAX_BUFFER,
|
|
493
|
-
});
|
|
494
|
-
} catch {
|
|
495
|
-
return false;
|
|
496
|
-
}
|
|
497
|
-
return out.split('\n').some((line) => SCRATCH_FILE_RE.test(line));
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
// bash: `if command -v git ... && [[ -d "$PROJECT_ROOT/.git" ]]; then ...; fi` gates BOTH nudge
|
|
501
|
-
// checks together — computed unconditionally every call, independent of the reminder-emission
|
|
502
|
-
// gate (see main()).
|
|
503
|
-
function computeNudges(root) {
|
|
504
|
-
const nudges = [];
|
|
505
|
-
if (isGitAvailable() && isDirectory(path.join(root, '.git'))) {
|
|
506
|
-
if (hasTodoMarkerInDiff(root)) {
|
|
507
|
-
nudges.push(
|
|
508
|
-
"Detected new TODO(claude)/FIXME(claude) markers in the diff against HEAD. List them explicitly as 'not done' in your next summary."
|
|
509
|
-
);
|
|
510
|
-
}
|
|
511
|
-
if (hasScratchFileInStatus(root)) {
|
|
512
|
-
nudges.push('Detected scratch / .bak files in working tree. Clean them up before declaring done.');
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
return nudges;
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
function main() {
|
|
519
|
-
readPayload();
|
|
520
|
-
|
|
521
|
-
const root = projectRoot();
|
|
522
|
-
const stateDir = path.join(root, '.somi', 'somi-state');
|
|
523
|
-
const stateFile = path.join(stateDir, 'last-context-signature');
|
|
524
|
-
fs.mkdirSync(stateDir, { recursive: true });
|
|
525
|
-
|
|
526
|
-
const currentSig = computeSignature(root);
|
|
527
|
-
let lastSig = '';
|
|
528
|
-
if (fs.existsSync(stateFile)) {
|
|
529
|
-
try {
|
|
530
|
-
// bash: `LAST_SIG="$(cat "$STATE_FILE" 2>/dev/null || true)"` — command substitution
|
|
531
|
-
// strips ALL trailing newlines (not general whitespace), so `.replace(/\n+$/, '')` rather
|
|
532
|
-
// than a generic `.trim()`.
|
|
533
|
-
lastSig = fs.readFileSync(stateFile, 'utf8').replace(/\n+$/, '');
|
|
534
|
-
} catch {
|
|
535
|
-
lastSig = '';
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
fs.writeFileSync(stateFile, `${currentSig}\n`); // bash: `echo "$CURRENT_SIG" > "$STATE_FILE"`.
|
|
539
|
-
|
|
540
|
-
// bash: `[[ -z "$LAST_SIG" ]] || [[ "$LAST_SIG" != "$CURRENT_SIG" ]]` — reproduced as the exact
|
|
541
|
-
// two-part condition (CURRENT_SIG is never truly empty, it's at minimum "::", but the explicit
|
|
542
|
-
// first-turn branch is preserved for fidelity/clarity rather than collapsed to a single `!==`).
|
|
543
|
-
const emitReminder = lastSig === '' || lastSig !== currentSig;
|
|
544
|
-
|
|
545
|
-
const planHint = computePlanHint(root);
|
|
546
|
-
const rdHint = computeRdHint(root);
|
|
547
|
-
const nudges = computeNudges(root);
|
|
548
|
-
|
|
549
|
-
// Tier 1: unconditional, every turn, independent of emitReminder.
|
|
550
|
-
const parts = [REMINDER_BODY];
|
|
551
|
-
|
|
552
|
-
// Tier 2: gated exactly as the old single-tier reminder was. planHint/rdHint ride Tier 2 (see
|
|
553
|
-
// the header note above) — concatenated the same way REMINDER_BODY+hints were joined before
|
|
554
|
-
// this split, then any leading newline left over from an empty/omitted digest is trimmed so a
|
|
555
|
-
// fail-safe-omitted Tier 2 with a present hint doesn't emit a stray blank line.
|
|
556
|
-
if (emitReminder) {
|
|
557
|
-
const tier2Digest = buildTier2Digest();
|
|
558
|
-
let tier2Block = `${tier2Digest}${planHint}${rdHint}`.replace(/^\n+/, '');
|
|
559
|
-
// The pointer goes last, after the hints — and only when a digest was actually
|
|
560
|
-
// extracted, so the fail-safe path (missing/marker-less rules/CLAUDE.md) doesn't advertise a
|
|
561
|
-
// skill for content it just failed to deliver.
|
|
562
|
-
if (tier2Digest !== '') tier2Block += `\n\n${RULES_SKILL_POINTER}`;
|
|
563
|
-
if (tier2Block !== '') parts.push(tier2Block);
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
if (nudges.length > 0) {
|
|
567
|
-
let nudgeBlock = 'somi loose-end check:';
|
|
568
|
-
for (const n of nudges) {
|
|
569
|
-
nudgeBlock += `\n - ${n}`;
|
|
570
|
-
}
|
|
571
|
-
parts.push(nudgeBlock);
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
// Tier 1 is unconditional, so `parts` is never empty — the old `if (parts.length > 0)` guard
|
|
575
|
-
// became dead code with the tier split and is dropped rather than left as a false suggestion that
|
|
576
|
-
// a silent turn is still reachable.
|
|
577
|
-
contextOutput('UserPromptSubmit', parts.join('\n\n'));
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
runHook(main);
|
package/rules/00-priorities.md
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
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; one you keep in code carries a comment `shortcut: <the limit>, <when to upgrade>`.
|