@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,287 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// hooks/session-start/detect-repo-instructions.mjs — SessionStart hook — detect repo-local
|
|
3
|
-
// agent/instruction files and surface them.
|
|
4
|
-
//
|
|
5
|
-
// Imports the shared read/context/projectRoot helpers from ../lib/common.mjs rather than
|
|
6
|
-
// reimplementing them.
|
|
7
|
-
//
|
|
8
|
-
// SoMi's design→execution economy is "respect repo conventions as context": when a project ships
|
|
9
|
-
// its own instructions (CLAUDE.md / AGENTS.md / copilot-instructions / .cursorrules) or its own
|
|
10
|
-
// subagents (.claude/agents/), SoMi's `cost: high` actions should read them once and fold the
|
|
11
|
-
// relevant conventions into the work-item brief.md, so execution inherits them without re-reading.
|
|
12
|
-
// Repo-local instructions WIN over SoMi defaults where they conflict; SoMi does NOT
|
|
13
|
-
// auto-invoke foreign agents. This hook only *surfaces* what exists (paths + a one-line
|
|
14
|
-
// directive) — it does not read or ingest file contents. It fires once per session and stays
|
|
15
|
-
// silent when nothing repo-local is present.
|
|
16
|
-
//
|
|
17
|
-
// === THE PRUNE-LIST DECISION (explicit and named) ==============================
|
|
18
|
-
//
|
|
19
|
-
// bash's nested-file find (`detect-repo-instructions.sh:41-46`) declares a prune list
|
|
20
|
-
// (.git/node_modules/.somi/vendor) but it is CONFIRMED NON-FUNCTIONAL on GNU find (found by a
|
|
21
|
-
// probe and reproduced independently with a control experiment): GNU
|
|
22
|
-
// find's `-mindepth 2` suppresses evaluation of EVERY predicate — including `-prune` — for
|
|
23
|
-
// entries at depth < 2, and the pruned directories themselves (.git, node_modules, .somi,
|
|
24
|
-
// vendor) are always depth-1 children of PROJECT_ROOT. The `-prune` clause therefore never
|
|
25
|
-
// fires; find still descends into all four directories, bounded only by `-maxdepth 3`.
|
|
26
|
-
//
|
|
27
|
-
// This port chooses **(b): fix forward.** A directory whose basename is one of the four
|
|
28
|
-
// pruned names, when it appears as a direct (depth-1) child of PROJECT_ROOT — exactly the
|
|
29
|
-
// entries bash's `-path "$PROJECT_ROOT/.git"`-style literal-path tests target, no broader — is
|
|
30
|
-
// never descended into. This is the narrowest possible fix: it reproduces exactly what the
|
|
31
|
-
// bash `-prune` clause is WRITTEN to do (literal full-path equality against the four
|
|
32
|
-
// top-level names, not a basename match at arbitrary depth), just makes it actually fire. It
|
|
33
|
-
// is not a redesign of the prune policy, only a bug fix confined to this one file.
|
|
34
|
-
//
|
|
35
|
-
// Reasoning, considered against reproducing the bug for strict parity instead:
|
|
36
|
-
//
|
|
37
|
-
// 1. Self-documented intent, violated by an accident, not a choice. This file's own header
|
|
38
|
-
// comment (both bash's and this one's) states the design goal in plain language: "cap
|
|
39
|
-
// depth and count so this stays cheap and never wanders into .git / node_modules /
|
|
40
|
-
// .somi." The current bash behavior directly contradicts its own stated purpose because
|
|
41
|
-
// of a mechanical find/mindepth interaction bug, not because anyone decided vendored
|
|
42
|
-
// dependencies should be scanned. Reproducing a bug that contradicts the file's own
|
|
43
|
-
// documented intent is a weaker form of "parity" than fixing it to match that intent.
|
|
44
|
-
//
|
|
45
|
-
// 2. Correctness, not just performance: what gets SURFACED. A CLAUDE.md/AGENTS.md that
|
|
46
|
-
// happens to live inside a vendored dependency (node_modules), a submodule under
|
|
47
|
-
// vendor/, or somi's own internal state directory is not "this repository's own
|
|
48
|
-
// instructions" in the sense this hook's entire purpose describes to the `cost: high`
|
|
49
|
-
// actions that consume its signal. Surfacing a third-party package's own CLAUDE.md as if it were
|
|
50
|
-
// this repo's convention is actively misleading downstream context, not neutral noise.
|
|
51
|
-
//
|
|
52
|
-
// 3. Performance, empirically measured, not assumed (possibly the strongest argument, and it
|
|
53
|
-
// held up under measurement). Built a synthetic
|
|
54
|
-
// 800-package node_modules (4802 fs entries at depth <= 3, no matches, so `head -n 10`
|
|
55
|
-
// cannot short-circuit either implementation — full traversal is forced both ways) and
|
|
56
|
-
// timed three walks against it: bash's find (buggy, still descends node_modules) ~14ms;
|
|
57
|
-
// a naive Node readdirSync walk reproducing the SAME non-pruning bug ~31-62ms (Node's
|
|
58
|
-
// per-entry overhead — Dirent construction, JS call/recursion cost — is measurably higher
|
|
59
|
-
// than find's C-native traversal, so "just port the bug" is not perf-neutral, it is
|
|
60
|
-
// WORSE); the fix-forward pruned walk below ~0.17-0.24ms (2 entries visited: node_modules
|
|
61
|
-
// itself, pruned before descending, plus the one root-level file). That is a ~150-350x
|
|
62
|
-
// difference in this synthetic case, and it scales with real node_modules trees, which
|
|
63
|
-
// commonly have thousands of packages — non-negligible for a hook whose whole premise is
|
|
64
|
-
// being cheap enough to run unconditionally on every SessionStart.
|
|
65
|
-
//
|
|
66
|
-
// 4. Fail-quiet in the safe direction, matching the other accepted divergences from the
|
|
67
|
-
// original bash hooks (the BASH_REMATCH-clobber fix, the UTF-8 truncation
|
|
68
|
-
// divergence): this change can only ever make a previously-surfaced file go silent
|
|
69
|
-
// (prune now excludes something it used to include); in every realistic case it never
|
|
70
|
-
// surfaces something new. (Pedantic corner: with >10 nested matches
|
|
71
|
-
// where pruned-dir junk sorts ahead of real files, bash's head -n 10 could truncate a
|
|
72
|
-
// REAL file the pruned walk now surfaces — arguably more correct, but not absolutely
|
|
73
|
-
// "never new".) A regression from this fix is "the hook says nothing when it used to
|
|
74
|
-
// say something," never a false positive.
|
|
75
|
-
//
|
|
76
|
-
// 5. Confined blast radius: unlike the audit()-embedded-delimiter issue (shared by every hook,
|
|
77
|
-
// deliberately NOT fixed in a single hook), this fix touches only this file
|
|
78
|
-
// — no shared common.mjs contract, no other hook's behavior, no cross-file coupling.
|
|
79
|
-
//
|
|
80
|
-
// What this means for the fixture (tests/hooks/cases/detect-repo-instructions.json):
|
|
81
|
-
// `surfaces-nested-claude-md-under-pruned-dir` (which pinned the CURRENT bash bug — a
|
|
82
|
-
// node_modules/CLAUDE.md being surfaced) is renamed and re-pointed to assert the FIXED
|
|
83
|
-
// behavior (silent exit — node_modules is now actually pruned) as a named, reviewed edit. The stated
|
|
84
|
-
// fixture-implications of the OTHER option (had (a) been chosen instead): every other case in
|
|
85
|
-
// the corpus would be untouched, this one case would pass completely as-is with zero edits,
|
|
86
|
-
// and the.mjs would need to intentionally NOT prune node_modules/.git/.somi/vendor at
|
|
87
|
-
// depth 1 — i.e. deliberately reproduce the bug, at the ~150-350x-in-synthetic-testing
|
|
88
|
-
// performance cost measured above, and at the cost of surfacing third-party CLAUDE.md files
|
|
89
|
-
// as if they were this repository's own conventions.
|
|
90
|
-
//
|
|
91
|
-
// === Depth-semantics translation (find -maxdepth 3 -mindepth 2) ==============================
|
|
92
|
-
// PROJECT_ROOT itself is depth 0; its direct children are depth 1; two directories down is
|
|
93
|
-
// depth 3 — the deepest this scan reaches (maxdepth 3). mindepth 2 excludes depth-0 (root
|
|
94
|
-
// itself, never a candidate anyway) and depth-1 files (root-level files are handled by the
|
|
95
|
-
// separate ROOT_FILES loop below, matching bash's separate `-f` loop + find). Verified against
|
|
96
|
-
// the fixture's depth-boundary pair: a/b/CLAUDE.md (file depth 3) IS surfaced
|
|
97
|
-
// (surfaces-nested-claude-md-at-max-scan-depth); a/b/c/CLAUDE.md (file depth 4) is NOT
|
|
98
|
-
// (omits-claude-md-beyond-scan-depth).
|
|
99
|
-
//
|
|
100
|
-
// === Symlink semantics (verified by direct probe against the unmodified bash hook, not
|
|
101
|
-
// assumed) ======================================================================================
|
|
102
|
-
// bash's ROOT-file loop uses `[[ -f "$PROJECT_ROOT/$f" ]]`, which FOLLOWS symlinks — a
|
|
103
|
-
// symlinked root CLAUDE.md IS surfaced. bash's nested find and the .claude/agents/ count both
|
|
104
|
-
// use `-type f` WITHOUT `-L`/`-follow` — this does NOT follow symlinks (a symlink has type
|
|
105
|
-
// 'l', not 'f'), confirmed with a live probe: a symlinked nested CLAUDE.md is silently
|
|
106
|
-
// excluded from the find output. Node's `fs.readdirSync(dir, { withFileTypes: true })` Dirent
|
|
107
|
-
// entries mirror this exactly, by construction, with no special-casing needed: `isFile()`/
|
|
108
|
-
// `isDirectory()` are both `false` for a symlink entry (confirmed with a live probe on the
|
|
109
|
-
// same fixture directories) — using `fs.statSync` (follows symlinks, like bash's `-f`) for the
|
|
110
|
-
// root-file loop and Dirent's `isFile()`/`isDirectory()` (does not follow, like bash's
|
|
111
|
-
// `-type f`/`-type d`) for the nested walk and the agents count reproduces both behaviors for
|
|
112
|
-
// free. Same reasoning covers a CLAUDE.md that is a DIRECTORY, not a file (verified live): the
|
|
113
|
-
// root loop's `-f` test is false for a directory, and the nested find's `-type f` test is
|
|
114
|
-
// false too (but the directory is still descended into like any other, matching bash) —
|
|
115
|
-
// `fs.statSync(...).isFile()` and Dirent's `isFile()` both return `false` for a directory
|
|
116
|
-
// identically, no extra branch required.
|
|
117
|
-
//
|
|
118
|
-
// === Windows caveat (same class already flagged in the other path-handling hooks) ==============================
|
|
119
|
-
// `path.relative()` (platform-default separator: posix on Linux/macOS, win32 on Windows) is
|
|
120
|
-
// used to build the relative paths this hook emits in its message text. On Windows this would
|
|
121
|
-
// emit backslash-separated relative paths where bash's `${nested#"$PROJECT_ROOT"/}` prefix
|
|
122
|
-
// strip always produced forward slashes — cosmetic only (the message is free text shown to the
|
|
123
|
-
// model, not machine-parsed), not fixed here, consistent with prior ports' documented-not-
|
|
124
|
-
// fixed Windows path-separator gaps.
|
|
125
|
-
|
|
126
|
-
import fs from 'node:fs';
|
|
127
|
-
import path from 'node:path';
|
|
128
|
-
import { readPayload, projectRoot, contextOutput, runHook } from '../lib/common.mjs';
|
|
129
|
-
|
|
130
|
-
// bash: `for f in "CLAUDE.md" "AGENTS.md" ".cursorrules" ".github/copilot-instructions.md"`.
|
|
131
|
-
const ROOT_FILES = ['CLAUDE.md', 'AGENTS.md', '.cursorrules', '.github/copilot-instructions.md'];
|
|
132
|
-
|
|
133
|
-
// bash: `-name 'CLAUDE.md' -o -name 'AGENTS.md'` in the nested find.
|
|
134
|
-
const NESTED_NAMES = new Set(['CLAUDE.md', 'AGENTS.md']);
|
|
135
|
-
|
|
136
|
-
// bash's documented prune list (`detect-repo-instructions.sh:42-43`), now actually enforced —
|
|
137
|
-
// see THE PRUNE-LIST DECISION above. Only matched at depth 1 (PROJECT_ROOT's direct children),
|
|
138
|
-
// mirroring bash's literal `-path "$PROJECT_ROOT/<name>"` full-path equality tests exactly —
|
|
139
|
-
// this is not a basename match at arbitrary depth.
|
|
140
|
-
const PRUNED_TOP_LEVEL_DIRS = new Set(['.git', 'node_modules', '.somi', 'vendor']);
|
|
141
|
-
|
|
142
|
-
const MAX_DEPTH = 3; // bash: find -maxdepth 3
|
|
143
|
-
const MIN_DEPTH = 2; // bash: -mindepth 2
|
|
144
|
-
const MAX_NESTED_RESULTS = 10; // bash: | head -n 10
|
|
145
|
-
|
|
146
|
-
// The walk's own bounds, beyond depth: a repo with a huge directory at depth <= 3 must not stall
|
|
147
|
-
// session start. The entry budget is the deterministic bound (tested); the deadline is the
|
|
148
|
-
// backstop for a slow filesystem. Hitting either just ends the scan with what was found so far.
|
|
149
|
-
const MAX_ENTRIES_VISITED = 5000;
|
|
150
|
-
const SCAN_DEADLINE_MS = 1000;
|
|
151
|
-
|
|
152
|
-
// Directory names are repo-controlled text, and this hook's output lands in the model's context.
|
|
153
|
-
// A nested path is listed only when every segment is a plain name; anything else (spaces, newlines,
|
|
154
|
-
// backticks, prose) is counted but never echoed, so a folder cannot be named into an instruction.
|
|
155
|
-
// Tradeoff, named: a legitimate folder like "my app/CLAUDE.md" is counted, not listed.
|
|
156
|
-
const SAFE_SEGMENT_RE = /^[A-Za-z0-9._-]{1,64}$/;
|
|
157
|
-
|
|
158
|
-
function isListablePath(rel) {
|
|
159
|
-
return rel.split(/[\\/]/).every((seg) => SAFE_SEGMENT_RE.test(seg));
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// bash's closing directive line (verbatim, including the embedded single quotes bash's
|
|
163
|
-
// `$'...'\''...'\''...'` escaping decodes to). Byte-exact against the fixture's
|
|
164
|
-
// expect_context substrings.
|
|
165
|
-
const DIRECTIVE =
|
|
166
|
-
"\n`cost: high` actions (/discover, /design, /refactor-design, 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 execution 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.";
|
|
167
|
-
|
|
168
|
-
function isFile(p) {
|
|
169
|
-
try {
|
|
170
|
-
return fs.statSync(p).isFile();
|
|
171
|
-
} catch {
|
|
172
|
-
return false;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function isDirectory(p) {
|
|
177
|
-
try {
|
|
178
|
-
return fs.statSync(p).isDirectory();
|
|
179
|
-
} catch {
|
|
180
|
-
return false;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// Nested CLAUDE.md/AGENTS.md scan, bounded to depth 3, actually pruning the four top-level
|
|
185
|
-
// directories (see THE PRUNE-LIST DECISION above). `depth` is the depth of the entries being
|
|
186
|
-
// iterated inside `dir` (root's direct children are depth 1). Capped at MAX_NESTED_RESULTS,
|
|
187
|
-
// matching bash's `| head -n 10`. Directory-listing order is filesystem-dependent in both
|
|
188
|
-
// implementations (find and readdirSync both return raw, unsorted directory order) — not a
|
|
189
|
-
// port-introduced nondeterminism, and no fixture case stages more than 2 nested matches, so
|
|
190
|
-
// this never matters for what's actually asserted.
|
|
191
|
-
function scanNested(root) {
|
|
192
|
-
const results = [];
|
|
193
|
-
const deadline = Date.now() + SCAN_DEADLINE_MS;
|
|
194
|
-
let visited = 0;
|
|
195
|
-
|
|
196
|
-
function walk(dir, depth) {
|
|
197
|
-
if (results.length >= MAX_NESTED_RESULTS) return;
|
|
198
|
-
if (visited >= MAX_ENTRIES_VISITED || Date.now() > deadline) return;
|
|
199
|
-
let entries;
|
|
200
|
-
try {
|
|
201
|
-
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
202
|
-
} catch {
|
|
203
|
-
return; // matches find's `2>/dev/null` — an unreadable subtree is silently skipped.
|
|
204
|
-
}
|
|
205
|
-
for (const entry of entries) {
|
|
206
|
-
if (results.length >= MAX_NESTED_RESULTS) return;
|
|
207
|
-
if (++visited > MAX_ENTRIES_VISITED) return;
|
|
208
|
-
const full = path.join(dir, entry.name);
|
|
209
|
-
if (entry.isDirectory()) {
|
|
210
|
-
if (depth === 1 && PRUNED_TOP_LEVEL_DIRS.has(entry.name)) continue;
|
|
211
|
-
if (depth + 1 <= MAX_DEPTH) walk(full, depth + 1);
|
|
212
|
-
continue;
|
|
213
|
-
}
|
|
214
|
-
if (!entry.isFile()) continue; // false for symlinks and dir-named entries — see header.
|
|
215
|
-
if (depth < MIN_DEPTH) continue;
|
|
216
|
-
if (!NESTED_NAMES.has(entry.name)) continue;
|
|
217
|
-
results.push(path.relative(root, full));
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
walk(root, 1);
|
|
222
|
-
return results;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
// bash: `find "$PROJECT_ROOT/.claude/agents" -maxdepth 1 -name '*.md' -type f | wc -l`.
|
|
226
|
-
function countAgentDefs(agentsDir) {
|
|
227
|
-
let entries;
|
|
228
|
-
try {
|
|
229
|
-
entries = fs.readdirSync(agentsDir, { withFileTypes: true });
|
|
230
|
-
} catch {
|
|
231
|
-
return 0;
|
|
232
|
-
}
|
|
233
|
-
return entries.filter((e) => e.isFile() && e.name.endsWith('.md')).length;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
function main() {
|
|
237
|
-
readPayload(); // Drains stdin, matching bash's `somi::read_payload` call. No payload field is
|
|
238
|
-
// read anywhere in this hook (grepped: bash never calls `somi::field` here either) — this is
|
|
239
|
-
// pure discovery over the filesystem, not the tool-call JSON.
|
|
240
|
-
|
|
241
|
-
const root = projectRoot();
|
|
242
|
-
|
|
243
|
-
const found = [];
|
|
244
|
-
for (const f of ROOT_FILES) {
|
|
245
|
-
if (isFile(path.join(root, f))) found.push(f);
|
|
246
|
-
}
|
|
247
|
-
let unlisted = 0;
|
|
248
|
-
for (const rel of scanNested(root)) {
|
|
249
|
-
if (isListablePath(rel)) found.push(rel);
|
|
250
|
-
else unlisted += 1;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
let repoAgents = '';
|
|
254
|
-
const agentsDir = path.join(root, '.claude', 'agents');
|
|
255
|
-
if (isDirectory(agentsDir)) {
|
|
256
|
-
const count = countAgentDefs(agentsDir);
|
|
257
|
-
if (count > 0) {
|
|
258
|
-
repoAgents = `.claude/agents/ (${count} repo-local subagent definition(s))`;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
if (found.length === 0 && !repoAgents && unlisted === 0) return;
|
|
263
|
-
|
|
264
|
-
let msg =
|
|
265
|
-
'somi repo-awareness — this repository ships its own instructions/agents. Respect them as context:';
|
|
266
|
-
|
|
267
|
-
// De-duplicate while preserving order (mirrors bash's `seen` accumulator). Structurally
|
|
268
|
-
// unreachable today — ROOT_FILES entries and scanNested() results can never collide, since
|
|
269
|
-
// the former are always single-segment (or the fixed two-segment copilot path) and the
|
|
270
|
-
// latter are always depth >= 2 relative paths pointing at a different filename set — but
|
|
271
|
-
// reproduced anyway for defensive fidelity with the bash original.
|
|
272
|
-
const seen = new Set();
|
|
273
|
-
for (const f of found) {
|
|
274
|
-
if (seen.has(f)) continue;
|
|
275
|
-
seen.add(f);
|
|
276
|
-
msg += `\n - ${f}`;
|
|
277
|
-
}
|
|
278
|
-
if (unlisted > 0) {
|
|
279
|
-
msg += `\n - ${unlisted} nested CLAUDE.md/AGENTS.md file(s) under folder names with unusual characters (not listed; find them with a file search)`;
|
|
280
|
-
}
|
|
281
|
-
if (repoAgents) msg += `\n - ${repoAgents}`;
|
|
282
|
-
msg += DIRECTIVE;
|
|
283
|
-
|
|
284
|
-
contextOutput('SessionStart', msg);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
runHook(main);
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// hooks/session-start/ensure-default-config.mjs — SessionStart hook — create a default
|
|
3
|
-
// .somi/config.json when the project has none.
|
|
4
|
-
//
|
|
5
|
-
// Without a config every agent runs at the built-in default ceiling, so the agents built for the
|
|
6
|
-
// strongest tier (reviewers, designer, security-reviewer, ...) would silently run lower. The default
|
|
7
|
-
// file pins each agent to the highest tier it declares and sets the ceiling; see
|
|
8
|
-
// scripts/lib/cost-defaults.mjs for the table and the exact text this hook writes.
|
|
9
|
-
//
|
|
10
|
-
// With a global config (scripts/lib/config-files.mjs), that file already supplies the defaults, and a
|
|
11
|
-
// fully pinned project file would mask every one of its values, so nothing is written.
|
|
12
|
-
//
|
|
13
|
-
// Guarantees (a project's own files are untrusted, and a hook must never block a session):
|
|
14
|
-
// - Acts only when NOTHING exists at <root>/.somi/config.json (lstat ENOENT) and no global config
|
|
15
|
-
// file exists. An existing file of any kind — valid, invalid JSON, a symlink (even dangling), a
|
|
16
|
-
// directory — is left untouched.
|
|
17
|
-
// - `.somi` must be a real directory (lstat) or absent; a symlink or file there writes nothing.
|
|
18
|
-
// It is created with mode 0700 only when absent.
|
|
19
|
-
// - The file is created with O_CREAT|O_EXCL|O_NOFOLLOW, so a race or a planted link at the path
|
|
20
|
-
// can never be written through. Nothing else is written anywhere.
|
|
21
|
-
// - The content is a fixed constant, never derived from any existing file.
|
|
22
|
-
// - Exit code is 0 on every path; no file content or error text is printed. On success it prints
|
|
23
|
-
// one short, fixed notice through the same SessionStart channel the sibling hook uses.
|
|
24
|
-
// - When a config file already exists (project or global), the effective config is only READ,
|
|
25
|
-
// through the shared loader (links followed, regular files of at most 64 KiB): if it has no
|
|
26
|
-
// cost.agents["somi-security-reviewer"] tier, or one below high, one fixed notice says so (a distinct
|
|
27
|
-
// text for each, naming the global config when there is one). An unreadable or invalid config prints
|
|
28
|
-
// nothing (the resolver reports it). Nothing from a file reaches the notice, and no file is written.
|
|
29
|
-
|
|
30
|
-
import fs from 'node:fs';
|
|
31
|
-
import path from 'node:path';
|
|
32
|
-
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
33
|
-
import { projectRoot, contextOutput, runHook } from '../lib/common.mjs';
|
|
34
|
-
|
|
35
|
-
const LIB = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', '..', 'scripts', 'lib');
|
|
36
|
-
const DEFAULTS_LIB = path.join(LIB, 'cost-defaults.mjs');
|
|
37
|
-
const CONFIG_LIB = path.join(LIB, 'config-files.mjs');
|
|
38
|
-
const CREATE = fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_EXCL | (fs.constants.O_NOFOLLOW ?? 0);
|
|
39
|
-
const LOW_PIN_NOTICE = 'SoMi: .somi/config.json pins somi-security-reviewer below high; its security reviews run at that lower tier.';
|
|
40
|
-
const PIN_NOTICE = 'SoMi: .somi/config.json has no cost.agents pin for somi-security-reviewer, so it runs at the ceiling (below high by default). Pin it under cost.agents to keep the strong pass.';
|
|
41
|
-
const GLOBAL_LOW_PIN_NOTICE = 'SoMi: the SoMi config (your global config, with any .somi/config.json over it) pins somi-security-reviewer below high; its security reviews run at that lower tier.';
|
|
42
|
-
const GLOBAL_PIN_NOTICE = 'SoMi: the SoMi config (your global config, with any .somi/config.json over it) has no cost.agents pin for somi-security-reviewer, so it runs at the ceiling (below high by default). Pin it under cost.agents to keep the strong pass.';
|
|
43
|
-
|
|
44
|
-
function writeAll(fd, text) {
|
|
45
|
-
const buf = Buffer.from(text);
|
|
46
|
-
for (let off = 0; off < buf.length;) off += fs.writeSync(fd, buf, off, buf.length - off);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// For the effective config: 'missing' when it has no own, valid-tier cost.agents["somi-security-reviewer"],
|
|
50
|
-
// 'low' when that entry is below high, else null.
|
|
51
|
-
function securityPinState(cfg) {
|
|
52
|
-
const agents = cfg.cost && typeof cfg.cost === 'object' ? cfg.cost.agents : undefined;
|
|
53
|
-
const tier = agents && typeof agents === 'object' && Object.hasOwn(agents, 'somi-security-reviewer') ? agents['somi-security-reviewer'] : undefined;
|
|
54
|
-
if (tier === 'low' || tier === 'medium') return 'low';
|
|
55
|
-
return tier === 'high' ? null : 'missing';
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function lstatOrNull(p) {
|
|
59
|
-
try { return fs.lstatSync(p); } catch (e) { if (e.code === 'ENOENT') return null; throw e; }
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
async function main() {
|
|
63
|
-
try {
|
|
64
|
-
const root = projectRoot();
|
|
65
|
-
if (!fs.statSync(root).isDirectory()) return;
|
|
66
|
-
const somi = path.join(root, '.somi');
|
|
67
|
-
const file = path.join(somi, 'config.json');
|
|
68
|
-
const { loadConfig, globalConfigPath } = await import(pathToFileURL(CONFIG_LIB).href);
|
|
69
|
-
const globalFile = globalConfigPath();
|
|
70
|
-
const hasGlobal = globalFile !== null && lstatOrNull(globalFile) !== null;
|
|
71
|
-
const dir = lstatOrNull(somi);
|
|
72
|
-
const existing = lstatOrNull(file); // through a linked .somi too: reads follow links
|
|
73
|
-
if (existing || hasGlobal) { // a config exists: it is only read, never written
|
|
74
|
-
let files = null;
|
|
75
|
-
try { files = loadConfig(root); } catch { /* the resolver reports an unreadable config */ }
|
|
76
|
-
const pin = files && (files.project.present || files.global.present) ? securityPinState(files.config) : null;
|
|
77
|
-
if (pin === 'low') contextOutput('SessionStart', hasGlobal ? GLOBAL_LOW_PIN_NOTICE : LOW_PIN_NOTICE);
|
|
78
|
-
else if (pin) contextOutput('SessionStart', hasGlobal ? GLOBAL_PIN_NOTICE : PIN_NOTICE);
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
if (dir && !dir.isDirectory()) return; // a symlinked .somi or a file: write nothing
|
|
82
|
-
const { serializeDefaultConfig, buildDefaultConfig } = await import(pathToFileURL(DEFAULTS_LIB).href);
|
|
83
|
-
const text = serializeDefaultConfig();
|
|
84
|
-
const ceiling = buildDefaultConfig().cost.ceiling;
|
|
85
|
-
if (!dir) {
|
|
86
|
-
try {
|
|
87
|
-
fs.mkdirSync(somi, { mode: 0o700 });
|
|
88
|
-
} catch (e) {
|
|
89
|
-
if (e.code !== 'EEXIST') return;
|
|
90
|
-
if (!lstatOrNull(somi)?.isDirectory()) return; // lost a race to a link or a file
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
const fd = fs.openSync(file, CREATE, 0o644);
|
|
94
|
-
try {
|
|
95
|
-
writeAll(fd, text);
|
|
96
|
-
} catch {
|
|
97
|
-
// We created it a moment ago; do not leave half a file, but never remove a swapped path.
|
|
98
|
-
try {
|
|
99
|
-
const mine = fs.fstatSync(fd);
|
|
100
|
-
const now = lstatOrNull(file);
|
|
101
|
-
if (now && now.dev === mine.dev && now.ino === mine.ino) fs.rmSync(file, { force: true });
|
|
102
|
-
} catch { /* leave it */ }
|
|
103
|
-
fs.closeSync(fd);
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
fs.closeSync(fd);
|
|
107
|
-
contextOutput('SessionStart', `SoMi created .somi/config.json with default cost settings: ceiling ${ceiling}, each agent pinned to its default tier. Run /somi-config, or edit "cost" in .somi/config.json, to change them.`);
|
|
108
|
-
} catch {
|
|
109
|
-
// Any failure (read-only directory, EEXIST race, missing plugin file) is a silent no-op.
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
runHook(() => main().then(() => { process.exitCode = 0; }));
|