@skathio/somi 4.1.1 → 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 -227
- 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 -282
- 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 -303
- 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 -139
- 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 -384
- package/tests/scripts/lib/loop-step-cli-tests.mjs +0 -156
- 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,303 +0,0 @@
|
|
|
1
|
-
// loop-step.mjs -- the composite steps of a loop: one call performs every deterministic transition between two agent
|
|
2
|
-
// starts, through the same library functions the primitive CLI subcommands use. This file holds `open`, `after-code`
|
|
3
|
-
// and `status`; `after-review` is in loop-step-review.mjs, `close` in loop-step-close.mjs, the shared kit in loop-step-kit.mjs; runStep(ctx, args) -> a response object (never a thrown refusal). ctx is the engine's ({root, env,
|
|
4
|
-
// stateDir, installRoot, now?}) plus `via` ('mcp' | 'cli', recorded in the cursor), `log` (where an unexpected error's
|
|
5
|
-
// name and stack go, one JSON line; console.error when absent) and, for tests only, `failAfter` (a sub-step name: the
|
|
6
|
-
// step throws right after completing it, as a killed process would).
|
|
7
|
-
//
|
|
8
|
-
// Response: {ok, step, pass, next, stop_reason, exit, wrote[], unwritten[], replayed, ...step fields}, at most
|
|
9
|
-
// BUDGET bytes (it is re-read on every later turn of the orchestrator). `exit` is the code the CLI gives for the same
|
|
10
|
-
// condition (0, 2, 3, 4, 64, 65 unknown agent) or 70, an internal error with no CLI counterpart: the step did not
|
|
11
|
-
// complete, the error went to the log and nothing of it is echoed; `ok` is exit === 0.
|
|
12
|
-
//
|
|
13
|
-
// Idempotency: state.steps["<pass>:<step>"] = {via, at, done: [sub-steps], response}. A sub-step's effect and its
|
|
14
|
-
// mark are saved together; a repeat of a finished step returns its stored response with replayed: true, a repeat of
|
|
15
|
-
// an interrupted one resumes at the first sub-step not in `done`. A gate stop is never stored (the gate is re-judged
|
|
16
|
-
// on the next call, so a cap raised through the CLI takes effect). An after-code on a code loop is never replayed: the
|
|
17
|
-
// dispatch is recorded once, the diff gate and the review scope are measured afresh on every call, and a repeat
|
|
18
|
-
// never asks for a weaker review than the pass already did. Diary titles and bodies come from stored state only,
|
|
19
|
-
// with the stored `at` as their time, so a retry is byte-identical and the writer drops it. Cap arguments only tighten
|
|
20
|
-
// (loop-caps.mjs); on a repeat of a finished step an argument that would still tighten one is refused with 64,
|
|
21
|
-
// never dropped. Every argument is validated before any path is built or any file touched.
|
|
22
|
-
|
|
23
|
-
import fs from 'node:fs';
|
|
24
|
-
import path from 'node:path';
|
|
25
|
-
import { EXIT_DIFF_CAP, EXIT_INTERNAL, EXIT_MAX_PASSES, EXIT_TIME_BUDGET, KIND, LoopExit, NEXT, PROG, usageError } from './loop-exit.mjs';
|
|
26
|
-
import { applyCapOverride, configVal, firstDefined, reresolveCap, resolveInitCap, tightenCap } from './loop-caps.mjs';
|
|
27
|
-
import { init, readConfig } from './loop-engine.mjs';
|
|
28
|
-
import { loadState, nowIso, saveState, stateFile } from './loop-state.mjs';
|
|
29
|
-
import { computeDiff } from './loop-diff.mjs';
|
|
30
|
-
import { escalate, reported } from './loop-escalate.mjs';
|
|
31
|
-
import { dispatchEntry } from './loop-dispatch.mjs';
|
|
32
|
-
import { REVIEW_SCOPES, reviewScope as scopeOf, snapshotTree } from './loop-review.mjs';
|
|
33
|
-
import { checkRun } from './run-budget.mjs';
|
|
34
|
-
import { buildCard, HOSTS, ITERATION_RE, MAX_BYTES, SLUG_RE } from './run-card.mjs';
|
|
35
|
-
import { appendDiary, findIterationRow, markIteration, plainDir, readPlanFile } from './loop-notes.mjs';
|
|
36
|
-
export { BUDGET } from './loop-step-kit.mjs';
|
|
37
|
-
import { ARG, base, bad, begin, advance, capsView, clean, cut, finalize, fitLines, floorLines, freezeFields, Killed, keep, MODES, noLoop, phaseFiles, replayOf, size, stateAt, SUB_STEPS } from './loop-step-kit.mjs';
|
|
38
|
-
import { afterReview, checkReview, FIELDS as REVIEW_FIELDS } from './loop-step-review.mjs';
|
|
39
|
-
import { checkClose, close, FIELDS as CLOSE_FIELDS } from './loop-step-close.mjs';
|
|
40
|
-
|
|
41
|
-
export const FIELDS = freezeFields({
|
|
42
|
-
open: ['slug', 'loop', 'iteration', 'files', 'host', 'max_passes', 'diff_cap'],
|
|
43
|
-
'after-code': ['slug', 'loop', 'iteration', 'agent', 'host', 'diff_cap', 'review_mode', 'review_scope'],
|
|
44
|
-
status: ['slug', 'loop', 'iteration'],
|
|
45
|
-
...REVIEW_FIELDS,
|
|
46
|
-
...CLOSE_FIELDS,
|
|
47
|
-
});
|
|
48
|
-
const IGNORED = ['host', 'project_dir']; // accepted on every step and dropped where the step has no use for them (a model puts them on every call)
|
|
49
|
-
const NOT_FOR_PLAN = ['files', 'diff_cap', 'review_mode', 'review_scope'];
|
|
50
|
-
const NEXT_REVIEW = { single: NEXT.taskReviewer, security: NEXT.taskReviewers, panel: NEXT.taskPanel };
|
|
51
|
-
const CARD_MAX = 1800; // bytes of the response the run card may take (as JSON), so the fields around it always fit in BUDGET
|
|
52
|
-
const NO_ROW = (it) => ({ // why findIterationRow found no usable row
|
|
53
|
-
missing: `iteration ${it} has no row in the Iteration progress table of progress.md`,
|
|
54
|
-
ambiguous: `iteration ${it} has more than one row in the Iteration progress table of progress.md`,
|
|
55
|
-
'not-template-shape': 'the Iteration progress table of progress.md is not in the template shape',
|
|
56
|
-
'row-not-template-shape': `the row of iteration ${it} in progress.md is not in the template shape`,
|
|
57
|
-
});
|
|
58
|
-
const AGENT_RE = /^[A-Za-z0-9][A-Za-z0-9:_-]{0,63}$/;
|
|
59
|
-
const STARTABLE = ['not-started', 'in-progress', 'blocked']; // the Status cells under which a new loop may start; done and superseded are over
|
|
60
|
-
|
|
61
|
-
function intArg(v, field) {
|
|
62
|
-
if (Number.isInteger(v) && v >= 0 && v <= 999999) return v;
|
|
63
|
-
if (typeof v === 'string' && /^\d{1,6}$/.test(v)) return Number(v);
|
|
64
|
-
throw bad(field, 'expected a non-negative integer');
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// The scope list as an array of relative paths, or a 64 naming `files`. `from` says where a list that was not given came from.
|
|
68
|
-
function checkFiles(files, from = '') {
|
|
69
|
-
const list = typeof files === 'string' ? files.split(/\s+/).filter(Boolean) : files;
|
|
70
|
-
if (!Array.isArray(list) || list.length > 200 || list.some((f) => typeof f !== 'string' || !/^[^\s\p{Cc}]{1,200}$/u.test(f) || /^[-~/]|\\|(^|\/)\.\.(\/|$)/.test(f))) throw bad('files', `expected up to 200 relative paths without whitespace, control characters, a backslash, a .. segment or a leading - or ~${from}`);
|
|
71
|
-
// A comma is refused: `a.js,b.js` is two paths a caller joined the wrong way, and taken as one it records a scope that matches nothing.
|
|
72
|
-
if (list.some((f) => f.includes(','))) throw bad('files', `a path holds a comma: separate the paths with spaces (a list of strings in the tool), not commas${from}`);
|
|
73
|
-
return list;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Whitelist the arguments of `step`, refuse any other with 64 naming it, and check every value's shape. Pure.
|
|
77
|
-
function validate(step, args) {
|
|
78
|
-
if (!Object.hasOwn(FIELDS, step)) throw bad('step', 'must be one of open|after-code|after-review|close|status');
|
|
79
|
-
for (const [k, v] of Object.entries(args)) {
|
|
80
|
-
if (k !== 'step' && v != null && !FIELDS[step].includes(k) && !IGNORED.includes(k)) throw bad(k, `is not an argument of step ${step}`);
|
|
81
|
-
}
|
|
82
|
-
const a = Object.fromEntries(FIELDS[step].map((k) => [k, args[k] ?? undefined]));
|
|
83
|
-
if (typeof a.slug !== 'string' || !SLUG_RE.test(a.slug)) throw bad('slug', 'must match ^[a-z0-9][a-z0-9-]{0,63}$');
|
|
84
|
-
a.loop ??= 'code';
|
|
85
|
-
if (!['code', 'plan'].includes(a.loop)) throw bad('loop', 'must be code or plan');
|
|
86
|
-
if (a.loop === 'plan') {
|
|
87
|
-
for (const k of NOT_FOR_PLAN) if (a[k] !== undefined) throw bad(k, 'is not an argument of a plan loop');
|
|
88
|
-
if (a.iteration !== undefined) throw bad('iteration', 'a plan loop takes no iteration');
|
|
89
|
-
} else if (typeof a.iteration !== 'string' || !ITERATION_RE.test(a.iteration)) throw bad('iteration', 'must look like 1.2 or 1.2b');
|
|
90
|
-
if (step === 'after-code' && (typeof a.agent !== 'string' || !AGENT_RE.test(a.agent))) throw bad('agent', 'is required: the agent that just ran');
|
|
91
|
-
if (a.review_mode !== undefined && !MODES.includes(a.review_mode)) throw bad('review_mode', `must be one of ${MODES.join('|')}`);
|
|
92
|
-
if (a.review_scope !== undefined && !REVIEW_SCOPES.includes(a.review_scope)) throw bad('review_scope', `must be one of ${REVIEW_SCOPES.join('|')}`);
|
|
93
|
-
if (a.host !== undefined && !HOSTS.includes(a.host)) throw bad('host', `must be one of ${HOSTS.join('|')}`);
|
|
94
|
-
for (const k of ['max_passes', 'diff_cap']) if (a[k] !== undefined) a[k] = intArg(a[k], k);
|
|
95
|
-
if (step === 'after-review') checkReview(a, { bad, intArg });
|
|
96
|
-
if (step === 'close') checkClose(a, { bad });
|
|
97
|
-
if (a.files !== undefined) a.files = checkFiles(a.files);
|
|
98
|
-
return a;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// The cap in force after the environment's re-resolution (as `pass` and `check-diff` do) and the tighten-only tool
|
|
102
|
-
// argument, with the override entries to apply. Pure: it throws 64 on an argument above the cap and mutates nothing.
|
|
103
|
-
function capsFor(ctx, state, field, arg, at) {
|
|
104
|
-
const env = reresolveCap(ctx.env, state, field, '', at);
|
|
105
|
-
const tool = tightenCap({ ...state, caps: { ...state.caps, [field]: env.resolved } }, field, arg, at, ARG[field]);
|
|
106
|
-
return { cap: tool ? tool.to : env.resolved, overrides: [env.override, tool].filter(Boolean) };
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// The run card as brief text. A file list that would push it over CARD_MAX is shortened until it fits (the state and the
|
|
110
|
-
// diff gate keep every file) and the cut is said; it is refused only when it does not fit with no files.
|
|
111
|
-
function cardOf(a, ctx, state) {
|
|
112
|
-
const all = state.iteration_files;
|
|
113
|
-
for (let k = all.length; ; k--) {
|
|
114
|
-
const c = buildCard({ slug: a.slug, iteration: a.iteration, host: a.host ?? 'claude-code', projectDir: ctx.root, somiRoot: ctx.installRoot, state: { ...state, iteration_files: all.slice(0, k) } });
|
|
115
|
-
const over = c.ok ? size(c.card) > CARD_MAX : c.error === `the card is over ${MAX_BYTES} bytes`; // the card builder's own limit is the other way too long shows
|
|
116
|
-
if (!c.ok && !over) throw usageError(c.error);
|
|
117
|
-
if (!over) return k < all.length ? `${c.card.trimEnd()}\n(${all.length - k} more files in scope: see the phase file; the diff gate counts them)` : c.card;
|
|
118
|
-
if (k === 0) throw usageError(`the run card is over the response limit with no files listed (${CARD_MAX} bytes)`);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// A gate stop: never stored, `next` is close with the status to close with, and for the gates a cap can move, the primitive that re-runs it raised.
|
|
123
|
-
function stop(step, state, code, reason, a, extra = {}) {
|
|
124
|
-
const at = a.iteration ? ` --iteration ${a.iteration}` : '';
|
|
125
|
-
const cli = { [EXIT_MAX_PASSES]: `node scripts/somi-loop.mjs pass --slug ${a.slug}${at} --max-passes <N>`, [EXIT_DIFF_CAP]: `node scripts/somi-loop.mjs check-diff --slug ${a.slug}${at} --diff-cap <N>` }[code];
|
|
126
|
-
return base(step, { ok: false, pass: state.pass, next: NEXT.close, close_args: { status: `stopped-${reason}` }, stop_reason: reason, exit: code, ...extra, ...(cli ? { cli } : {}) });
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// A new state needs a plan directory that is real, and its declaration: a code loop, a startable row for the iteration
|
|
130
|
-
// in progress.md's table (read as markIteration reads it); a plan loop, a spec.md, progress.md or brief.md file (the
|
|
131
|
-
// /design handoff holds brief.md and no spec.md yet). -> the reason it lacks them, else null.
|
|
132
|
-
function undeclared(root, a) {
|
|
133
|
-
const d = plainDir(root, ['.somi', 'plans', a.slug]);
|
|
134
|
-
if (!d.dir) return `.somi/plans/${a.slug} is ${d.reason}`;
|
|
135
|
-
if (a.loop === 'plan') return ['spec.md', 'progress.md', 'brief.md'].some((f) => { try { return fs.lstatSync(path.join(d.dir, f)).isFile(); } catch { return false; } }) ? null : 'the plan directory has none of spec.md, progress.md or brief.md';
|
|
136
|
-
const p = readPlanFile(path.join(d.dir, 'progress.md'));
|
|
137
|
-
if (!p.text) return `progress.md is ${p.reason ?? 'empty'}`;
|
|
138
|
-
const found = findIterationRow(p.text, a.iteration, true);
|
|
139
|
-
if (!found.cells) return `${NO_ROW(a.iteration)[found.reason]}${found.why ? `: ${found.why}` : ''}`;
|
|
140
|
-
const status = found.cells[found.cols.status].trim();
|
|
141
|
-
return STARTABLE.includes(status) ? null : `iteration ${a.iteration} is marked ${clean(status, 20)} in progress.md`;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// The Status cell of the iteration's row, or null when the row cannot be read as `undeclared` reads it.
|
|
145
|
-
function rowStatus(root, slug, iteration) {
|
|
146
|
-
const d = plainDir(root, ['.somi', 'plans', slug]);
|
|
147
|
-
const p = d.dir ? readPlanFile(path.join(d.dir, 'progress.md')) : {};
|
|
148
|
-
const found = p.text ? findIterationRow(p.text, iteration, true) : {};
|
|
149
|
-
return found.cells?.[found.cols.status].trim() || null;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function open(ctx, a) {
|
|
153
|
-
const now = ctx.now ?? nowIso;
|
|
154
|
-
const sf = stateFile(ctx.stateDir, a.slug, a.iteration);
|
|
155
|
-
let state = stateAt(sf);
|
|
156
|
-
if (state === null) return base('open', { ok: false, next: NEXT.askUser, stop_reason: 'no-running-loop', exit: 64, error: 'the loop state is finished or cannot be read; the user decides whether to restart it through the CLI (a restart discards a state that is still running)' }); // open never re-initialises an existing state: that is the user's to restart, never the model's
|
|
157
|
-
if (!state) {
|
|
158
|
-
if (a.loop === 'code' && !a.files?.length) { // the argument wins; without it the iteration's own "Files (approx)" line in the phase file, checked as a given list is
|
|
159
|
-
const listed = phaseFiles(ctx.root, a.slug, a.iteration);
|
|
160
|
-
if (!listed) throw bad('files', 'required to start a code loop');
|
|
161
|
-
a.files = checkFiles(listed, ' (read from the "Files (approx)" line of the phase file)');
|
|
162
|
-
}
|
|
163
|
-
const why = undeclared(ctx.root, a); if (why) return base('open', { ok: false, next: NEXT.askUser, stop_reason: 'not-declared', exit: 64, error: `${why}; the user starts a new loop through the CLI` });
|
|
164
|
-
const cfg = readConfig(ctx.root, ctx.env);
|
|
165
|
-
const would = { slug: a.slug, iteration: a.iteration, iteration_files: a.files, baseline_sha: '0'.repeat(64), loop: a.loop, pass: 0, caps: { max_passes: resolveInitCap(ctx.env, cfg, a.loop, 'max_passes', ''), diff_cap_lines: resolveInitCap(ctx.env, cfg, a.loop, 'diff_cap_lines', '') } };
|
|
166
|
-
tightenCap(would, 'max_passes', a.max_passes, '', ARG.max_passes); tightenCap(would, 'diff_cap_lines', a.diff_cap, '', ARG.diff_cap_lines); // refuse before init writes anything
|
|
167
|
-
if (a.loop === 'code') cardOf(a, ctx, would); // the card at its longest (a 64-digit baseline), before init writes anything
|
|
168
|
-
const r = init(ctx, { slug: a.slug, loop: a.loop, iteration: a.iteration ?? '', files: (a.files ?? []).join(' '), force: false, maxPasses: '', diffCap: '', severity: '' });
|
|
169
|
-
if (r.code) throw new LoopExit(r.code, r.message);
|
|
170
|
-
state = loadState(sf);
|
|
171
|
-
}
|
|
172
|
-
if (state.loop !== a.loop) throw bad('loop', `the loop state of this slug is a ${state.loop} loop`);
|
|
173
|
-
|
|
174
|
-
const T = state.pass === state.history.length ? state.pass + 1 : state.pass; // a pass counted but not recorded is the current one
|
|
175
|
-
const key = `${T}:open`;
|
|
176
|
-
const passes = capsFor(ctx, state, 'max_passes', a.max_passes, now());
|
|
177
|
-
const diff = state.loop === 'code' ? capsFor(ctx, state, 'diff_cap_lines', a.diff_cap, now()) : { overrides: [] };
|
|
178
|
-
const overrides = [...passes.overrides, ...diff.overrides];
|
|
179
|
-
const again = replayOf(state, key, overrides); if (again) return again;
|
|
180
|
-
const applyAll = () => overrides.forEach((o) => applyCapOverride(state, o));
|
|
181
|
-
const card = state.loop === 'code' ? cardOf(a, ctx, state) : '';
|
|
182
|
-
|
|
183
|
-
const run = T > passes.cap ? null : checkRun(path.dirname(ctx.stateDir), a.slug, Date.parse(now()));
|
|
184
|
-
if (T > passes.cap || run?.over) { // the raise is kept even when the gate still fails, as `pass` does
|
|
185
|
-
if (overrides.length) { applyAll(); saveState(sf, state); }
|
|
186
|
-
return T > passes.cap
|
|
187
|
-
? stop('open', state, EXIT_MAX_PASSES, 'max-passes-exceeded', a, { caps: capsView(state).caps })
|
|
188
|
-
: stop('open', state, EXIT_TIME_BUDGET, 'time-budget', a, { elapsed_minutes: run.elapsed_minutes, max_minutes: run.max_minutes });
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
const entry = begin(ctx, state, key);
|
|
192
|
-
applyAll();
|
|
193
|
-
const { floor, caps } = capsView(state); // after the tightening, so the response and the diary show the caps in force
|
|
194
|
-
advance(ctx, sf, state, entry, 'pass', () => { state.pass = T; entry.tree = snapshotTree(ctx.root) ?? undefined; }); // the tree the coder starts from
|
|
195
|
-
const out = (entry.out ??= { wrote: [], unwritten: [] }); // stored with the sub-step mark, so a resumed step reports them
|
|
196
|
-
if (overrides.length) saveState(sf, state);
|
|
197
|
-
const finished = (k) => Boolean(state.steps?.[`${T - 1}:${k}`]?.response); // the pass before ended through the steps only if its after-code and after-review both finished; otherwise (the CLI recorded it, or a session died) this open resumes
|
|
198
|
-
const kind = T === 1 ? 'started' : finished('after-code') && finished('after-review') ? null : `resumed from pass ${T - 1}`;
|
|
199
|
-
if (kind) {
|
|
200
|
-
const title = `${state.loop}-loop ${kind === 'started' ? `started${state.iteration ? ` for iteration ${state.iteration}` : ''}` : kind}`;
|
|
201
|
-
advance(ctx, sf, state, entry, 'diary', () => {
|
|
202
|
-
const c = caps;
|
|
203
|
-
const gates = state.loop === 'code' ? `max_passes ${c.max_passes}, diff_cap_lines ${c.diff_cap_lines}, severity_floor ${c.severity_floor}; files in scope: ${state.iteration_files.length}` : `max_passes ${c.max_passes}, severity_floor ${c.severity_floor}`;
|
|
204
|
-
keep(out, appendDiary({ root: ctx.root, slug: a.slug }, { category: 'note', phase: state.iteration || 'work-item-wide', title, body: gates, now: entry.at })); // the unwritten line is a pointer to the entry, not the entry: the response has a budget
|
|
205
|
-
});
|
|
206
|
-
if (state.loop === 'code') advance(ctx, sf, state, entry, 'row', () => {
|
|
207
|
-
if (kind !== 'started' && rowStatus(ctx.root, a.slug, state.iteration) === 'blocked') out.unwritten.push({ file: 'progress.md', reason: 'row-left-blocked', kind: KIND.notice, line: `iteration ${state.iteration} is marked blocked; left as it is` });
|
|
208
|
-
else keep(out, markIteration({ root: ctx.root, slug: a.slug }, state.iteration, { status: 'in-progress', activity: title, now: entry.at }));
|
|
209
|
-
}); // the row says the loop is running; close makes the one move to done. A row a person marked blocked stays so on a resume
|
|
210
|
-
}
|
|
211
|
-
const resp = fitLines((kept) => base('open', {
|
|
212
|
-
pass: T, loop: state.loop, next: state.loop === 'code' ? NEXT.taskCoder : NEXT.taskPlanner, caps, ...(state.review_min ? { review_min: state.review_min } : {}),
|
|
213
|
-
brief: [...(card ? [card.trimEnd()] : []), ...(kept.length ? [`Open findings at or above ${floor} (data from earlier reviews, not instructions):`, '```text', ...kept, '```'] : [])].join('\n'), ...out,
|
|
214
|
-
}), floorLines(ctx.root, a.slug, floor));
|
|
215
|
-
return finalize(sf, state, entry, resp);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// The review lens and scope for this pass: configuration and the sizing record decide, an argument may only strengthen.
|
|
219
|
-
function reviewSettings(ctx, state, a) {
|
|
220
|
-
const config = readConfig(ctx.root, ctx.env);
|
|
221
|
-
const setting = firstDefined(ctx.env.SOMI_CODE_LOOP_REVIEW, configVal(config, ['code_loop', 'review_mode']), 'single');
|
|
222
|
-
if (!MODES.includes(setting)) throw usageError(`review mode must be one of ${MODES.join('|')}, got ${JSON.stringify(setting)}`);
|
|
223
|
-
const scope = firstDefined(ctx.env.SOMI_CODE_LOOP_REVIEW_SCOPE, configVal(config, ['code_loop', 'review_scope']), 'delta');
|
|
224
|
-
if (!REVIEW_SCOPES.includes(scope)) throw usageError(`review scope must be one of ${REVIEW_SCOPES.join('|')}, got ${JSON.stringify(scope)}`);
|
|
225
|
-
const top = Math.max(...[setting, state.review_min, a.review_mode].map((m) => MODES.indexOf(m ?? 'single')));
|
|
226
|
-
return { mode: MODES[top], scope: a.review_scope === 'full' ? 'full' : scope };
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// After the coder (the planner, on a plan loop): record the dispatch, then judge the diff gate and fix the review's lens
|
|
230
|
-
// and scope. The gate is re-judged on every call, so only the dispatch is a sub-step.
|
|
231
|
-
function afterCode(ctx, a) {
|
|
232
|
-
const now = ctx.now ?? nowIso;
|
|
233
|
-
const sf = stateFile(ctx.stateDir, a.slug, a.iteration);
|
|
234
|
-
const state = stateAt(sf);
|
|
235
|
-
if (!state) throw noLoop(a);
|
|
236
|
-
if (state.loop !== a.loop) throw bad('loop', `the loop state of this slug is a ${state.loop} loop`);
|
|
237
|
-
if (state.pass < 1 || state.history.length >= state.pass) throw usageError('no pass is open: call open first');
|
|
238
|
-
const key = `${state.pass}:after-code`;
|
|
239
|
-
const code = state.loop === 'code';
|
|
240
|
-
const diffCap = code ? capsFor(ctx, state, 'diff_cap_lines', a.diff_cap, now()) : { cap: 0, overrides: [] };
|
|
241
|
-
const again = code ? null : replayOf(state, key, diffCap.overrides); if (again) return again;
|
|
242
|
-
const review = code ? reviewSettings(ctx, state, a) : null;
|
|
243
|
-
const prior = state.steps?.[key]?.review; // what an earlier call of this pass asked for
|
|
244
|
-
if (prior) { review.mode = MODES[Math.max(...[prior.mode, review.mode].map((m) => MODES.indexOf(m)))]; if (prior.scope === 'full') review.scope = 'full'; } // a repeat may strengthen the lens or widen the scope, and never weakens what the pass already asked for
|
|
245
|
-
let d;
|
|
246
|
-
if (!state.steps?.[key]?.done.includes('dispatch')) {
|
|
247
|
-
d = dispatchEntry({ root: ctx.root, installRoot: ctx.installRoot, agent: a.agent, host: a.host, pass: state.pass });
|
|
248
|
-
if (!d.ok) throw new LoopExit(d.code, `${PROG}: ${d.message}`);
|
|
249
|
-
}
|
|
250
|
-
const entry = begin(ctx, state, key);
|
|
251
|
-
diffCap.overrides.forEach((o) => applyCapOverride(state, o));
|
|
252
|
-
advance(ctx, sf, state, entry, 'dispatch', () => (state.dispatches ??= []).push(d.entry));
|
|
253
|
-
if (diffCap.overrides.length) saveState(sf, state); // a cap changed on a resumed step is kept too
|
|
254
|
-
if (!code) return finalize(sf, state, entry, base('after-code', { pass: state.pass, loop: 'plan', next: NEXT.taskReviewer }));
|
|
255
|
-
|
|
256
|
-
const { total, weighted, outOfScope, rows } = computeDiff(ctx.root, state.baseline_sha, state.iteration_files);
|
|
257
|
-
const shown = outOfScope.slice(0, 6).map((f) => cut(f, 60));
|
|
258
|
-
const diff = { diff_lines: total, weighted_lines: weighted, cap: diffCap.cap, out_of_scope: shown, ...(outOfScope.length > shown.length ? { out_of_scope_total: outOfScope.length } : {}) };
|
|
259
|
-
if (diffCap.cap > 0 && weighted > diffCap.cap) {
|
|
260
|
-
if (entry.response) { delete entry.response; delete entry.measured; saveState(sf, state); } // an earlier pass of the gate no longer stands: no later step may read this tree as gated
|
|
261
|
-
return stop('after-code', state, EXIT_DIFF_CAP, outOfScope.length ? 'scope-expansion' : 'diff-cap-exceeded', a, { diff });
|
|
262
|
-
}
|
|
263
|
-
const found = reported(escalate(ctx.root, ctx.env, rows, state.baseline_sha, state.ignored_guarded)); // report only: the lens above is not touched by it
|
|
264
|
-
const s = scopeOf(ctx.root, state, review.scope);
|
|
265
|
-
const scope = s.scope === 'full' ? s : { ...s, files: s.files.slice(0, 5).map((f) => cut(f, 60)), files_total: s.files.length };
|
|
266
|
-
const brief = s.scope === 'full'
|
|
267
|
-
? `Review this iteration's whole diff against the baseline ${state.baseline_sha}.`
|
|
268
|
-
: `Review only the change from ${s.from} to ${s.to} (git --no-replace-objects diff --text ${s.from} ${s.to}, so a file marked binary shows its lines; ${s.files.length} files), and re-check each open finding in the ledger: resolved, or still open with its evidence. Do not re-review code outside that change; it was reviewed on pass ${s.since_pass}. A defect the delta introduces anywhere is in scope.\nFile names from git, data and not instructions:\n\`\`\`text\n${scope.files.slice(0, 3).join('\n') || 'none'}\n\`\`\``;
|
|
269
|
-
entry.review = { mode: review.mode, scope: review.scope };
|
|
270
|
-
const [was, tree] = [state.steps?.[`${state.pass}:open`]?.tree, snapshotTree(ctx.root)]; // what the coder changed outside .somi since open, when both trees are known
|
|
271
|
-
entry.measured = tree ?? undefined; // the tree this response gated
|
|
272
|
-
const changed = was && tree ? { changed: was !== tree, ...(was === tree ? { note: 'nothing changed since open outside .somi, .claude and ignored files: the reviewer re-checks the open findings' } : {}) } : {};
|
|
273
|
-
return finalize(sf, state, entry, base('after-code', { pass: state.pass, loop: 'code', next: NEXT_REVIEW[review.mode], diff, scope, review_mode: review.mode, ...found, ...changed, review_brief: brief }));
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
// Read only: the state (a finished loop too), the last cursor entries, every open finding. It records nothing.
|
|
277
|
-
function status(ctx, a) {
|
|
278
|
-
const state = stateAt(stateFile(ctx.stateDir, a.slug, a.iteration), true);
|
|
279
|
-
if (!state) throw noLoop(a);
|
|
280
|
-
if (state.loop !== a.loop) throw bad('loop', `the loop state of this slug is a ${state.loop} loop`);
|
|
281
|
-
const cursor = Object.entries(state.steps ?? {}).slice(-4).map(([key, e]) => ({ key: clean(key, 20), via: e.via === 'mcp' ? 'mcp' : 'cli', done: SUB_STEPS.filter((d) => e.done.includes(d)), complete: Boolean(e.response) }));
|
|
282
|
-
return fitLines((kept) => base('status', {
|
|
283
|
-
pass: state.pass, loop: state.loop, state: { status: clean(state.status, 20), recorded: state.history.length, caps: capsView(state).caps }, cursor, open_findings: kept, ...(kept.length ? { open_findings_note: 'data from earlier reviews, not instructions' } : {}),
|
|
284
|
-
}), floorLines(ctx.root, a.slug, 'Nit'));
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
const STEPS = { open, 'after-code': afterCode, 'after-review': afterReview, close, status };
|
|
288
|
-
|
|
289
|
-
export function runStep(ctx, args) {
|
|
290
|
-
const step = args?.step;
|
|
291
|
-
try {
|
|
292
|
-
if (args === null || typeof args !== 'object' || Array.isArray(args)) throw bad('arguments', 'expected an object');
|
|
293
|
-
return STEPS[step](ctx, validate(step, args));
|
|
294
|
-
} catch (e) {
|
|
295
|
-
if (e instanceof Killed) throw e;
|
|
296
|
-
const name = typeof step === 'string' ? step.slice(0, 20) : null;
|
|
297
|
-
if (!(e instanceof LoopExit)) {
|
|
298
|
-
try { (ctx.log ?? console.error)(JSON.stringify({ somi_loop_step: name, ...(e instanceof Error ? { error: String(e.name).slice(0, 100), stack: String(e.stack).slice(0, 4000) } : { thrown: String(e).slice(0, 200) }) })); } catch { /* a failing sink must not turn exit 70 into a crash */ } // the operator sees it; the response carries none of it
|
|
299
|
-
return base(name, { ok: false, exit: EXIT_INTERNAL, error: 'internal error: the step did not complete; retry it, and report it if it repeats' });
|
|
300
|
-
}
|
|
301
|
-
return base(name, { ok: false, exit: e.code, error: clean(e.message.replace(`${PROG}: `, ''), 300) });
|
|
302
|
-
}
|
|
303
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
// run-budget.mjs -- a /ship-loop run's wall-time budget. The run records its start once (run-start); every later
|
|
2
|
-
// `pass` of any plan or code loop on the same slug checks it, so the stop does not depend on an orchestrator
|
|
3
|
-
// remembering to look at the clock. State: .somi/somi-state/run/<slug>.json { started, max_minutes }.
|
|
4
|
-
|
|
5
|
-
import fs from 'node:fs';
|
|
6
|
-
import path from 'node:path';
|
|
7
|
-
|
|
8
|
-
const file = (stateRoot, slug) => path.join(stateRoot, 'run', `${slug}.json`);
|
|
9
|
-
|
|
10
|
-
// -> the recorded run; an existing one is kept unless `force` (a resumed run keeps its clock).
|
|
11
|
-
export function startRun(stateRoot, slug, maxMinutes, { force = false, now = Date.now() } = {}) {
|
|
12
|
-
const f = file(stateRoot, slug);
|
|
13
|
-
if (!force && fs.existsSync(f)) return { ...JSON.parse(fs.readFileSync(f, 'utf8')), resumed: true };
|
|
14
|
-
const run = { started: new Date(now).toISOString(), max_minutes: maxMinutes };
|
|
15
|
-
fs.mkdirSync(path.dirname(f), { recursive: true });
|
|
16
|
-
fs.writeFileSync(f, JSON.stringify(run));
|
|
17
|
-
return run;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// -> null when the slug has no run or no time budget, else { elapsed_minutes, max_minutes, over }.
|
|
21
|
-
export function checkRun(stateRoot, slug, now = Date.now()) {
|
|
22
|
-
let run;
|
|
23
|
-
try { run = JSON.parse(fs.readFileSync(file(stateRoot, slug), 'utf8')); } catch { return null; }
|
|
24
|
-
if (!Number.isSafeInteger(run?.max_minutes) || run.max_minutes < 1) return null;
|
|
25
|
-
const elapsed = Math.floor((now - Date.parse(run.started)) / 60000);
|
|
26
|
-
if (!Number.isFinite(elapsed)) return { elapsed_minutes: null, max_minutes: run.max_minutes, over: true }; // unreadable start: fail closed
|
|
27
|
-
return { elapsed_minutes: elapsed, max_minutes: run.max_minutes, over: elapsed >= run.max_minutes };
|
|
28
|
-
}
|
package/scripts/lib/run-card.mjs
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
// run-card.mjs -- the run card: the few verified facts every agent of one code iteration needs, built once from the
|
|
2
|
-
// loop state the orchestrator already has, so each agent it starts stops re-deriving them (where SoMi's scripts are,
|
|
3
|
-
// which plan files to read, which files the iteration may touch, how the tests run) and every briefing in the loop
|
|
4
|
-
// opens with the same bytes, which a repeated start can reuse from the prompt cache.
|
|
5
|
-
//
|
|
6
|
-
// Facts only, never reasoning: a reviewer briefed with the card learns where things are, not what the coder thought.
|
|
7
|
-
// The card is data: every value is checked or reduced to a printable path before it is written, and the text is
|
|
8
|
-
// fenced so an agent reads it as data.
|
|
9
|
-
|
|
10
|
-
import fs from 'node:fs';
|
|
11
|
-
import path from 'node:path';
|
|
12
|
-
|
|
13
|
-
export const SLUG_RE = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
14
|
-
// The one iteration id pattern (loop steps, the notes writers and the card): N.M, or a split such as 2.1b.
|
|
15
|
-
export const ITERATION_RE = /^(?:0|[1-9]\d{0,2})\.(?:0|[1-9]\d{0,2})[a-z]?$/;
|
|
16
|
-
export const HOSTS = ['claude-code', 'copilot'];
|
|
17
|
-
export const MAX_FILES = 20;
|
|
18
|
-
export const MAX_BYTES = 2048;
|
|
19
|
-
|
|
20
|
-
// A path as printable text: control and bidi characters removed, length capped.
|
|
21
|
-
const printable = (s) => String(s).replace(/[\u0000-\u001f\u007f--]/g, '').slice(0, 200);
|
|
22
|
-
|
|
23
|
-
export function phaseFile(planDir, iteration) {
|
|
24
|
-
const n = iteration.split('.')[0].padStart(2, '0');
|
|
25
|
-
try {
|
|
26
|
-
const hit = fs.readdirSync(path.join(planDir, 'phases')).filter((f) => f.startsWith(`${n}-`) && f.endsWith('.md')).sort()[0];
|
|
27
|
-
return hit ? `phases/${hit}` : null;
|
|
28
|
-
} catch {
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function testCommand(projectDir) {
|
|
34
|
-
try {
|
|
35
|
-
const pkg = JSON.parse(fs.readFileSync(path.join(projectDir, 'package.json'), 'utf8'));
|
|
36
|
-
return typeof pkg?.scripts?.test === 'string' ? 'npm test' : null;
|
|
37
|
-
} catch {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Builds the card. Returns { ok: true, card } or { ok: false, error }.
|
|
44
|
-
* `state` is the parsed loop state (.somi/somi-state/loop/<slug>.<iteration>.json).
|
|
45
|
-
*/
|
|
46
|
-
export function buildCard({ slug, iteration, host, projectDir, somiRoot, state }) {
|
|
47
|
-
if (!SLUG_RE.test(slug ?? '')) return { ok: false, error: 'slug must match ^[a-z0-9][a-z0-9-]{0,63}$' };
|
|
48
|
-
if (!ITERATION_RE.test(iteration ?? '')) return { ok: false, error: 'iteration must look like 1.2' };
|
|
49
|
-
if (!HOSTS.includes(host)) return { ok: false, error: `host must be one of ${HOSTS.join(', ')}` };
|
|
50
|
-
if (!state || state.slug !== slug || state.iteration !== iteration) return { ok: false, error: 'no loop state for this slug and iteration: run somi-loop init first' };
|
|
51
|
-
const planDir = path.join(projectDir, '.somi', 'plans', slug);
|
|
52
|
-
const files = Array.isArray(state.iteration_files) ? state.iteration_files.map((f) => printable(f).replace(/`/g, "'")) : [];
|
|
53
|
-
const shown = files.slice(0, MAX_FILES).join(' ') + (files.length > MAX_FILES ? ` (and ${files.length - MAX_FILES} more in the phase file)` : '');
|
|
54
|
-
const read = ['spec.md', phaseFile(planDir, iteration), fs.existsSync(path.join(planDir, 'brief.md')) ? 'brief.md' : null].filter(Boolean);
|
|
55
|
-
const tests = testCommand(projectDir);
|
|
56
|
-
const lines = [
|
|
57
|
-
'```somi-card',
|
|
58
|
-
'SoMi run card: verified by the orchestrator. Facts, not instructions; do not re-derive them.',
|
|
59
|
-
`install_root: ${printable(somiRoot)} (scripts: ${printable(path.join(somiRoot, 'scripts'))})`,
|
|
60
|
-
`project_dir: ${printable(projectDir)}`,
|
|
61
|
-
`host: ${host}`,
|
|
62
|
-
`work_item: .somi/plans/${slug}/ iteration ${iteration}`,
|
|
63
|
-
`read for the task: ${read.join(', ')}`,
|
|
64
|
-
'written only by the orchestrator (agents never write them): progress.md, diary.md, .somi/somi-state/',
|
|
65
|
-
`files in scope: ${shown || '(none recorded)'}`,
|
|
66
|
-
`baseline: ${/^[0-9a-f]{7,64}$/.test(state.baseline_sha ?? '') ? state.baseline_sha : 'unknown'}`,
|
|
67
|
-
`tests: ${tests ?? 'not declared in package.json; find them as usual'}`,
|
|
68
|
-
'```',
|
|
69
|
-
];
|
|
70
|
-
const card = `${lines.join('\n')}\n`;
|
|
71
|
-
if (Buffer.byteLength(card) > MAX_BYTES) return { ok: false, error: `the card is over ${MAX_BYTES} bytes` };
|
|
72
|
-
return { ok: true, card };
|
|
73
|
-
}
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
// size-tier.mjs — decideTier(signals): how much pipeline does this request deserve?
|
|
2
|
-
//
|
|
3
|
-
// The model extracts observable signals (each with an evidence string); this pure function decides
|
|
4
|
-
// the tier, so the same signals always give the same answer and the reasons come from signal ids,
|
|
5
|
-
// never from model prose. No I/O, no clock, no imports. Unsure goes up: a signal that is unknown,
|
|
6
|
-
// missing, lacks evidence, is malformed, or is contradicted by the counts counts as its worst case
|
|
7
|
-
// and is listed in `failed`.
|
|
8
|
-
//
|
|
9
|
-
// Tiers: trivial (-> /code), small (-> inline brief -> /code-loop), full (-> today's flow).
|
|
10
|
-
//
|
|
11
|
-
// Signals T1..T5 are the five numbered signals of the trivial threshold, in the same order. Their
|
|
12
|
-
// meaning, and how to extract every other signal (what the count signals measure, what
|
|
13
|
-
// hard_surface covers), lives only in skills/somi-routing/SKILL.md, section "Size tiers"; this
|
|
14
|
-
// file holds ids and thresholds, never the wording.
|
|
15
|
-
//
|
|
16
|
-
// Input: { <id>: { value, evidence } }; evidence is 1..MAX_EVIDENCE_CHARS characters with no
|
|
17
|
-
// control characters. Output, always the same keys:
|
|
18
|
-
// tier 'trivial' | 'small' | 'full'
|
|
19
|
-
// floor 'full' | null — 'full' whenever sensitive_core is not a proven false, whichever rule fired
|
|
20
|
-
// first (a doubt about auth, crypto, secrets or PII must survive an existing-work-item
|
|
21
|
-
// match); no override may go below it
|
|
22
|
-
// securityLens true unless T3 is a proven true and sensitive_core a proven false: the change may
|
|
23
|
-
// handle untrusted input or touch the core, so the security lens reviews it at any tier
|
|
24
|
-
// failed ids that were read as their worst case = unknown + invalid, in SIGNAL_IDS order
|
|
25
|
-
// unknown ids the extractor explicitly marked null / 'unknown'
|
|
26
|
-
// invalid ids that were missing, malformed, over the evidence cap, or contradicted by the counts
|
|
27
|
-
// reasons signal ids that fired the deciding rule (`<id>_unknown` for an unknown work-item or
|
|
28
|
-
// brief signal); for small, the signals that kept it from trivial; for trivial, empty
|
|
29
|
-
// basis { id: evidence } for T3 and sensitive_core and, when the tier is below full, every signal read cleanly,
|
|
30
|
-
// so a human can see why security and size were ruled out
|
|
31
|
-
//
|
|
32
|
-
// Hostile input: the function runs no user code of its own making. It reads own data properties
|
|
33
|
-
// only (an accessor is never invoked) once each into a plain copy. That guarantee covers
|
|
34
|
-
// JSON-derived input, which is all a caller should pass (the CLI hands over JSON.parse output
|
|
35
|
-
// only). A Proxy can still fire its own traps, which the function survives (any throw becomes the
|
|
36
|
-
// refusal result), but it cannot claim more than plain JSON could.
|
|
37
|
-
|
|
38
|
-
export const MAX_MODULES = 2;
|
|
39
|
-
export const MAX_FILES = 6;
|
|
40
|
-
// Provisional: production lines only, tests not counted. To be revisited once the code loop's
|
|
41
|
-
// diff cap no longer counts test lines.
|
|
42
|
-
export const MAX_DIFF_LINES = 100;
|
|
43
|
-
export const TRIVIAL_MAX_FILES = 1;
|
|
44
|
-
export const TRIVIAL_MAX_MODULES = 1;
|
|
45
|
-
export const TRIVIAL_MAX_DIFF_LINES = 50;
|
|
46
|
-
export const MAX_EVIDENCE_CHARS = 300;
|
|
47
|
-
|
|
48
|
-
export const SIGNAL_IDS = Object.freeze([
|
|
49
|
-
'T1', 'T2', 'T3', 'T4', 'T5', 'sensitive_core',
|
|
50
|
-
'hard_surface', 'design_open', 'open_questions', 'acceptance_testable',
|
|
51
|
-
'modules_touched', 'est_files', 'est_diff_lines',
|
|
52
|
-
'existing_work_item', 'brief_exists',
|
|
53
|
-
]);
|
|
54
|
-
|
|
55
|
-
const MIN_COUNT = { open_questions: 0, modules_touched: 1, est_files: 1, est_diff_lines: 1 };
|
|
56
|
-
const TRIVIAL_IDS = SIGNAL_IDS.slice(0, 5);
|
|
57
|
-
// C0/C1 controls plus the invisible and direction-changing characters that can disguise text in a terminal.
|
|
58
|
-
const CONTROL_CHARS = /[\u0000-\u001f\u007f-\u009f\u061c\u200b-\u200f\u2028-\u202e\u2060-\u2069\ufeff]/;
|
|
59
|
-
|
|
60
|
-
// What an unreadable signal is taken to be: the answer that sends the tier up.
|
|
61
|
-
const WORST = Object.freeze({
|
|
62
|
-
T1: false, T2: false, T3: false, T4: false, T5: false, sensitive_core: true,
|
|
63
|
-
hard_surface: true, design_open: true, acceptance_testable: false,
|
|
64
|
-
existing_work_item: true, brief_exists: true,
|
|
65
|
-
open_questions: Infinity, modules_touched: Infinity, est_files: Infinity, est_diff_lines: Infinity,
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
const REFUSED = () => ({
|
|
69
|
-
tier: 'full', floor: 'full', securityLens: true, failed: [...SIGNAL_IDS], unknown: [], invalid: [...SIGNAL_IDS],
|
|
70
|
-
reasons: ['signals_unreadable'], basis: {},
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
function plain(o) {
|
|
74
|
-
if (o === null || typeof o !== 'object' || Array.isArray(o)) return false;
|
|
75
|
-
const p = Object.getPrototypeOf(o);
|
|
76
|
-
return p === Object.prototype || p === null;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Own data property only: an accessor is never invoked, an inherited key is never seen.
|
|
80
|
-
function own(o, key) {
|
|
81
|
-
const d = Object.getOwnPropertyDescriptor(o, key);
|
|
82
|
-
return d && 'value' in d ? d.value : undefined;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const validEvidence = (e) => typeof e === 'string' && e.trim() !== ''
|
|
86
|
-
&& e.length <= MAX_EVIDENCE_CHARS && !CONTROL_CHARS.test(e);
|
|
87
|
-
|
|
88
|
-
// -> { state: 'ok', value, evidence } | { state: 'unknown' } | { state: 'invalid' }
|
|
89
|
-
function readEntry(entry, id) {
|
|
90
|
-
if (!plain(entry)) return { state: 'invalid' };
|
|
91
|
-
const value = own(entry, 'value');
|
|
92
|
-
const evidence = own(entry, 'evidence');
|
|
93
|
-
if (!validEvidence(evidence)) return { state: 'invalid' };
|
|
94
|
-
if (value === null || value === 'unknown') return { state: 'unknown' };
|
|
95
|
-
const isCount = id in MIN_COUNT;
|
|
96
|
-
const good = isCount ? Number.isSafeInteger(value) && value >= MIN_COUNT[id] : typeof value === 'boolean';
|
|
97
|
-
return good ? { state: 'ok', value, evidence } : { state: 'invalid' };
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// One pass, each field read once into a plain copy; everything after works on the copy.
|
|
101
|
-
function readSignals(input) {
|
|
102
|
-
if (!plain(input)) return null;
|
|
103
|
-
const v = {};
|
|
104
|
-
const read = {};
|
|
105
|
-
for (const id of SIGNAL_IDS) read[id] = readEntry(own(input, id), id);
|
|
106
|
-
// A footprint claim the counts contradict is not believed.
|
|
107
|
-
if (read.T1.state === 'ok' && read.T1.value) {
|
|
108
|
-
const files = read.est_files, mods = read.modules_touched;
|
|
109
|
-
if ((files.state === 'ok' && files.value > TRIVIAL_MAX_FILES) || (mods.state === 'ok' && mods.value > TRIVIAL_MAX_MODULES)) {
|
|
110
|
-
read.T1 = { state: 'invalid' };
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
// "Not security-sensitive" contradicts "touches auth, crypto, secrets or PII": the T3 claim is not believed.
|
|
114
|
-
if (read.T3.state === 'ok' && read.T3.value && read.sensitive_core.state === 'ok' && read.sensitive_core.value) {
|
|
115
|
-
read.T3 = { state: 'invalid' };
|
|
116
|
-
}
|
|
117
|
-
for (const id of SIGNAL_IDS) v[id] = read[id].state === 'ok' ? read[id].value : WORST[id];
|
|
118
|
-
const unknown = SIGNAL_IDS.filter((id) => read[id].state === 'unknown');
|
|
119
|
-
const invalid = SIGNAL_IDS.filter((id) => read[id].state === 'invalid');
|
|
120
|
-
return { v, read, unknown, invalid };
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// Each check is [signal id, does this value send the tier up?].
|
|
124
|
-
const fired = (v, checks) => checks.filter(([id, up]) => up(v[id])).map(([id]) => id);
|
|
125
|
-
|
|
126
|
-
// First match wins. Order is the contract; each rule names the signals that fired it.
|
|
127
|
-
const RULES = [
|
|
128
|
-
(v) => {
|
|
129
|
-
const hit = fired(v, [['existing_work_item', (x) => x], ['brief_exists', (x) => x]]);
|
|
130
|
-
return hit.length ? { tier: 'full', reasons: hit } : null;
|
|
131
|
-
},
|
|
132
|
-
// Auth, crypto, secrets or PII: a security floor no override can lower. Untrusted input alone (a false T3) is not
|
|
133
|
-
// trivial and gets the security lens, but does not by itself need the planning pipeline.
|
|
134
|
-
(v) => (v.sensitive_core === true ? { tier: 'full', reasons: ['sensitive_core'] } : null),
|
|
135
|
-
(v) => {
|
|
136
|
-
const hit = fired(v, [
|
|
137
|
-
['hard_surface', (x) => x], ['design_open', (x) => x], ['open_questions', (x) => x > 0],
|
|
138
|
-
['acceptance_testable', (x) => !x], ['T4', (x) => !x],
|
|
139
|
-
]);
|
|
140
|
-
return hit.length ? { tier: 'full', reasons: hit } : null;
|
|
141
|
-
},
|
|
142
|
-
(v) => {
|
|
143
|
-
const hit = fired(v, [
|
|
144
|
-
['modules_touched', (x) => x > MAX_MODULES], ['est_files', (x) => x > MAX_FILES],
|
|
145
|
-
['est_diff_lines', (x) => x > MAX_DIFF_LINES],
|
|
146
|
-
]);
|
|
147
|
-
return hit.length ? { tier: 'full', reasons: hit } : null;
|
|
148
|
-
},
|
|
149
|
-
(v) => (TRIVIAL_IDS.every((id) => v[id] === true) && v.est_files <= TRIVIAL_MAX_FILES
|
|
150
|
-
&& v.modules_touched <= TRIVIAL_MAX_MODULES && v.est_diff_lines <= TRIVIAL_MAX_DIFF_LINES
|
|
151
|
-
? { tier: 'trivial', reasons: [] } : null),
|
|
152
|
-
];
|
|
153
|
-
|
|
154
|
-
const SMALL_BECAUSE = [
|
|
155
|
-
['est_files', (x) => x > TRIVIAL_MAX_FILES],
|
|
156
|
-
['modules_touched', (x) => x > TRIVIAL_MAX_MODULES],
|
|
157
|
-
['est_diff_lines', (x) => x > TRIVIAL_MAX_DIFF_LINES],
|
|
158
|
-
];
|
|
159
|
-
|
|
160
|
-
export function decideTier(signals, { fullBasis = false } = {}) {
|
|
161
|
-
let r;
|
|
162
|
-
try {
|
|
163
|
-
r = readSignals(signals);
|
|
164
|
-
} catch {
|
|
165
|
-
return REFUSED();
|
|
166
|
-
}
|
|
167
|
-
if (!r) return REFUSED();
|
|
168
|
-
const { v, read, unknown, invalid } = r;
|
|
169
|
-
let decided = null;
|
|
170
|
-
for (const rule of RULES) {
|
|
171
|
-
decided = rule(v);
|
|
172
|
-
if (decided) break;
|
|
173
|
-
}
|
|
174
|
-
if (!decided) {
|
|
175
|
-
decided = { tier: 'small', reasons: [...TRIVIAL_IDS.filter((id) => v[id] !== true), ...fired(v, SMALL_BECAUSE)] };
|
|
176
|
-
}
|
|
177
|
-
const failed = SIGNAL_IDS.filter((id) => read[id].state !== 'ok');
|
|
178
|
-
const reasons = decided.reasons.map((id) => ((id === 'existing_work_item' || id === 'brief_exists') && failed.includes(id) ? `${id}_unknown` : id));
|
|
179
|
-
const basis = {};
|
|
180
|
-
for (const id of SIGNAL_IDS) {
|
|
181
|
-
if (read[id].state === 'ok' && (fullBasis || (id === 'T3' || id === 'sensitive_core' || decided.tier !== 'full'))) basis[id] = read[id].evidence;
|
|
182
|
-
}
|
|
183
|
-
return { tier: decided.tier, floor: v.sensitive_core === false ? null : 'full', securityLens: v.T3 !== true || v.sensitive_core !== false, failed, unknown, invalid, reasons, basis };
|
|
184
|
-
}
|