@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,146 +0,0 @@
|
|
|
1
|
-
// escalation-facts.mjs — diffFacts(rows, options): the facts escalation() reads, from the per-file rows of a diff.
|
|
2
|
-
//
|
|
3
|
-
// A row is { file, added, deleted, status }: the changed-file listing's shape plus git's status letter. The listing must be
|
|
4
|
-
// read NUL-separated (`-z`): git's default form quotes a non-ASCII name (`"\303\251/a.pem"`), which the deny list cannot
|
|
5
|
-
// read, so a name that starts with a double quote is an unusable row here (a name that really starts with one over-flags),
|
|
6
|
-
// and so is a name with a control, format or line-separator character (`.e<ZWNJ>nv` is `.env` on HFS+).
|
|
7
|
-
// Pure but for a clock: no filesystem, no git, no content, and no path in the result. Returns
|
|
8
|
-
// { facts, source, notes }
|
|
9
|
-
// facts escalation()'s input: counts, flags and class names from its closed lists
|
|
10
|
-
// source where each plan input came from: { plan: ['target'|'paths'], sdlc: ['slug'|'paths'] }, as ids
|
|
11
|
-
// notes ids of what degraded: rows_unusable (not a list, over MAX_ROWS, or a count past the safe integers), row_unusable, time_box, config_refused,
|
|
12
|
-
// internal_error (a bug here: the result is the floor, never a throw)
|
|
13
|
-
// options: { config, slug, target, planPaths, workItemPaths, budgetMs }. `config` is loadConfig's `{global, project}` result or
|
|
14
|
-
// nothing: any other shape (a merged `.config` erases the user's own additions) is noted `config_refused`, adds the sensitive name
|
|
15
|
-
// `config` (a refused config must raise, never lower) and the built-in lists apply. The layers are read once, into plain copies
|
|
16
|
-
// (a getter cannot answer differently on a later read), and those copies are what the classifier sees.
|
|
17
|
-
// A key of it that classifyPaths refuses is noted too. Only a refused `sensitive_paths` adds `config`; a refused `module_containers`
|
|
18
|
-
// adds nothing, and the module count then reads low (the container names group more children into modules).
|
|
19
|
-
// `target` is the review target a caller names (a plan directory, a brief or an ADR path), judged by its name only. `planPaths`
|
|
20
|
-
// and `workItemPaths` are names-only lists the caller built; only whether they are empty matters. `budgetMs` can only shorten
|
|
21
|
-
// TIME_BOX_MS.
|
|
22
|
-
//
|
|
23
|
-
// Every degraded outcome (an unusable row too: it may hide anything) is the FLOOR, the top of the lattice: every count at the cap, every
|
|
24
|
-
// class name, every flag, so each seat, reason, hard-surface id and flag is at least a full read's. A time box cannot interrupt
|
|
25
|
-
// synchronous code, so the clock is read between chunks of CHUNK rows: the bound is the budget plus one chunk, which is small
|
|
26
|
-
// because classifyPaths caps the cost of one path. The clock starts before the first row is read, so the row checks count too, and
|
|
27
|
-
// it is read at least once whatever the kept count. A denied name sets `denied` whatever its status or prefix: a deleted `.env`
|
|
28
|
-
// floors, and so does one under `.somi/`. Rows under `.somi/` and `.claude/` are ignored (the measurement excludes them), by their
|
|
29
|
-
// exact prefix, and every row, ignored or not, is read for the guard: on its segments folded as the deny list folds them (case,
|
|
30
|
-
// compatibility forms, trailing dots and spaces, either separator) a segment `.claude` at any depth and with no exemption, a
|
|
31
|
-
// `CLAUDE.md`, `CLAUDE.local.md` or `AGENTS.md` segment at any depth, a `.mcp.json` segment at any depth, a `.vscode` segment directly followed by
|
|
32
|
-
// `mcp.json` (project MCP servers: a command that runs on a developer's machine), or a first segment `.somi` alone or followed
|
|
33
|
-
// by `config.json` or `rules`, is the sensitive name `config`. A case variant (`agents.md`) raises too: the folded name is the name. A row that is not a plain name (an empty, `.` or `..`
|
|
34
|
-
// segment, git never writes one) is unusable.
|
|
35
|
-
// `new_top_dirs` counts first directories whose every changed row is an add; a diff cannot know the base, so a directory that
|
|
36
|
-
// existed and only gained files reads as new, and the residual is one extra architecture seat.
|
|
37
|
-
import { MAX_GLOBS, classifyPaths } from './path-facts.mjs';
|
|
38
|
-
import { MAX_PATH_CHARS, UNSAFE_CHARS, denyListed, foldName, trimDots } from './path-safety.mjs';
|
|
39
|
-
import { CLASS_NAMES } from './escalation.mjs';
|
|
40
|
-
|
|
41
|
-
export const MAX_ROWS = 2000;
|
|
42
|
-
export const TIME_BOX_MS = 3000;
|
|
43
|
-
const CHUNK = 10; // rows per clock read: well under classifyPaths' list cap, and about 0.6 s at its worst-case cost per path
|
|
44
|
-
const KINDS = ['sensitive', 'boundary', 'contract'];
|
|
45
|
-
const COUNTS = ['production_lines', 'production_files', 'test_lines_added', 'test_lines_deleted', 'test_files_deleted', 'test_files_changed', 'modules', 'new_top_dirs'];
|
|
46
|
-
|
|
47
|
-
const count = (v) => Number.isSafeInteger(v) && v >= 0;
|
|
48
|
-
const SEP = /[\\/]/;
|
|
49
|
-
// A name's segments as the deny list reads them: each raw segment folded and re-split (a fold can make a separator), dots and spaces trimmed off the end.
|
|
50
|
-
const pieces = (file) => file.split(SEP).flatMap((s) => foldName(s).split(SEP)).map(trimDots);
|
|
51
|
-
const sane = (r) => r !== null && typeof r === 'object' && typeof r.file === 'string' && r.file.length > 0 && r.file.length <= MAX_PATH_CHARS && foldName(r.file).length <= MAX_PATH_CHARS
|
|
52
|
-
&& !r.file.startsWith('"') && !UNSAFE_CHARS.test(r.file) && !pieces(r.file).includes('') && count(r.added) && count(r.deleted) && typeof r.status === 'string' && /^[A-Z]$/.test(r.status);
|
|
53
|
-
const hidden = (file) => ['.somi', '.claude'].includes(file.split('/')[0]);
|
|
54
|
-
const guarded = (file) => {
|
|
55
|
-
const segs = pieces(file); const [head, second] = segs;
|
|
56
|
-
return segs.includes('.claude') || segs.includes('claude.md') || segs.includes('claude.local.md') || segs.includes('agents.md') || segs.includes('.mcp.json')
|
|
57
|
-
|| segs.some((s, i) => s === '.vscode' && segs[i + 1] === 'mcp.json') || (head === '.somi' && (second === undefined || second === 'config.json' || second === 'rules'));
|
|
58
|
-
};
|
|
59
|
-
const plain = (o) => o !== null && typeof o === 'object' && !Array.isArray(o);
|
|
60
|
-
const once = (o, k) => (plain(o) && Object.hasOwn(o, k) ? o[k] : undefined); // the one read of a key
|
|
61
|
-
// A list read by index into a plain array, capped just over the limit (a list over the cap stays over it); a hole reads as undefined, which the classifier refuses.
|
|
62
|
-
const glist = (v) => (Array.isArray(v) ? Array.from({ length: Math.min(v.length, MAX_GLOBS + 1) }, (_, i) => v[i]) : v);
|
|
63
|
-
// The config layers as plain copies of what the classifier reads, each accessor read once; null when the shape is not loadConfig's.
|
|
64
|
-
function layersOf(c) {
|
|
65
|
-
if (c === undefined) return [];
|
|
66
|
-
const layers = [];
|
|
67
|
-
for (const k of ['global', 'project']) {
|
|
68
|
-
const cfg = once(once(c, k), 'config');
|
|
69
|
-
if (!plain(cfg)) return null;
|
|
70
|
-
const sizing = once(cfg, 'sizing');
|
|
71
|
-
layers.push({ sizing: { sensitive_paths: glist(once(sizing, 'sensitive_paths')), module_containers: glist(once(sizing, 'module_containers')) } });
|
|
72
|
-
}
|
|
73
|
-
return layers;
|
|
74
|
-
}
|
|
75
|
-
const given = (v) => v !== undefined && v !== null && v !== false && v !== '' && !(Array.isArray(v) && v.length === 0);
|
|
76
|
-
const PLAN_TARGET = /(^|\/)(\.somi\/plans|adrs?|decisions)(\/|$)|(^|\/)(brief\.md|adr[-_]?\d[^/]*)$/;
|
|
77
|
-
const names = (set) => [...set].sort();
|
|
78
|
-
|
|
79
|
-
// An unusable `target` (not a string, or over the length cap) counts as a plan target: a bad input raises a seat, never removes one.
|
|
80
|
-
function planInputs({ slug, target, planPaths, workItemPaths }) {
|
|
81
|
-
const named = given(target) && (typeof target !== 'string' || target.length > MAX_PATH_CHARS || PLAN_TARGET.test(target.normalize('NFKC').toLowerCase().replaceAll('\\', '/')));
|
|
82
|
-
const facts = { plan_target: named, plan_paths: given(planPaths), slug_given: given(slug), work_item_paths: given(workItemPaths) };
|
|
83
|
-
const source = { plan: [...(named ? ['target'] : []), ...(facts.plan_paths ? ['paths'] : [])], sdlc: [...(facts.slug_given ? ['slug'] : []), ...(facts.work_item_paths ? ['paths'] : [])] };
|
|
84
|
-
return { facts, source };
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const EVERY_PLAN_SEAT = { facts: { plan_target: true, plan_paths: true, slug_given: true, work_item_paths: true }, source: { plan: ['target', 'paths'], sdlc: ['slug', 'paths'] } };
|
|
88
|
-
|
|
89
|
-
// No test lines added and no test file changed keep `tests_weakened` and `untested_production` on: they are the two facts a count cannot raise.
|
|
90
|
-
const floor = (plan) => ({ ...Object.fromEntries(COUNTS.map((k) => [k, 1e9])), test_lines_added: 0, test_files_changed: 0, denied: true, ...plan,
|
|
91
|
-
classes: Object.fromEntries(Object.entries(CLASS_NAMES).map(([k, v]) => [k, [...v]])) });
|
|
92
|
-
|
|
93
|
-
function measure(rows, opts, plan) {
|
|
94
|
-
const start = Date.now();
|
|
95
|
-
if (!Array.isArray(rows) || rows.length > MAX_ROWS) return { facts: floor(plan), notes: ['rows_unusable'] };
|
|
96
|
-
if (!rows.every(sane)) return { facts: floor(plan), notes: ['row_unusable'] };
|
|
97
|
-
const f = { ...Object.fromEntries(COUNTS.map((k) => [k, 0])), denied: false, ...plan };
|
|
98
|
-
const seen = { sensitive: new Set(), boundary: new Set(), contract: new Set() };
|
|
99
|
-
const modules = new Set(); const tops = new Map(); const kept = []; const notes = new Set();
|
|
100
|
-
const layers = layersOf(opts.config);
|
|
101
|
-
if (layers === null) { notes.add('config_refused'); seen.sensitive.add('config'); }
|
|
102
|
-
const config = layers ?? [];
|
|
103
|
-
const refused = classifyPaths([], config).refused; // no row may be needed to learn that a key was refused
|
|
104
|
-
if (refused.length > 0) notes.add('config_refused');
|
|
105
|
-
if (refused.includes('sensitive_paths')) seen.sensitive.add('config');
|
|
106
|
-
for (const r of rows) {
|
|
107
|
-
if (guarded(r.file)) seen.sensitive.add('config');
|
|
108
|
-
if (!hidden(r.file)) kept.push(r); else f.denied ||= denyListed(r.file);
|
|
109
|
-
}
|
|
110
|
-
const budget = Math.min(TIME_BOX_MS, Number.isFinite(opts.budgetMs) && opts.budgetMs >= 0 ? opts.budgetMs : TIME_BOX_MS);
|
|
111
|
-
let at = 0;
|
|
112
|
-
do { // the clock is read at least once, whatever the kept count
|
|
113
|
-
if (Date.now() - start >= budget) return { facts: floor(plan), notes: ['time_box'] };
|
|
114
|
-
const chunk = kept.slice(at, at + CHUNK);
|
|
115
|
-
const result = classifyPaths(chunk.map((r) => r.file), config);
|
|
116
|
-
result.files.forEach((c, j) => {
|
|
117
|
-
const r = chunk[j];
|
|
118
|
-
f.denied ||= c.denied;
|
|
119
|
-
for (const k of KINDS) c[k].forEach((n) => seen[k].add(n));
|
|
120
|
-
modules.add(c.module);
|
|
121
|
-
if (c.production) { f.production_lines += r.added + r.deleted; f.production_files++; } else {
|
|
122
|
-
f.test_lines_added += r.added; f.test_lines_deleted += r.deleted; f.test_files_changed++;
|
|
123
|
-
if (r.status === 'D') f.test_files_deleted++;
|
|
124
|
-
}
|
|
125
|
-
const dirs = r.file.split(/[\\/]+/).filter((x) => x !== '' && x !== '.');
|
|
126
|
-
if (dirs.length > 1) tops.set(dirs[0], (tops.get(dirs[0]) ?? true) && r.status === 'A');
|
|
127
|
-
});
|
|
128
|
-
at += CHUNK;
|
|
129
|
-
} while (at < kept.length);
|
|
130
|
-
f.modules = modules.size; f.new_top_dirs = [...tops.values()].filter(Boolean).length;
|
|
131
|
-
if (!COUNTS.every((k) => count(f[k]))) return { facts: floor(plan), notes: ['rows_unusable'] }; // a sum past the safe integers is no count
|
|
132
|
-
// CI paths are a sensitive name (they raise security); `classes.ci` carries the hard-surface id beside it.
|
|
133
|
-
f.classes = { sensitive: names(seen.sensitive), boundary: names(seen.boundary), contract: names(seen.contract), ci: seen.sensitive.has('ci') ? ['ci'] : [] };
|
|
134
|
-
return { facts: f, notes: names(notes) };
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export function diffFacts(rows, options) {
|
|
138
|
-
let plan = EVERY_PLAN_SEAT; // until the options are read
|
|
139
|
-
try {
|
|
140
|
-
const opts = options ?? {};
|
|
141
|
-
plan = planInputs(opts);
|
|
142
|
-
return { ...measure(rows, opts, plan.facts), source: plan.source };
|
|
143
|
-
} catch {
|
|
144
|
-
return { facts: floor(plan.facts), source: plan.source, notes: ['internal_error'] };
|
|
145
|
-
}
|
|
146
|
-
}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
// escalation.mjs — escalation(facts): which review lenses does the shape of a diff warrant?
|
|
2
|
-
//
|
|
3
|
-
// Pure: no import, no filesystem, no clock, no content. The input is counts, flags and class names (what
|
|
4
|
-
// classifyPaths and a diff's per-file rows give); no path and no diff text goes in, so none can come out. Output:
|
|
5
|
-
// { review_min, reasons, tests_weakened, size_flag, hard_surface, seats: { <lens>: { seat, reasons } } }
|
|
6
|
-
// `review_min` is `security` or null and nothing else (the loop's validator allows only that). A sensitive or
|
|
7
|
-
// boundary class name, a denied name or weakened tests raise it. Size only marks: `size_flag` changes no lens.
|
|
8
|
-
//
|
|
9
|
-
// Raise-only, with two exceptions: every fact is ordered (a class name present, a flag set, a count over its edge is the
|
|
10
|
-
// more alarming value) and every output grows with it, so a fact added never removes a seat, a reason, a hard-surface id
|
|
11
|
-
// or the flag, except more test lines added (`tests_weakened` reads net lines, so padding tests switches it off) and a
|
|
12
|
-
// test file changed (drops `untested_production`). There is no config. A result is never lowered across passes because
|
|
13
|
-
// the loop takes the max with the earlier pass. The input is a closed grammar read once into a plain
|
|
14
|
-
// copy: an unknown or missing key, a wrong type, a negative count, an unknown class name, an accessor or a
|
|
15
|
-
// non-plain object is the refused result, which is the raising result (every seat, every hard-surface id), as
|
|
16
|
-
// size-tier does for unreadable signals. An unexpected error in the rules themselves (a bug, not the input) is the same raising
|
|
17
|
-
// result under its own reason id, so it is not reported as unreadable input. `escalation` never throws.
|
|
18
|
-
//
|
|
19
|
-
// Provisional: the numbers are the research report's guesses (150 lines, 5 files) or the planner's, and live
|
|
20
|
-
// here so they can be fitted without touching the rules.
|
|
21
|
-
|
|
22
|
-
export const SIZE_FLAG_LINES = 150;
|
|
23
|
-
export const SIZE_FLAG_FILES = 5;
|
|
24
|
-
export const WEAKENED_NET_LINES = 20;
|
|
25
|
-
export const MAX_MODULES_SEAT = 2;
|
|
26
|
-
export const LARGE_TEST_CHANGE = 100;
|
|
27
|
-
export const UNTESTED_PRODUCTION_LINES = 60;
|
|
28
|
-
export const MAX_CLASS_NAMES = 16;
|
|
29
|
-
export const REFUSED_REASON = 'facts_unreadable';
|
|
30
|
-
export const INTERNAL_REASON = 'internal_error';
|
|
31
|
-
const DENY = 'deny_list';
|
|
32
|
-
|
|
33
|
-
const freezeAll = (o) => Object.freeze(Object.fromEntries(Object.entries(o).map(([k, v]) => [k, Object.freeze(v)])));
|
|
34
|
-
export const HARD_SURFACE_IDS = Object.freeze(['ci', DENY, 'lockfile', 'manifest', 'migration', 'schema']);
|
|
35
|
-
export const CLASS_NAMES = freezeAll({
|
|
36
|
-
sensitive: ['auth', 'ci', 'config', 'crypto', DENY, 'infra', 'migrations', 'secrets'],
|
|
37
|
-
boundary: ['data', DENY, 'input', 'process', 'routes'],
|
|
38
|
-
contract: ['lockfile', 'manifest', 'schema'],
|
|
39
|
-
ci: ['ci'],
|
|
40
|
-
});
|
|
41
|
-
// The reason ids each lens can carry (`sensitive:<name>` and `contract:<name>` are listed by prefix); the lens table in
|
|
42
|
-
// the review-panel flow is compared with this.
|
|
43
|
-
export const SEAT_REASONS = freezeAll({
|
|
44
|
-
'somi-reviewer': ['always'],
|
|
45
|
-
'somi-security-reviewer': ['sensitive', 'boundary', DENY, 'tests_weakened'],
|
|
46
|
-
'somi-architecture-reviewer': ['new_top_dirs', 'contract', 'modules'],
|
|
47
|
-
'somi-test-strategist': ['tests_weakened', 'large_test_change', 'untested_production'],
|
|
48
|
-
'somi-plan-reviewer': ['plan_target', 'plan_paths'],
|
|
49
|
-
'somi-sdlc-reviewer': ['slug_given', 'work_item_paths'],
|
|
50
|
-
});
|
|
51
|
-
const SEATS = Object.keys(SEAT_REASONS);
|
|
52
|
-
const COUNTS = ['production_lines', 'production_files', 'test_lines_added', 'test_lines_deleted', 'test_files_deleted', 'test_files_changed', 'modules', 'new_top_dirs'];
|
|
53
|
-
const FLAGS = ['denied', 'plan_target', 'plan_paths', 'slug_given', 'work_item_paths'];
|
|
54
|
-
|
|
55
|
-
const refuse = () => { throw new TypeError('unreadable facts'); };
|
|
56
|
-
const isPlain = (o) => o !== null && typeof o === 'object' && [Object.prototype, null].includes(Object.getPrototypeOf(o));
|
|
57
|
-
const own = (o, k) => { const d = Object.getOwnPropertyDescriptor(o, k); return d && 'value' in d ? d.value : refuse(); };
|
|
58
|
-
const keysAre = (o, want) => { const have = Reflect.ownKeys(o); return (have.length === want.length && want.every((k) => have.includes(k))) || refuse(); };
|
|
59
|
-
|
|
60
|
-
function names(list, allowed) {
|
|
61
|
-
if (!Array.isArray(list) || Object.getPrototypeOf(list) !== Array.prototype || list.length > MAX_CLASS_NAMES) refuse();
|
|
62
|
-
const slots = Array.from({ length: list.length }, (_, i) => String(i));
|
|
63
|
-
keysAre(list, [...slots, 'length']);
|
|
64
|
-
const out = slots.map((i) => own(list, i));
|
|
65
|
-
return out.every((n) => allowed.includes(n)) ? [...new Set(out)].sort() : refuse();
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function read(facts) {
|
|
69
|
-
if (!isPlain(facts)) refuse();
|
|
70
|
-
keysAre(facts, [...COUNTS, ...FLAGS, 'classes']);
|
|
71
|
-
const f = {};
|
|
72
|
-
for (const k of COUNTS) { const v = own(facts, k); f[k] = Number.isSafeInteger(v) && v >= 0 ? v : refuse(); }
|
|
73
|
-
for (const k of FLAGS) { const v = own(facts, k); f[k] = typeof v === 'boolean' ? v : refuse(); }
|
|
74
|
-
const classes = own(facts, 'classes');
|
|
75
|
-
if (!isPlain(classes)) refuse();
|
|
76
|
-
keysAre(classes, Object.keys(CLASS_NAMES));
|
|
77
|
-
f.classes = Object.fromEntries(Object.keys(CLASS_NAMES).map((k) => [k, names(own(classes, k), CLASS_NAMES[k])]));
|
|
78
|
-
return f;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const seated = (byLens) => Object.fromEntries(SEATS.map((l) => [l, { seat: byLens[l].length > 0, reasons: byLens[l] }]));
|
|
82
|
-
const when = (on, id) => (on ? [id] : []);
|
|
83
|
-
|
|
84
|
-
function judge(f) {
|
|
85
|
-
const { sensitive, boundary, contract, ci } = f.classes;
|
|
86
|
-
const net = f.test_lines_added - f.test_lines_deleted;
|
|
87
|
-
const tests_weakened = net < 0 && (f.test_files_deleted >= 1 || -net >= WEAKENED_NET_LINES);
|
|
88
|
-
const denied = f.denied || sensitive.includes(DENY) || boundary.includes(DENY);
|
|
89
|
-
const reasons = [
|
|
90
|
-
...sensitive.filter((n) => n !== DENY).map((n) => `sensitive:${n}`),
|
|
91
|
-
...boundary.filter((n) => n !== DENY).map((n) => `boundary:${n}`),
|
|
92
|
-
...when(denied, DENY), ...when(tests_weakened, 'tests_weakened'),
|
|
93
|
-
];
|
|
94
|
-
const hard = [...contract, ...when(sensitive.includes('migrations'), 'migration'), ...when(ci.length > 0 || sensitive.includes('ci'), 'ci'), ...when(denied, DENY)];
|
|
95
|
-
return {
|
|
96
|
-
review_min: reasons.length > 0 ? 'security' : null,
|
|
97
|
-
reasons,
|
|
98
|
-
tests_weakened,
|
|
99
|
-
size_flag: f.production_lines > SIZE_FLAG_LINES || f.production_files > SIZE_FLAG_FILES,
|
|
100
|
-
hard_surface: [...new Set(hard)].sort(),
|
|
101
|
-
seats: seated({
|
|
102
|
-
'somi-reviewer': ['always'],
|
|
103
|
-
'somi-security-reviewer': reasons,
|
|
104
|
-
'somi-architecture-reviewer': [...when(f.new_top_dirs >= 1, 'new_top_dirs'), ...contract.map((n) => `contract:${n}`), ...when(f.modules > MAX_MODULES_SEAT, 'modules')],
|
|
105
|
-
'somi-test-strategist': [
|
|
106
|
-
...when(tests_weakened, 'tests_weakened'),
|
|
107
|
-
...when(f.test_lines_added + f.test_lines_deleted >= LARGE_TEST_CHANGE, 'large_test_change'),
|
|
108
|
-
...when(f.production_lines >= UNTESTED_PRODUCTION_LINES && f.test_files_changed === 0, 'untested_production'),
|
|
109
|
-
],
|
|
110
|
-
'somi-plan-reviewer': [...when(f.plan_target, 'plan_target'), ...when(f.plan_paths, 'plan_paths')],
|
|
111
|
-
'somi-sdlc-reviewer': [...when(f.slug_given, 'slug_given'), ...when(f.work_item_paths, 'work_item_paths')],
|
|
112
|
-
}),
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const refused = (reason) => ({
|
|
117
|
-
review_min: 'security',
|
|
118
|
-
reasons: [reason],
|
|
119
|
-
tests_weakened: false,
|
|
120
|
-
size_flag: true,
|
|
121
|
-
hard_surface: [...HARD_SURFACE_IDS],
|
|
122
|
-
seats: seated(Object.fromEntries(SEATS.map((l) => [l, [reason]]))),
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
export function escalation(facts) {
|
|
126
|
-
let f;
|
|
127
|
-
try { f = read(facts); } catch { return refused(REFUSED_REASON); }
|
|
128
|
-
try { return judge(f); } catch { return refused(INTERNAL_REASON); }
|
|
129
|
-
}
|
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
// findings-ledger.mjs -- the findings ledger: identity, the ledger file and every handler (record, resolve,
|
|
2
|
-
// reopen, open, get). Each returns `{lines, code, message}`. Nothing here
|
|
3
|
-
// reads the process environment, stdin or argv, and nothing prints: the caller (somi-findings.mjs today, a tool
|
|
4
|
-
// later) hands in the project root and already-parsed arguments, and gets back the lines to print, an exit code
|
|
5
|
-
// and the stderr text. The stdin read and the JSON parse stay at the CLI, the trust boundary of the shell path.
|
|
6
|
-
//
|
|
7
|
-
// Ledger: .somi/reviews/<slug>/findings.json under the root. Locus matching: same file + same symbol
|
|
8
|
-
// (case-insensitive) + same normalized title (lowercased, non-alphanumerics collapsed, first 8 words); line
|
|
9
|
-
// numbers are deliberately NOT part of the locus, lines drift between passes. Exit codes: 0 ok, 5 consecutive
|
|
10
|
-
// recurrence detected, 64 bad input.
|
|
11
|
-
|
|
12
|
-
import fs from 'node:fs';
|
|
13
|
-
import path from 'node:path';
|
|
14
|
-
import { randomBytes } from 'node:crypto';
|
|
15
|
-
import { EXIT_CIRCUIT_BREAKER } from './loop-exit.mjs';
|
|
16
|
-
|
|
17
|
-
export const PROG = 'somi-findings';
|
|
18
|
-
|
|
19
|
-
export function ledgerPaths(root, slug) {
|
|
20
|
-
const dir = path.join(root, '.somi', 'reviews', slug);
|
|
21
|
-
return { dir, file: path.join(dir, 'findings.json') };
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function nowDateUtc() {
|
|
25
|
-
// `date -u +%Y-%m-%d` — bare date, no time component (findings' seen[].date).
|
|
26
|
-
return new Date().toISOString().slice(0, 10);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Mirrors jq's `//` alternative operator at the JSON-value level: substitutes the
|
|
30
|
-
// fallback only when the left side is `null`/missing or `false` — NOT for other
|
|
31
|
-
// falsy values like `""` or `0`, which jq treats as present. Used wherever the bash
|
|
32
|
-
// script keeps a raw JSON value (locus/severity/confidence on a newly created finding).
|
|
33
|
-
function orElse(v, fallback) {
|
|
34
|
-
return v === null || v === undefined || v === false ? fallback : v;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Mirrors `jq -r '<expr> // empty'` captured into a bash variable: same null/false
|
|
38
|
-
// substitution as orElse, then stringified (bash captures everything as text) — used
|
|
39
|
-
// wherever the bash script tests `[[ -n "$var" ]]` or concatenates into the locus key.
|
|
40
|
-
function rawStr(v) {
|
|
41
|
-
const x = orElse(v, '');
|
|
42
|
-
return x === '' ? '' : String(x);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// normalize_title() — bash pipeline: `tr '[:upper:]' '[:lower:]'` (byte-wise, ASCII-only —
|
|
46
|
-
// it only maps the 26 ASCII uppercase bytes; any multi-byte UTF-8 sequence passes through
|
|
47
|
-
// untouched) -> `tr -cs 'a-z0-9' ' '` (every maximal run of non-alphanumerics — including a
|
|
48
|
-
// leading or trailing run — collapses to ONE space; this is what then eats those untouched
|
|
49
|
-
// UTF-8 bytes) -> awk takes fields 1-8 (awk's default field-splitting ignores leading/
|
|
50
|
-
// trailing whitespace and splits on whitespace runs). By the time the tr step is done,
|
|
51
|
-
// the only characters left in the string are lowercase alphanumerics and single-space
|
|
52
|
-
// separators (with at most one leading and one trailing space) — so the awk step's only
|
|
53
|
-
// remaining job is to drop that leading/trailing space and truncate to 8 fields, which
|
|
54
|
-
// is exactly what trim + split + slice does below — PROVIDED the lowercasing step is also
|
|
55
|
-
// byte-wise ASCII-only. JS's `String.prototype.toLowerCase()` is Unicode-aware (e.g. U+0130
|
|
56
|
-
// İ -> "i" + combining dot above), which can *introduce* a fresh ASCII letter that bash's
|
|
57
|
-
// byte-wise `tr` would never produce (bash leaves İ's UTF-8 bytes alone; the following
|
|
58
|
-
// `tr -cs 'a-z0-9' ' '` step then discards all of them as non-alphanumeric). So the
|
|
59
|
-
// lowercasing below only maps `A`-`Z`, mirroring `tr '[:upper:]' '[:lower:]'` exactly.
|
|
60
|
-
// Verified against six normalize_title edge-case goldens (empty,
|
|
61
|
-
// single-word, >8-word, leading/trailing whitespace, multi-space, punctuation) plus
|
|
62
|
-
// adversarial Unicode probes (café, İstanbul).
|
|
63
|
-
export function normalizeTitle(title) {
|
|
64
|
-
const lowered = title.replace(/[A-Z]/g, (c) => c.toLowerCase());
|
|
65
|
-
const squeezed = lowered.replace(/[^a-z0-9]+/g, ' ').trim();
|
|
66
|
-
if (squeezed === '') return '';
|
|
67
|
-
return squeezed.split(/\s+/).slice(0, 8).join(' ');
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// The locus a finding is matched on. ASCII-only lowercase of the symbol, same reasoning as normalizeTitle: bash uses
|
|
71
|
-
// byte-wise `tr '[:upper:]' '[:lower:]'`.
|
|
72
|
-
export function locusKey(f) {
|
|
73
|
-
return `${rawStr(f.file)}|${rawStr(f.symbol).replace(/[A-Z]/g, (c) => c.toLowerCase())}|${normalizeTitle(rawStr(f.title))}`;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function ensureLedger(ledgerDir, ledgerPath) {
|
|
77
|
-
fs.mkdirSync(ledgerDir, { recursive: true });
|
|
78
|
-
if (!fs.existsSync(ledgerPath)) {
|
|
79
|
-
// Byte-for-byte the bash seed: `printf '{"next_id": 1, "findings": []}\n' > "$LEDGER"` —
|
|
80
|
-
// a literal, NOT jq output (note the space after each colon but no other jq-pretty
|
|
81
|
-
// formatting). Immediately superseded by the jq-pretty form on the first record/resolve/
|
|
82
|
-
// reopen that touches this ledger; only matters at rest if `open`/`get` is called first.
|
|
83
|
-
try { fs.writeFileSync(ledgerPath, '{"next_id": 1, "findings": []}\n', { flag: 'wx' }); } catch (e) { if (e.code !== 'EEXIST') throw e; } // exclusive: nothing is created through a link at the name; a first touch that lost a race is fine
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function loadLedger(ledgerPath) {
|
|
88
|
-
return JSON.parse(fs.readFileSync(ledgerPath, 'utf8'));
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// A killed write leaves its random temp file behind. Once a save has landed, a regular file of that shape untouched for an
|
|
92
|
-
// hour (no live writer holds one that long) is removed; a link, a younger file and any other name are left alone.
|
|
93
|
-
const STALE_TMP_MS = 60 * 60 * 1000;
|
|
94
|
-
function sweepTmp(dir) {
|
|
95
|
-
try {
|
|
96
|
-
for (const f of fs.readdirSync(dir)) {
|
|
97
|
-
const st = /^findings\.json\.[0-9a-f]{12}\.tmp$/.test(f) ? fs.lstatSync(path.join(dir, f)) : null;
|
|
98
|
-
if (st?.isFile() && Date.now() - st.mtimeMs > STALE_TMP_MS) fs.rmSync(path.join(dir, f), { force: true });
|
|
99
|
-
}
|
|
100
|
-
} catch { /* housekeeping only: the save has already landed */ }
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function saveLedger(ledgerPath, ledger) {
|
|
104
|
-
// Mirror bash's `tmp="$(mktemp)"; jq ... "$LEDGER" > "$tmp" && mv "$tmp" "$LEDGER"`:
|
|
105
|
-
// pretty 2-space + trailing newline (jq's default pretty-print, verified byte-identical
|
|
106
|
-
// against JSON.stringify(ledger, null, 2) + '\n'), written to a temp file in
|
|
107
|
-
// the SAME directory as the target and renamed into place so the write is atomic and the
|
|
108
|
-
// rename never crosses a filesystem boundary.
|
|
109
|
-
// The temp name is random and created exclusively ('wx'), so a link planted at a guessable name is never followed.
|
|
110
|
-
const tmpPath = `${ledgerPath}.${randomBytes(6).toString('hex')}.tmp`;
|
|
111
|
-
try {
|
|
112
|
-
fs.writeFileSync(tmpPath, JSON.stringify(ledger, null, 2) + '\n', { flag: 'wx' });
|
|
113
|
-
fs.renameSync(tmpPath, ledgerPath);
|
|
114
|
-
sweepTmp(path.dirname(ledgerPath));
|
|
115
|
-
} catch (e) {
|
|
116
|
-
fs.rmSync(tmpPath, { force: true });
|
|
117
|
-
throw e;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// A finding is recordable when it names a file and a title.
|
|
122
|
-
function firstUnrecordable(input) {
|
|
123
|
-
return input.findIndex((f) => !rawStr(f?.file) || !rawStr(f?.title));
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// Upserts each finding of `input` (an already-parsed array) into the ledger: a new locus becomes F-<n>, a known
|
|
127
|
-
// OPEN locus gets a sighting appended. `lines` is one JSON line per finding; `code` is 5 if ANY finding recurred
|
|
128
|
-
// in consecutive passes (judged after all are processed). Every element is validated before the ledger is
|
|
129
|
-
// touched: a malformed one returns 64 and writes nothing, not even the empty ledger. `dedupe` (a step that may be
|
|
130
|
-
// replayed) skips a sighting the same review, run and pass already holds on a known locus; so two findings of one
|
|
131
|
-
// locus in one batch leave a single sighting.
|
|
132
|
-
export function recordFindings({ root, slug, review, run, pass, input, now = nowDateUtc, dedupe = false }) {
|
|
133
|
-
const bad = firstUnrecordable(input);
|
|
134
|
-
if (bad !== -1) return { lines: [], code: 64, message: `${PROG}: finding ${bad} needs at least {file, title}` };
|
|
135
|
-
|
|
136
|
-
const { dir, file } = ledgerPaths(root, slug);
|
|
137
|
-
ensureLedger(dir, file);
|
|
138
|
-
const ledger = loadLedger(file);
|
|
139
|
-
const date = now();
|
|
140
|
-
const lines = [];
|
|
141
|
-
let breaker = false;
|
|
142
|
-
|
|
143
|
-
for (const f of input.map((x) => x ?? {})) {
|
|
144
|
-
const key = locusKey(f);
|
|
145
|
-
const sighting = { review, run, pass, date };
|
|
146
|
-
|
|
147
|
-
// Known open locus: recurrence is classified BEFORE the sighting is appended.
|
|
148
|
-
const existing = ledger.findings.find((x) => x.key === key && x.status === 'open');
|
|
149
|
-
if (existing) {
|
|
150
|
-
const recurringConsecutive = existing.seen.some((s) => s.run === run && s.pass === pass - 1);
|
|
151
|
-
const recurringCross = existing.seen.some((s) => s.run !== run);
|
|
152
|
-
const raised = canonSeverity(f.severity); // a re-sighting at a stronger severity raises it (and says so on the sighting), never lowers it
|
|
153
|
-
if (SEVERITIES.includes(raised) && SEVERITIES.indexOf(raised) < SEVERITIES.indexOf(existing.severity)) existing.severity = sighting.severity = raised;
|
|
154
|
-
if (!(dedupe && existing.seen.some((s) => s.review === review && s.run === run && s.pass === pass))) existing.seen.push(sighting); // dedupe: a replayed call adds no second sighting
|
|
155
|
-
if (recurringConsecutive) breaker = true;
|
|
156
|
-
lines.push(JSON.stringify({ id: existing.id, state: 'known', recurring_consecutive: recurringConsecutive, recurring_cross_run: recurringCross }));
|
|
157
|
-
} else {
|
|
158
|
-
const id = `F-${ledger.next_id}`;
|
|
159
|
-
ledger.next_id += 1;
|
|
160
|
-
ledger.findings.push({
|
|
161
|
-
id,
|
|
162
|
-
key,
|
|
163
|
-
locus: { file: f.file, symbol: orElse(f.symbol, '') },
|
|
164
|
-
title: f.title,
|
|
165
|
-
severity: canonSeverity(orElse(f.severity, 'Minor')),
|
|
166
|
-
confidence: orElse(f.confidence, 'Medium'),
|
|
167
|
-
status: 'open',
|
|
168
|
-
introduced_by: review,
|
|
169
|
-
resolved_by: null,
|
|
170
|
-
seen: [sighting],
|
|
171
|
-
});
|
|
172
|
-
lines.push(JSON.stringify({ id, state: 'new', recurring_consecutive: false, recurring_cross_run: false }));
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// An empty batch changes nothing: leave the file as it is, seed literal included.
|
|
177
|
-
if (input.length > 0) saveLedger(file, ledger);
|
|
178
|
-
return { lines, code: breaker ? EXIT_CIRCUIT_BREAKER : 0, message: '' };
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
export const SEVERITIES = ['Blocker', 'Major', 'Minor', 'Nit']; // strongest first
|
|
182
|
-
// A stored severity is read as one of the four names, else Unrated; an Unrated one counts as at the floor (it fails closed).
|
|
183
|
-
export const readSeverity = (s) => (SEVERITIES.includes(s) ? s : 'Unrated');
|
|
184
|
-
export const atOrAbove = (severity, floor) => !SEVERITIES.includes(severity) || SEVERITIES.indexOf(severity) <= SEVERITIES.indexOf(floor);
|
|
185
|
-
export const CONFIDENCES = ['High', 'Medium', 'Low'];
|
|
186
|
-
export const canonName = (names, v) => names.find((n) => typeof v === 'string' && n.toLowerCase() === v.toLowerCase()) ?? v; // blocker -> Blocker
|
|
187
|
-
const canonSeverity = (v) => canonName(SEVERITIES, v);
|
|
188
|
-
const STATUSES = ['fixed', 'accepted', 'wontfix'];
|
|
189
|
-
const refuse = (msg) => ({ lines: [], code: 64, message: `${PROG}: ${msg}` });
|
|
190
|
-
const ok = (lines = []) => ({ lines, code: 0, message: '' });
|
|
191
|
-
|
|
192
|
-
// Seeds the ledger on first touch and returns its path. Every lifecycle handler does this before it validates its
|
|
193
|
-
// arguments, so a refused call still leaves the seed behind, as the bash original did.
|
|
194
|
-
function touchLedger(root, slug) {
|
|
195
|
-
const { dir, file } = ledgerPaths(root, slug);
|
|
196
|
-
ensureLedger(dir, file);
|
|
197
|
-
return file;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// An unknown id is not an error: nothing is changed and nothing is printed.
|
|
201
|
-
export function resolveFinding({ root, slug, id, status, by }) {
|
|
202
|
-
const file = touchLedger(root, slug);
|
|
203
|
-
if (!id || !status) return refuse('resolve requires --id and --status');
|
|
204
|
-
if (!STATUSES.includes(status)) return refuse('--status must be fixed|accepted|wontfix');
|
|
205
|
-
const ledger = loadLedger(file);
|
|
206
|
-
const found = ledger.findings.find((x) => x.id === id);
|
|
207
|
-
if (!found) return ok();
|
|
208
|
-
found.status = status;
|
|
209
|
-
found.resolved_by = by;
|
|
210
|
-
saveLedger(file, ledger);
|
|
211
|
-
return ok([JSON.stringify({ id: found.id, status: found.status, resolved_by: found.resolved_by })]);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
export function reopenFinding({ root, slug, id, by }) {
|
|
215
|
-
const file = touchLedger(root, slug);
|
|
216
|
-
if (!id) return refuse('reopen requires --id');
|
|
217
|
-
const ledger = loadLedger(file);
|
|
218
|
-
const found = ledger.findings.find((x) => x.id === id);
|
|
219
|
-
if (!found) return ok();
|
|
220
|
-
found.status = 'open';
|
|
221
|
-
found.resolved_by = null;
|
|
222
|
-
found.reopened_by = by;
|
|
223
|
-
saveLedger(file, ledger);
|
|
224
|
-
return ok([JSON.stringify({ id: found.id, status: found.status })]);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// The open findings only, trimmed to the fields a reader needs, as one pretty-printed JSON array.
|
|
228
|
-
export function openFindings({ root, slug }) {
|
|
229
|
-
const ledger = loadLedger(touchLedger(root, slug));
|
|
230
|
-
const open = ledger.findings
|
|
231
|
-
.filter((x) => x.status === 'open')
|
|
232
|
-
.map((x) => ({ id: x.id, locus: x.locus, title: x.title, severity: x.severity, confidence: x.confidence, introduced_by: x.introduced_by }));
|
|
233
|
-
return ok([JSON.stringify(open, null, 2)]);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
export function getFinding({ root, slug, id }) {
|
|
237
|
-
const file = touchLedger(root, slug);
|
|
238
|
-
if (!id) return refuse('get requires --id');
|
|
239
|
-
const found = loadLedger(file).findings.find((x) => x.id === id);
|
|
240
|
-
return ok(found ? [JSON.stringify(found, null, 2)] : []);
|
|
241
|
-
}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
// install-text.mjs — the install-root text tools: somi_command, somi_skill and somi_agent, each
|
|
2
|
-
// serving one file that ships in SoMi's own install directory (commands/<name>.md,
|
|
3
|
-
// skills/<name>/SKILL.md, agents/<name>.md). A consuming project can't follow a relative link into
|
|
4
|
-
// that directory, so the text is served over the MCP channel instead.
|
|
5
|
-
//
|
|
6
|
-
// Pure apart from the one file read: the caller supplies the install root and turns {ok, ...} into
|
|
7
|
-
// its own surface (the MCP server's textResult and the `<prog>: <message> (exit N)` failure line).
|
|
8
|
-
|
|
9
|
-
import fs from 'node:fs';
|
|
10
|
-
import path from 'node:path';
|
|
11
|
-
import { AGENT_NAME_RE, EXIT_USAGE, EXIT_UNKNOWN_AGENT } from './dispatch-resolver.mjs';
|
|
12
|
-
|
|
13
|
-
export const INSTALL_TEXT_TOOLS = [
|
|
14
|
-
{
|
|
15
|
-
name: 'somi_command',
|
|
16
|
-
description:
|
|
17
|
-
"Read a SoMi command's own procedure text (commands/<name>.md) from the install root, so " +
|
|
18
|
-
'a front door running in a consuming project can follow it live without knowing where SoMi ' +
|
|
19
|
-
'is installed.',
|
|
20
|
-
inputSchema: {
|
|
21
|
-
type: 'object',
|
|
22
|
-
properties: {
|
|
23
|
-
name: { type: 'string', description: 'command name, e.g. "plan" (matches ^[a-z][a-z0-9-]*$)' },
|
|
24
|
-
},
|
|
25
|
-
required: ['name'],
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
name: 'somi_skill',
|
|
30
|
-
description:
|
|
31
|
-
"Read a SoMi skill's own text (skills/<name>/SKILL.md) from the install root — the same " +
|
|
32
|
-
'problem `somi_command` solves for commands/, applied to skills/: a reference to a skill from ' +
|
|
33
|
-
"a consuming project can't rely on a relative link into SoMi's own install directory, since " +
|
|
34
|
-
"that directory generally isn't the consuming project's own tree. Read the dispatch " +
|
|
35
|
-
'procedure this way (`somi_skill({name: "somi-dispatch"})`) whenever the skill can\'t be ' +
|
|
36
|
-
'loaded by name on the current host (e.g. no Skill tool, or a non-Claude-Code host).',
|
|
37
|
-
inputSchema: {
|
|
38
|
-
type: 'object',
|
|
39
|
-
properties: {
|
|
40
|
-
name: { type: 'string', description: 'skill name, e.g. "somi-dispatch" (matches ^[a-z][a-z0-9-]*$)' },
|
|
41
|
-
},
|
|
42
|
-
required: ['name'],
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
name: 'somi_agent',
|
|
47
|
-
description:
|
|
48
|
-
"Read a SoMi agent's instructions (agents/<name>.md, frontmatter removed) from the install " +
|
|
49
|
-
'root, to inspect or quote them. Not a way to run the agent: start it as the agent_type ' +
|
|
50
|
-
'somi_resolve returns, never as another agent given this text.',
|
|
51
|
-
inputSchema: {
|
|
52
|
-
type: 'object',
|
|
53
|
-
properties: {
|
|
54
|
-
name: { type: 'string', description: 'agent name, e.g. "somi-reviewer" (matches ^[a-z][a-z0-9-]*$)' },
|
|
55
|
-
},
|
|
56
|
-
required: ['name'],
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
];
|
|
60
|
-
|
|
61
|
-
const NAME_MAX = 64; // the slug bound; the echo of a refused name is cut as well
|
|
62
|
-
const fail = (code, message) => ({ ok: false, code, message });
|
|
63
|
-
|
|
64
|
-
// The agent's instructions without its frontmatter, for reading. Dispatch never uses this: an agent
|
|
65
|
-
// starts as its registered agent_type (see skills/somi-dispatch §5), so the text is never a payload.
|
|
66
|
-
const stripFrontmatter = (text) => text.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n/, '').trimStart();
|
|
67
|
-
|
|
68
|
-
const SOURCES = {
|
|
69
|
-
command: { relPath: (n) => ['commands', `${n}.md`], shape: (t) => t },
|
|
70
|
-
skill: { relPath: (n) => ['skills', n, 'SKILL.md'], shape: (t) => t },
|
|
71
|
-
agent: { relPath: (n) => ['agents', `${n}.md`], shape: stripFrontmatter },
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
// One reader for every install-root text tool. The name is checked against AGENT_NAME_RE BEFORE
|
|
75
|
-
// any path is built, so a traversal payload (`../x`, `a/b`) is a 64 and never reaches path.join.
|
|
76
|
-
// JSON.stringify, not a template interpolation, for the invalid name: an object-shaped `name`
|
|
77
|
-
// (e.g. `{toString: null}`) throws inside `${name}` and would surface as an unrelated -32603.
|
|
78
|
-
/**
|
|
79
|
-
* @param {'command' | 'skill' | 'agent'} kind
|
|
80
|
-
* @param {{name?: unknown}} args
|
|
81
|
-
* @param {{installRoot: string}} env
|
|
82
|
-
* @returns {{ok: true, text: string} | {ok: false, code: number, message: string}}
|
|
83
|
-
*/
|
|
84
|
-
export function installText(kind, args, { installRoot }) {
|
|
85
|
-
const name = args?.name;
|
|
86
|
-
if (typeof name !== 'string' || name.length > NAME_MAX || !AGENT_NAME_RE.test(name)) {
|
|
87
|
-
return fail(EXIT_USAGE, `invalid name ${JSON.stringify(name)?.slice(0, 60)} (expected ${AGENT_NAME_RE}, at most ${NAME_MAX} characters)`);
|
|
88
|
-
}
|
|
89
|
-
const { relPath, shape } = SOURCES[kind];
|
|
90
|
-
const filePath = path.join(installRoot, ...relPath(name));
|
|
91
|
-
try {
|
|
92
|
-
return { ok: true, text: shape(fs.readFileSync(filePath, 'utf8')) };
|
|
93
|
-
} catch (e) {
|
|
94
|
-
if (e.code === 'ENOENT') return fail(EXIT_UNKNOWN_AGENT, `unknown ${kind} "${name}" (no ${filePath})`);
|
|
95
|
-
throw e;
|
|
96
|
-
}
|
|
97
|
-
}
|