@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
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// check.mjs: `somi check`, the fast gate before every commit, and `somi check --full`, the push gate.
|
|
2
|
+
//
|
|
3
|
+
// It runs project commands, so only the CLI calls it, from a shell the OS sandbox wraps. The MCP server runs outside the sandbox and
|
|
4
|
+
// must never reach this module. The plan comes from a committed somi.check.json:
|
|
5
|
+
// { "budget_s": 60, "fast_cmd": "npm run lint", "full_cmd": "npm test", "always": ["tests/x.test.mjs"],
|
|
6
|
+
// "map": { "scripts/lib/a.mjs": ["tests/a.test.mjs"], "hooks/": ["tests/hooks.test.mjs"] },
|
|
7
|
+
// "model_name_gate": true, "gate_exclude": ["CHANGELOG.md"] }
|
|
8
|
+
// A map key ending in "/" is a prefix. A code file no key covers falls back to full_cmd, within the budget.
|
|
9
|
+
|
|
10
|
+
import fs from 'node:fs';
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
import os from 'node:os';
|
|
13
|
+
import vm from 'node:vm';
|
|
14
|
+
import { spawnSync } from 'node:child_process';
|
|
15
|
+
import { readDiff, baseRef, snapshotTree } from './git-tree.mjs';
|
|
16
|
+
import { qualityStep } from './quality/run.mjs';
|
|
17
|
+
import { readReviews } from './reviews.mjs';
|
|
18
|
+
import { conflictMarkerProblems, modelNameProblems, pipefailProblems, planningIdProblems } from './gates.mjs';
|
|
19
|
+
|
|
20
|
+
const DEFAULT_BUDGET_S = 60;
|
|
21
|
+
const MAX_SHOWN = 10;
|
|
22
|
+
const JS = /\.(mjs|cjs|js)$/;
|
|
23
|
+
const SHELL = /\.(sh|bash)$/;
|
|
24
|
+
const DOC = /\.(md|mdx|txt|rst|adoc|json|ya?ml|toml|png|svg)$/i;
|
|
25
|
+
const RUNNABLE_TEST = /(^|\/)[^/]*\.test\.(mjs|cjs|js)$|(^|\/)tests?\/[^/]+\.(sh|bash)$/;
|
|
26
|
+
|
|
27
|
+
export function loadPlan(root) {
|
|
28
|
+
const file = path.join(root, 'somi.check.json');
|
|
29
|
+
let plan = {};
|
|
30
|
+
try { plan = JSON.parse(fs.readFileSync(file, 'utf8')); } catch (e) { if (e.code !== 'ENOENT') throw new Error('somi.check.json is not valid JSON'); }
|
|
31
|
+
const strings = (v) => (Array.isArray(v) ? v.filter((x) => typeof x === 'string') : []);
|
|
32
|
+
const map = plan.map !== null && typeof plan.map === 'object' ? plan.map : {};
|
|
33
|
+
return {
|
|
34
|
+
budget_s: Number.isInteger(plan.budget_s) && plan.budget_s > 0 ? plan.budget_s : DEFAULT_BUDGET_S,
|
|
35
|
+
fast_cmd: typeof plan.fast_cmd === 'string' ? plan.fast_cmd : null,
|
|
36
|
+
full_cmd: typeof plan.full_cmd === 'string' ? plan.full_cmd : null,
|
|
37
|
+
always: strings(plan.always),
|
|
38
|
+
map: Object.fromEntries(Object.entries(map).map(([k, v]) => [k, strings(v)])),
|
|
39
|
+
model_name_gate: plan.model_name_gate === true,
|
|
40
|
+
gate_exclude: strings(plan.gate_exclude),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function selectTests(files, plan, exists) {
|
|
45
|
+
const tests = new Set(plan.always);
|
|
46
|
+
let unmapped = false;
|
|
47
|
+
for (const f of files) {
|
|
48
|
+
if (RUNNABLE_TEST.test(f)) { tests.add(f); continue; }
|
|
49
|
+
const hit = Object.entries(plan.map).filter(([k]) => f === k || (k.endsWith('/') && f.startsWith(k)));
|
|
50
|
+
hit.forEach(([, list]) => list.forEach((t) => tests.add(t)));
|
|
51
|
+
if (hit.length === 0 && !DOC.test(f) && exists(f)) unmapped = true;
|
|
52
|
+
}
|
|
53
|
+
return { tests: [...tests].filter(exists).sort(), unmapped };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const gate = (name, failures) => ({ name, ok: failures.length === 0, failures: failures.slice(0, MAX_SHOWN), more: Math.max(0, failures.length - MAX_SHOWN) });
|
|
57
|
+
|
|
58
|
+
// `node --check` accepts a broken .js that it cannot classify as a module or a script, so a .js file is tried both ways. Neither
|
|
59
|
+
// way runs the file.
|
|
60
|
+
function parses(abs) {
|
|
61
|
+
const checkAsModule = (file) => spawnSync(process.execPath, ['--check', file], { encoding: 'utf8', timeout: 10000 }).status === 0;
|
|
62
|
+
if (abs.endsWith('.mjs')) return checkAsModule(abs);
|
|
63
|
+
const text = fs.readFileSync(abs, 'utf8').replace(/^#!.*/, '');
|
|
64
|
+
// A host workflow script is the body of an async function after its meta block: top-level await and return are allowed there.
|
|
65
|
+
if (/(^|\/)workflows\/[^/]+\.js$/.test(abs)) { try { new vm.Script(`(async function () {\n${text.replace(/^export const meta = /m, 'const meta = ')}\n})`); return true; } catch { return false; } }
|
|
66
|
+
try { new vm.Script(`(function () {\n${text}\n})`); return true; } catch { /* not a script; it may still be a module */ }
|
|
67
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'somi-parse-'));
|
|
68
|
+
try {
|
|
69
|
+
const copy = path.join(dir, 'module.mjs');
|
|
70
|
+
fs.writeFileSync(copy, text);
|
|
71
|
+
return checkAsModule(copy);
|
|
72
|
+
} finally { fs.rmSync(dir, { recursive: true, force: true }); }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function lintGate(root, files) {
|
|
76
|
+
const failures = [];
|
|
77
|
+
for (const f of files) {
|
|
78
|
+
const abs = path.join(root, f);
|
|
79
|
+
if (!fs.existsSync(abs) || !fs.lstatSync(abs).isFile()) continue;
|
|
80
|
+
if (JS.test(f)) {
|
|
81
|
+
if (!parses(abs)) failures.push(`${f}: does not parse`);
|
|
82
|
+
} else if (f.endsWith('.json')) {
|
|
83
|
+
try { JSON.parse(fs.readFileSync(abs, 'utf8')); } catch { failures.push(`${f}: invalid JSON`); }
|
|
84
|
+
} else if (SHELL.test(f)) failures.push(...pipefailProblems(f, fs.readFileSync(abs, 'utf8')));
|
|
85
|
+
}
|
|
86
|
+
return gate('lint', failures);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function artefactGate(root, env) {
|
|
90
|
+
const failures = [];
|
|
91
|
+
try { readReviews(root, env); } catch (e) { failures.push(e.message); }
|
|
92
|
+
return gate('artefacts', failures);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function runShell(root, name, command, timeoutMs) {
|
|
96
|
+
const r = spawnSync('sh', ['-c', command], { cwd: root, encoding: 'utf8', timeout: timeoutMs, killSignal: 'SIGKILL', maxBuffer: 16 * 1024 * 1024 });
|
|
97
|
+
if (r.error?.code === 'ETIMEDOUT' || r.signal === 'SIGKILL') return gate(name, [`over the time budget: ${command}`]);
|
|
98
|
+
if (r.status === 0) return gate(name, []);
|
|
99
|
+
const tail = `${r.stdout ?? ''}${r.stderr ?? ''}`.trim().split('\n').slice(-6).join(' | ').slice(0, 600);
|
|
100
|
+
return gate(name, [`${command}: exit ${r.status}: ${tail}`]);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function runTests(root, tests, timeoutMs) {
|
|
104
|
+
const js = tests.filter((t) => !SHELL.test(t));
|
|
105
|
+
const results = [];
|
|
106
|
+
const start = Date.now();
|
|
107
|
+
const left = () => Math.max(1, timeoutMs - (Date.now() - start));
|
|
108
|
+
if (js.length > 0) {
|
|
109
|
+
// A test runner's child marker in the environment would make this run report nothing, so it is dropped.
|
|
110
|
+
const { NODE_TEST_CONTEXT: _child, ...env } = process.env;
|
|
111
|
+
const r = spawnSync(process.execPath, ['--test', ...js], { cwd: root, env, encoding: 'utf8', timeout: left(), killSignal: 'SIGKILL', maxBuffer: 32 * 1024 * 1024 });
|
|
112
|
+
if (r.error?.code === 'ETIMEDOUT' || r.signal === 'SIGKILL') results.push('tests went over the time budget; map fewer tests to this path');
|
|
113
|
+
else if (r.status !== 0) results.push(...`${r.stdout}`.split('\n').filter((l) => /^\s*not ok|^✖|^\s*✖/.test(l)).map((l) => l.trim()).slice(0, MAX_SHOWN), ...(r.status !== 0 && !/not ok|✖/.test(`${r.stdout}`) ? ['the test run failed'] : []));
|
|
114
|
+
}
|
|
115
|
+
for (const t of tests.filter((x) => SHELL.test(x))) {
|
|
116
|
+
const r = spawnSync('bash', [t], { cwd: root, encoding: 'utf8', timeout: left(), killSignal: 'SIGKILL' });
|
|
117
|
+
if (r.status !== 0) results.push(`${t}: failed`);
|
|
118
|
+
}
|
|
119
|
+
return gate('tests', results);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// The quality gate scores what a commit adds to the last one by default, and the whole branch with --full, which is what a push and a
|
|
123
|
+
// pull request carry. A staged build asks for the branch scope too, so it is held to what its pull request will be.
|
|
124
|
+
export function runCheck({ root, env = process.env, full = false, from = null, scope = full ? 'pr' : 'commit' }) {
|
|
125
|
+
const started = Date.now();
|
|
126
|
+
const plan = loadPlan(root);
|
|
127
|
+
const tree = snapshotTree(root);
|
|
128
|
+
const diff = readDiff(root, from ?? baseRef(root), tree);
|
|
129
|
+
// SoMi's working plan is never committed, and it may name the ticket's own ids. A project's committed config and rules are still scanned.
|
|
130
|
+
const excluded = (f) => f === '.somi/plan.md' || plan.gate_exclude.some((e) => f === e || (e.endsWith('/') && f.startsWith(e)));
|
|
131
|
+
const files = diff.rows.filter((r) => !r.status.startsWith('D')).map((r) => r.file);
|
|
132
|
+
const added = diff.lines.filter((l) => l.sign === '+' && !excluded(l.file));
|
|
133
|
+
|
|
134
|
+
const gates = [
|
|
135
|
+
gate('diff', diff.unreadable ? ['the diff is too large to read'] : []),
|
|
136
|
+
lintGate(root, files),
|
|
137
|
+
gate('conflict-markers', conflictMarkerProblems(added)),
|
|
138
|
+
gate('planning-ids', planningIdProblems(added)),
|
|
139
|
+
gate('model-names', plan.model_name_gate ? modelNameProblems(added) : []),
|
|
140
|
+
artefactGate(root, env),
|
|
141
|
+
];
|
|
142
|
+
const quality = qualityStep(root, { scope, env });
|
|
143
|
+
gates.push(gate('quality', quality.failures));
|
|
144
|
+
|
|
145
|
+
if (full) {
|
|
146
|
+
const command = plan.full_cmd ?? (hasNpmTest(root) ? 'npm test' : null);
|
|
147
|
+
gates.push(command ? runShell(root, 'full-suite', command, undefined) : gate('full-suite', []));
|
|
148
|
+
} else {
|
|
149
|
+
const budget = plan.budget_s * 1000;
|
|
150
|
+
const left = () => Math.max(1, budget - (Date.now() - started));
|
|
151
|
+
if (plan.fast_cmd) gates.push(runShell(root, 'fast', plan.fast_cmd, left()));
|
|
152
|
+
const selected = selectTests(files, plan, (f) => fs.existsSync(path.join(root, f)));
|
|
153
|
+
if (selected.unmapped && plan.full_cmd) gates.push(runShell(root, 'tests', plan.full_cmd, left()));
|
|
154
|
+
else if (selected.tests.length > 0) gates.push(runTests(root, selected.tests, left()));
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const failed = gates.filter((g) => !g.ok).map((g) => g.name);
|
|
158
|
+
// A command may write files of its own, so what it vouches for is the tree it leaves behind. Otherwise the check is out of date at once.
|
|
159
|
+
return { ok: failed.length === 0, tree: snapshotTree(root), full, failed, gates: gates.filter((g) => !g.ok), ran: gates.map((g) => g.name), elapsed_ms: Date.now() - started };
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function hasNpmTest(root) {
|
|
163
|
+
try { return typeof JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8')).scripts?.test === 'string'; } catch { return false; }
|
|
164
|
+
}
|
|
165
|
+
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Copilot CLI registers a workflow from an extension, not from a plugin's workflows folder, and hands it ctx.agent and the rest instead
|
|
2
|
+
// of globals. This runs the same workflow files there, so the two hosts share one source for every stage and its tier.
|
|
3
|
+
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
|
|
8
|
+
const WORKFLOWS_DIR = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', '..', 'workflows');
|
|
9
|
+
const AsyncFunction = Object.getPrototypeOf(async () => {}).constructor;
|
|
10
|
+
// Copilot's agent options, exactly. Anything else is dropped rather than sent, and agentType is Copilot's agent.
|
|
11
|
+
const AGENT_OPTIONS = ['label', 'schema', 'model', 'agent', 'reasoningEffort', 'contextTier'];
|
|
12
|
+
export const copilotName = (name) => `somi-${name}`;
|
|
13
|
+
|
|
14
|
+
/** A workflow file's literal meta and its body, which runs with agent, pipeline, parallel, phase, log and args in scope. */
|
|
15
|
+
export function parseWorkflow(text) {
|
|
16
|
+
const m = /^export const meta = (\{[\s\S]*?\n\})\n/.exec(text);
|
|
17
|
+
if (!m) throw new Error('a workflow file starts with its meta, a literal');
|
|
18
|
+
return { meta: Function(`return (${m[1]})`)(), body: text.slice(m[0].length) };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function copilotAgentOptions({ agentType, effort, ...rest } = {}) {
|
|
22
|
+
const opts = { ...rest, ...(agentType ? { agent: agentType } : {}), ...(effort ? { reasoningEffort: effort } : {}) };
|
|
23
|
+
return Object.fromEntries(Object.entries(opts).filter(([k]) => AGENT_OPTIONS.includes(k)));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Runs a parsed workflow against a Copilot run context. */
|
|
27
|
+
export function runOnCopilot({ body }, ctx) {
|
|
28
|
+
const agent = (prompt, opts) => ctx.agent(prompt, copilotAgentOptions(opts));
|
|
29
|
+
const run = new AsyncFunction('agent', 'pipeline', 'parallel', 'phase', 'log', 'args', body);
|
|
30
|
+
return run(agent, (items, ...stages) => ctx.pipeline(items, ...stages), (thunks) => ctx.parallel(thunks), (t) => ctx.phase(t), (m) => ctx.log(m), ctx.args);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Called by the extension `somi init` writes, with the SDK's own functions, which resolve only inside the extension's process. */
|
|
34
|
+
export async function registerCopilotWorkflows({ defineWorkflow, joinSession, dir = WORKFLOWS_DIR }) {
|
|
35
|
+
const workflows = fs.readdirSync(dir).filter((f) => f.endsWith('.js')).sort().map((f) => {
|
|
36
|
+
const parsed = parseWorkflow(fs.readFileSync(path.join(dir, f), 'utf8'));
|
|
37
|
+
const { name, description, phases } = parsed.meta;
|
|
38
|
+
return defineWorkflow({ meta: { name: copilotName(name), description, phases }, run: (ctx) => runOnCopilot(parsed, ctx) });
|
|
39
|
+
});
|
|
40
|
+
return joinSession({ workflows });
|
|
41
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// doctor.mjs: is the security boundary actually there? Reading settings is not proof, so the verdict comes from the vendor's own
|
|
2
|
+
// probes, run inside the agent's shell: writing to the home directory and reaching the network directly must both fail.
|
|
3
|
+
// Settings only add warnings about strictness. Run it from the agent, because a shell the user typed bypasses the sandbox.
|
|
4
|
+
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import os from 'node:os';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { spawnSync } from 'node:child_process';
|
|
9
|
+
import { resolveSpawn } from './tiers.mjs';
|
|
10
|
+
|
|
11
|
+
const WSL_REMEDY = 'Native Windows has no OS sandbox for agents. Run the agent inside WSL2 and run this again there.';
|
|
12
|
+
|
|
13
|
+
function readJson(file) {
|
|
14
|
+
try { return JSON.parse(fs.readFileSync(file, 'utf8')); } catch { return null; }
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Later files win, as they do on Claude Code: user, then project, then local.
|
|
18
|
+
export function sandboxSettings({ host, root, home = os.homedir(), env = process.env }) {
|
|
19
|
+
if (host === 'copilot') {
|
|
20
|
+
const dir = env.COPILOT_HOME || path.join(home, '.copilot');
|
|
21
|
+
return readJson(path.join(dir, 'settings.json'))?.sandbox ?? null;
|
|
22
|
+
}
|
|
23
|
+
const dir = env.CLAUDE_CONFIG_DIR || path.join(home, '.claude');
|
|
24
|
+
const files = [path.join(dir, 'settings.json'), path.join(root, '.claude', 'settings.json'), path.join(root, '.claude', 'settings.local.json')];
|
|
25
|
+
let merged = null;
|
|
26
|
+
for (const f of files) {
|
|
27
|
+
const s = readJson(f)?.sandbox;
|
|
28
|
+
if (s && typeof s === 'object') merged = { ...merged, ...s };
|
|
29
|
+
}
|
|
30
|
+
return merged;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function settingsWarnings(host, s) {
|
|
34
|
+
if (!s || s.enabled !== true) return ['the sandbox is not enabled in settings'];
|
|
35
|
+
const warnings = [];
|
|
36
|
+
if (host === 'claude') {
|
|
37
|
+
if (s.failIfUnavailable !== true) warnings.push('sandbox.failIfUnavailable is not true, so a missing sandbox silently runs commands unsandboxed');
|
|
38
|
+
if (s.allowUnsandboxedCommands !== false) warnings.push('sandbox.allowUnsandboxedCommands is not false, so a command can retry outside the sandbox');
|
|
39
|
+
} else {
|
|
40
|
+
if (s.allowBypass !== false) warnings.push('sandbox.allowBypass is not false, so a command can ask to retry outside the sandbox (enforceable only through managed settings)');
|
|
41
|
+
warnings.push('the Copilot CLI sandbox is in public preview and allows outbound internet by default; set host rules with /sandbox');
|
|
42
|
+
}
|
|
43
|
+
return warnings;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const defaultExec = (cmd, args) => spawnSync(cmd, args, { encoding: 'utf8', timeout: 20000 });
|
|
47
|
+
|
|
48
|
+
// A tier with no model runs on the session's, so its spend is not where the config says. Worth saying, not failing over.
|
|
49
|
+
export function tierWarnings(config, host) {
|
|
50
|
+
const unmapped = ['low', 'medium', 'high'].filter((t) => !resolveSpawn(config, host, t).enforced);
|
|
51
|
+
return unmapped.length ? [`no model is set for tier ${unmapped.join(', ')} on ${host}, so those workers run on the session's model; set them under tiers.${host} in config`] : [];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Under Auto, Copilot CLI gives every subagent the model Auto chose and ignores the agent's own, so tiers do nothing there.
|
|
55
|
+
export function autoWarnings(host, { home = os.homedir(), env = process.env } = {}) {
|
|
56
|
+
if (host !== 'copilot') return [];
|
|
57
|
+
const model = env.COPILOT_MODEL || readJson(path.join(env.COPILOT_HOME || path.join(home, '.copilot'), 'settings.json'))?.model;
|
|
58
|
+
return String(model ?? '').toLowerCase() === 'auto' ? ['the session model is Auto, so Copilot CLI ignores the model on every subagent and tiers do nothing; start with `somi setup`'] : [];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// An earlier somi init wrote the hooks into the project. Copilot CLI now runs the plugin's own, so with that file every hook runs twice.
|
|
62
|
+
export function duplicateHookWarnings(root) {
|
|
63
|
+
const file = path.join(root, '.github', 'hooks', 'somi.json');
|
|
64
|
+
return fs.existsSync(file) ? [`${file} was written by an earlier somi init, and Copilot CLI now runs the plugin's own hooks, so every SoMi hook runs twice; delete that file`] : [];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// A plugin's hooks can fail to load without any error. The audit hook runs on every tool call, so a log with nothing recent means none of them ran.
|
|
68
|
+
export function hookWarnings(root, { now = Date.now(), env = process.env } = {}) {
|
|
69
|
+
const log = env.SOMI_AUDIT_LOG || path.join(root, '.somi', 'audit.log');
|
|
70
|
+
try { if (now - fs.statSync(log).mtimeMs < 3600000) return []; } catch { /* no log is the same answer as an old one */ }
|
|
71
|
+
return ['no hook has logged a tool call here in the last hour, so the tripwire hooks may not be running on this host; run this from inside an agent session, and check that the SoMi plugin is enabled'];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function runDoctor({ root, host, config = {}, platform = process.platform, env = process.env, home = os.homedir(), exec = defaultExec, removeFile = fs.rmSync, pid = process.pid }) {
|
|
75
|
+
if (platform === 'win32') return { ok: false, verdict: 'FAIL', host, remedy: WSL_REMEDY, probes: [], warnings: [] };
|
|
76
|
+
const probePath = path.join(home, `.somi-sandbox-probe-${pid}`);
|
|
77
|
+
const touch = exec('touch', [probePath]);
|
|
78
|
+
const curl = exec('curl', ['--noproxy', '*', '--silent', '--max-time', '8', '--output', '/dev/null', 'https://example.com']);
|
|
79
|
+
if (touch.status === 0) { try { removeFile(probePath, { force: true }); } catch { /* the probe file is empty; the verdict stands */ } }
|
|
80
|
+
const absent = (r) => r.error?.code === 'ENOENT';
|
|
81
|
+
const probes = [
|
|
82
|
+
{ name: 'home-write', blocked: touch.status !== 0 && !absent(touch), detail: absent(touch) ? 'touch is not installed, so this was not verified' : undefined },
|
|
83
|
+
{ name: 'direct-network', blocked: curl.status !== 0 && !absent(curl), detail: absent(curl) ? 'curl is not installed, so this was not verified' : undefined },
|
|
84
|
+
];
|
|
85
|
+
const ok = probes.every((p) => p.blocked);
|
|
86
|
+
return {
|
|
87
|
+
ok, verdict: ok ? 'PASS' : 'FAIL', host, probes,
|
|
88
|
+
warnings: [...settingsWarnings(host, sandboxSettings({ host, root, home, env })), ...tierWarnings(config, host), ...autoWarnings(host, { home, env }), ...hookWarnings(root, { env }), ...duplicateHookWarnings(root)],
|
|
89
|
+
remedy: ok ? undefined : 'Enable the sandbox: `somi doctor --profile` prints the settings to merge into the host\'s own. Then check again from inside an agent session, because a command typed at a `!` prompt usually bypasses the sandbox.',
|
|
90
|
+
};
|
|
91
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// gates.mjs: the pure text gates behind `somi check`. Each takes lines and returns problems; none reads a file.
|
|
2
|
+
// They look only at lines this change added, so old text never blocks new work.
|
|
3
|
+
|
|
4
|
+
// A pointer that only resolves inside the local `.somi/` folder dangles for everyone who clones the repository.
|
|
5
|
+
const CODE_ID = new RegExp([
|
|
6
|
+
String.raw`\bF-?\d{2,}\b`, String.raw`\bD\d+[a-z]?\b`, String.raw`decisions\.md#`, String.raw`\b[Ii]teration \d`, String.raw`\b[Pp]hase[ -]\d`,
|
|
7
|
+
String.raw`\b[Mm]ilestone m?\d+\b`, String.raw`\(m\d+\)`, String.raw`\b\d\.\d+[a-z]?(?:'s)? pass \d`, String.raw`\b(?:this|that) iteration\b`,
|
|
8
|
+
String.raw`\bsee (?:the )?(?:diary|phase file)\b`, String.raw`\b(?:spec|context|brief)\.md §`, String.raw`\bthis work[ -]item\b`, String.raw`\.somi/(?:plans|reviews|rd|state)\b`,
|
|
9
|
+
].join('|'));
|
|
10
|
+
const PROSE_ID = new RegExp([
|
|
11
|
+
String.raw`\bF-?\d{2,}\b`, String.raw`\(D\d+[a-z]?\)`, String.raw`\bD\d+[a-z]?'s\b`, String.raw`decisions\.md#`, String.raw`\(m\d+\)`, String.raw`\.somi/(?:plans|reviews|rd)\b`,
|
|
12
|
+
].join('|'));
|
|
13
|
+
|
|
14
|
+
const CODE_EXT = /\.(mjs|cjs|js|jsx|ts|tsx|sh|bash|py|rb|go|rs|java|kt|cs|c|cc|cpp|h|hpp|swift|php)$/i;
|
|
15
|
+
const PROSE_EXT = /\.(md|mdx|rst|adoc)$/i;
|
|
16
|
+
const HASH_COMMENT = /\.(sh|bash|py|rb)$/i;
|
|
17
|
+
|
|
18
|
+
function commentText(line, file) {
|
|
19
|
+
const t = line.trim();
|
|
20
|
+
if (HASH_COMMENT.test(file)) {
|
|
21
|
+
if (t.startsWith('#!')) return null;
|
|
22
|
+
if (t.startsWith('#')) return t;
|
|
23
|
+
const at = line.search(/\s#\s/);
|
|
24
|
+
return at === -1 ? null : line.slice(at);
|
|
25
|
+
}
|
|
26
|
+
if (/^(\/\/|\/\*|\*)/.test(t)) return t;
|
|
27
|
+
const at = line.search(/\s\/\/\s/);
|
|
28
|
+
return at === -1 ? null : line.slice(at);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const shown = (l) => `${l.file}: ${l.text.trim().slice(0, 120)}`;
|
|
32
|
+
|
|
33
|
+
export function planningIdProblems(addedLines) {
|
|
34
|
+
const problems = [];
|
|
35
|
+
for (const l of addedLines) {
|
|
36
|
+
if (CODE_EXT.test(l.file)) {
|
|
37
|
+
const text = commentText(l.text, l.file);
|
|
38
|
+
if (text !== null && CODE_ID.test(text)) problems.push(shown(l));
|
|
39
|
+
} else if (PROSE_EXT.test(l.file) && PROSE_ID.test(l.text)) problems.push(shown(l));
|
|
40
|
+
}
|
|
41
|
+
return problems;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Shipped text that names a model generation goes stale with the next one. Off unless the repository asks for it, because a
|
|
45
|
+
// consumer's code may call a model on purpose.
|
|
46
|
+
const MODEL_NAME = /\b(claude-(?:opus|sonnet|haiku|fable|mythos)[-\w.]*|(?:opus|sonnet|haiku|fable|mythos) \d(?:\.\d)?|gpt-\d[\w.-]*|gemini-\d[\w.-]*)\b/i;
|
|
47
|
+
|
|
48
|
+
export function modelNameProblems(addedLines) {
|
|
49
|
+
return addedLines.filter((l) => MODEL_NAME.test(l.text)).map(shown);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function conflictMarkerProblems(addedLines) {
|
|
53
|
+
return addedLines.filter((l) => /^(<{7}|>{7})( |$)/.test(l.text)).map(shown);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const PIPE_TO_TRUNCATOR = /\|\s*(head|tail|cut)\b/;
|
|
57
|
+
const PIPEFAIL = /^\s*set\s+(-[a-z]*o\s+pipefail|-[a-z]+\s+pipefail|-o\s+pipefail)/m;
|
|
58
|
+
|
|
59
|
+
// A pipe into head, tail or cut hides the left command's exit status. `# pipe-ok` marks a line where the status does not matter.
|
|
60
|
+
export function pipefailProblems(file, text) {
|
|
61
|
+
const problems = [];
|
|
62
|
+
if (!PIPEFAIL.test(text)) problems.push(`${file}: no "set -o pipefail"`);
|
|
63
|
+
text.split('\n').forEach((line, i) => {
|
|
64
|
+
const t = line.trim();
|
|
65
|
+
if (t.startsWith('#') || !PIPE_TO_TRUNCATOR.test(t) || t.includes('# pipe-ok')) return;
|
|
66
|
+
problems.push(`${file}:${i + 1}: a pipe into head, tail or cut hides a failure; mark "# pipe-ok" if the status does not matter`);
|
|
67
|
+
});
|
|
68
|
+
return problems;
|
|
69
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
// git-tree.mjs: the working tree as git objects. Tracked, staged and untracked files go into a throwaway index and become a tree
|
|
2
|
+
// id, so "what changed" is a content hash, a re-run on an unchanged tree is recognisable, and a reviewer can read an exact diff.
|
|
3
|
+
// Nothing here touches the real index. SoMi's own state is left out so writing a record never changes the tree.
|
|
4
|
+
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import os from 'node:os';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { execFileSync } from 'node:child_process';
|
|
9
|
+
|
|
10
|
+
const SAFE = ['-c', 'core.fsmonitor=false', '-c', 'core.hooksPath=/dev/null', '-c', 'core.trustctime=true', '-c', 'core.checkStat=default', '-c', 'core.quotePath=false'];
|
|
11
|
+
const DIFF = ['--no-ext-diff', '--no-textconv', '--no-renames', '--no-color'];
|
|
12
|
+
const MAX_OUTPUT = 32 * 1024 * 1024;
|
|
13
|
+
|
|
14
|
+
const git = (root, args, opts = {}) => execFileSync('git', [...SAFE, ...args], { cwd: root, encoding: 'utf8', maxBuffer: MAX_OUTPUT, stdio: ['ignore', 'pipe', 'pipe'], ...opts });
|
|
15
|
+
|
|
16
|
+
// A repository's config can name programs git runs while reading files, and the MCP server runs outside the sandbox, so reading the tree
|
|
17
|
+
// must never start one. Files already in the index keep their cached stat, so switching filters off does not make them look changed.
|
|
18
|
+
function noFilters(root) {
|
|
19
|
+
let names = [];
|
|
20
|
+
try { names = git(root, ['config', '--name-only', '--get-regexp', '^filter\\.']).split('\n'); } catch { /* git exits 1 when there are none */ }
|
|
21
|
+
const drivers = new Set(names.map((n) => /^filter\.(.+)\.[^.]+$/.exec(n)?.[1]).filter(Boolean));
|
|
22
|
+
return [...drivers].flatMap((d) => ['-c', `filter.${d}.clean=`, '-c', `filter.${d}.smudge=`, '-c', `filter.${d}.process=`, '-c', `filter.${d}.required=false`]);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function isClean(root) {
|
|
26
|
+
return git(root, [...noFilters(root), 'status', '--porcelain', '--', '.', ':(glob,exclude)**/.somi/**']).trim() === '';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const stateIsTracked = (root) => git(root, ['ls-files', '--cached', '--', ':(glob)**/.somi/state/**']).trim() !== '';
|
|
30
|
+
|
|
31
|
+
// The tree of a commit or tree id, for telling "nothing changed" apart from "changed and already committed".
|
|
32
|
+
export const treeOf = (root, ref) => git(root, ['rev-parse', '--verify', `${ref}^{tree}`]).trim();
|
|
33
|
+
|
|
34
|
+
// Everything except SoMi's own folder, in one commit, with a message that never passes through a shell.
|
|
35
|
+
export function commitAll(root, message) {
|
|
36
|
+
execFileSync('git', ['add', '-A'], { cwd: root, stdio: 'ignore' });
|
|
37
|
+
execFileSync('git', ['reset', '-q', '--', ':(glob)**/.somi/**'], { cwd: root, stdio: 'ignore' });
|
|
38
|
+
if (execFileSync('git', ['diff', '--cached', '--name-only'], { cwd: root, encoding: 'utf8' }).trim() === '') return false;
|
|
39
|
+
execFileSync('git', ['commit', '-q', '-m', message], { cwd: root, stdio: 'ignore' });
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function repoRoot(cwd) {
|
|
44
|
+
return git(cwd, ['rev-parse', '--show-toplevel']).trim();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// What a commit adds to: the last commit when there is work not yet committed, as before a commit, or else the last commit's parent, so
|
|
48
|
+
// the last commit itself is scored. With no parent it is the empty tree.
|
|
49
|
+
export function commitBase(root) {
|
|
50
|
+
const head = headSha(root);
|
|
51
|
+
if (head === null) return baseRef(root);
|
|
52
|
+
if (!isClean(root)) return head;
|
|
53
|
+
try { return git(root, ['rev-parse', '--verify', '--quiet', 'HEAD^']).trim(); } catch { return git(root, ['hash-object', '-t', 'tree', '--stdin'], { stdio: ['pipe', 'pipe', 'pipe'], input: '' }).trim(); }
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function headSha(root) {
|
|
57
|
+
try { return git(root, ['rev-parse', '--verify', '--quiet', 'HEAD']).trim(); } catch { return null; }
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function baseRef(root) {
|
|
61
|
+
return headSha(root) ?? git(root, ['hash-object', '-t', 'tree', '--stdin'], { stdio: ['pipe', 'pipe', 'pipe'], input: '' }).trim();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Where this line of work left the shared history. A branch compares against the default branch. On the default branch itself it
|
|
65
|
+
// compares against its upstream. With neither, only what is not committed yet counts.
|
|
66
|
+
export function workBase(root) {
|
|
67
|
+
const quiet = (args) => { try { return git(root, args, { stdio: ['ignore', 'pipe', 'ignore'] }).trim(); } catch { return null; } };
|
|
68
|
+
const head = headSha(root);
|
|
69
|
+
if (head === null) return baseRef(root);
|
|
70
|
+
for (const ref of ['origin/HEAD', 'origin/main', 'main', 'origin/master', 'master']) {
|
|
71
|
+
const shared = quiet(['merge-base', head, ref]);
|
|
72
|
+
if (shared && shared !== head) return shared;
|
|
73
|
+
if (shared) break;
|
|
74
|
+
}
|
|
75
|
+
const upstream = quiet(['merge-base', head, '@{upstream}']);
|
|
76
|
+
return upstream ?? head;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Subjects of the commits since a base, oldest first, with hostile control characters left for the renderer to strip.
|
|
80
|
+
export function commitSubjects(root, from) {
|
|
81
|
+
if (!OBJECT_ID.test(String(from))) throw new Error('a recorded revision is not an object id');
|
|
82
|
+
try { return git(root, ['log', '--reverse', '--format=%s', `${from}..HEAD`]).split('\n').filter(Boolean); } catch { return []; }
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function resolveRef(root, ref) {
|
|
86
|
+
return git(root, ['rev-parse', '--verify', '--end-of-options', `${ref}^{commit}`]).trim();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function snapshotTree(root) {
|
|
90
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'somi-tree-'));
|
|
91
|
+
const index = path.join(dir, 'index');
|
|
92
|
+
const env = { ...process.env, GIT_INDEX_FILE: index, GIT_OPTIONAL_LOCKS: '0' };
|
|
93
|
+
try {
|
|
94
|
+
const real = git(root, ['rev-parse', '--path-format=absolute', '--git-path', 'index']).trim();
|
|
95
|
+
// The copy keeps the original's times. A newer index would make a same-size edit made in the same second look clean.
|
|
96
|
+
if (fs.existsSync(real)) {
|
|
97
|
+
fs.copyFileSync(real, index);
|
|
98
|
+
const st = fs.statSync(real);
|
|
99
|
+
fs.utimesSync(index, st.atime, st.mtime);
|
|
100
|
+
}
|
|
101
|
+
const off = noFilters(root);
|
|
102
|
+
git(root, [...off, 'add', '-A', '--', '.'], { env });
|
|
103
|
+
// The audit log grows on every tool call, so in a repository that does not ignore it, keeping it would make every tree new.
|
|
104
|
+
git(root, [...off, 'rm', '-r', '-q', '--cached', '--ignore-unmatch', '--', ':(glob)**/.somi/state/**', ':(glob)**/.somi/audit.log'], { env });
|
|
105
|
+
return git(root, [...off, 'write-tree'], { env }).trim();
|
|
106
|
+
} finally { fs.rmSync(dir, { recursive: true, force: true }); }
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const OBJECT_ID = /^[0-9a-f]{40,64}$/;
|
|
110
|
+
|
|
111
|
+
const stripPrefix = (name, prefix) => name.replace(new RegExp(`^"?${prefix}/`), '').replace(/"$/, '');
|
|
112
|
+
|
|
113
|
+
// A file header names the file, from its old side and then its new one. /dev/null on either side leaves the name the other gave.
|
|
114
|
+
function headerLine(state, line) {
|
|
115
|
+
for (const [marker, prefix] of [['--- ', 'a'], ['+++ ', 'b']]) {
|
|
116
|
+
if (line.startsWith(marker) && line !== `${marker}/dev/null`) state.file = stripPrefix(line.slice(4), prefix);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// [{ file, sign: '+'|'-', text }]. Only the file header needs care: a removed line starting `-- ` must not read as one, so headers
|
|
121
|
+
// are read only before a file's first hunk.
|
|
122
|
+
export function parsePatch(patch) {
|
|
123
|
+
const out = [];
|
|
124
|
+
const state = { file: null, inHunk: false };
|
|
125
|
+
for (const line of patch.split('\n')) {
|
|
126
|
+
if (line.startsWith('diff --git ')) Object.assign(state, { file: null, inHunk: false });
|
|
127
|
+
else if (line.startsWith('@@')) state.inHunk = true;
|
|
128
|
+
else if (!state.inHunk) headerLine(state, line);
|
|
129
|
+
else if (state.file !== null && (line[0] === '+' || line[0] === '-')) out.push({ file: state.file, sign: line[0], text: line.slice(1) });
|
|
130
|
+
}
|
|
131
|
+
return out;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Per-file rows plus the patch's added and removed lines. A diff too large to read returns `unreadable`, which signals reads as
|
|
135
|
+
// "everything fired": a change that cannot be measured must not look small.
|
|
136
|
+
export function readDiff(root, from, to) {
|
|
137
|
+
if (!OBJECT_ID.test(from) || !OBJECT_ID.test(to)) throw new Error('a recorded revision is not an object id');
|
|
138
|
+
try {
|
|
139
|
+
const status = git(root, ['diff', ...DIFF, '--name-status', '-z', from, to]).split('\0').filter(Boolean);
|
|
140
|
+
const letters = new Map();
|
|
141
|
+
for (let i = 0; i + 1 < status.length; i += 2) letters.set(status[i + 1], status[i]);
|
|
142
|
+
const rows = git(root, ['diff', ...DIFF, '--numstat', '-z', from, to]).split('\0').filter(Boolean).map((t) => {
|
|
143
|
+
const [added, deleted, ...name] = t.split('\t');
|
|
144
|
+
const file = name.join('\t');
|
|
145
|
+
return { file, added: added === '-' ? 0 : Number(added), deleted: deleted === '-' ? 0 : Number(deleted), status: letters.get(file) ?? 'M' };
|
|
146
|
+
});
|
|
147
|
+
return { rows, lines: parsePatch(git(root, ['diff', ...DIFF, '-U0', from, to])), unreadable: false };
|
|
148
|
+
} catch (e) {
|
|
149
|
+
if (e.code === 'ENOBUFS') return { rows: [], lines: [], unreadable: true };
|
|
150
|
+
throw e;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// What a diff added, per file: { file → { status, added: [[first, last], ...] } }, with line numbers in the new version. The quality
|
|
155
|
+
// gate scores only the functions these lines touch.
|
|
156
|
+
function changedFiles(root, from, to) {
|
|
157
|
+
const out = new Map();
|
|
158
|
+
const status = git(root, ['diff', ...DIFF, '--name-status', '-z', from, to]).split('\0').filter(Boolean);
|
|
159
|
+
for (let i = 0; i + 1 < status.length; i += 2) out.set(status[i + 1], { status: status[i], added: [] });
|
|
160
|
+
return out;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const HUNK = /^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@/;
|
|
164
|
+
|
|
165
|
+
// A hunk header's new side: its first line and how many lines it holds there. A hunk that only removes holds none.
|
|
166
|
+
function addHunk(entry, line) {
|
|
167
|
+
const hunk = HUNK.exec(line);
|
|
168
|
+
if (!hunk || !entry) return;
|
|
169
|
+
const first = Number(hunk[1]);
|
|
170
|
+
const count = hunk[2] === undefined ? 1 : Number(hunk[2]);
|
|
171
|
+
if (count > 0) entry.added.push([first, first + count - 1]);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function addedRanges(root, from, to) {
|
|
175
|
+
if (!OBJECT_ID.test(from) || !OBJECT_ID.test(to)) throw new Error('a recorded revision is not an object id');
|
|
176
|
+
const out = changedFiles(root, from, to);
|
|
177
|
+
let file = null;
|
|
178
|
+
for (const line of git(root, ['diff', ...DIFF, '-U0', from, to]).split('\n')) {
|
|
179
|
+
if (line.startsWith('+++ ')) file = line === '+++ /dev/null' ? null : stripPrefix(line.slice(4), 'b');
|
|
180
|
+
else addHunk(file === null ? null : out.get(file), line);
|
|
181
|
+
}
|
|
182
|
+
return out;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Every file path in a commit or tree. */
|
|
186
|
+
export function listFiles(root, rev) {
|
|
187
|
+
if (!OBJECT_ID.test(rev)) throw new Error('a recorded revision is not an object id');
|
|
188
|
+
return git(root, ['ls-tree', '-r', '--name-only', '-z', rev]).split('\0').filter(Boolean);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** A file's text at a commit or tree, or null when it is not there. */
|
|
192
|
+
export function fileAt(root, rev, file) {
|
|
193
|
+
if (!OBJECT_ID.test(rev)) throw new Error('a recorded revision is not an object id');
|
|
194
|
+
try { return git(root, ['cat-file', '-p', `${rev}:${file}`]); } catch { return null; }
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// This string reaches an agent as a command, and its ids come from a state file, so anything but an object id is refused.
|
|
198
|
+
export function reviewDiffCommand(from, to) {
|
|
199
|
+
if (!OBJECT_ID.test(String(from)) || !OBJECT_ID.test(String(to))) throw new Error('a recorded revision is not an object id');
|
|
200
|
+
return `git diff --no-ext-diff --no-textconv ${from} ${to}`;
|
|
201
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// init.mjs: writes the extension that registers SoMi's staged workflows with Copilot CLI, which loads a workflow only from an extension.
|
|
2
|
+
// Copilot CLI runs the plugin's own hooks, so nothing else is written, and the Claude Code plugin install needs none of this.
|
|
3
|
+
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { pathToFileURL } from 'node:url';
|
|
7
|
+
|
|
8
|
+
// Copilot loads a workflow only from an extension. This one is a few lines that load SoMi's own module from the plugin.
|
|
9
|
+
export function copilotExtension(pluginRoot) {
|
|
10
|
+
const lib = pathToFileURL(path.join(pluginRoot, 'scripts', 'lib', 'copilot-workflow.mjs')).href;
|
|
11
|
+
return `// Written by somi init: registers SoMi's staged workflows with Copilot CLI. Remove this folder to turn them off.\nimport { defineWorkflow, joinSession } from '@github/copilot-sdk/extension';\n\nconst { registerCopilotWorkflows } = await import(${JSON.stringify(lib)});\nawait registerCopilotWorkflows({ defineWorkflow, joinSession });\n`;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function writeCopilotExtension(root, pluginRoot) {
|
|
15
|
+
return writeOnce(path.join(root, '.github', 'extensions', 'somi', 'extension.mjs'), copilotExtension(pluginRoot), 'extension.mjs');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function writeOnce(file, text, label) {
|
|
19
|
+
if (fs.existsSync(file) && fs.readFileSync(file, 'utf8') !== text) return { written: false, file, reason: `a different ${label} is already there; remove it first` };
|
|
20
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
21
|
+
fs.writeFileSync(file, text);
|
|
22
|
+
return { written: true, file };
|
|
23
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// ledger.mjs: the small decision record that survives compaction. Compaction drops rules and scope exclusions first, and what gets
|
|
2
|
+
// re-injected survives, so this one file is put back at every session start and comes back with every route. It has a hard size limit,
|
|
3
|
+
// because a state file nobody can afford to read protects nothing. Writes go through here only.
|
|
4
|
+
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { StateError, statePaths, writeStateFile } from './state.mjs';
|
|
8
|
+
|
|
9
|
+
export const MAX_LINES = 40;
|
|
10
|
+
export const MAX_BYTES = 6144;
|
|
11
|
+
const KINDS = Object.freeze(['decision', 'constraint', 'pointer']);
|
|
12
|
+
|
|
13
|
+
const file = (root, env) => path.join(statePaths(root, env).dir, 'ledger.md');
|
|
14
|
+
const oneLine = (s) => String(s ?? '').replace(/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]+/gu, ' ').trim();
|
|
15
|
+
|
|
16
|
+
export function readLedger(root, env = process.env) {
|
|
17
|
+
try { return fs.readFileSync(file(root, env), 'utf8').trim(); } catch (e) { if (e.code === 'ENOENT') return ''; throw e; }
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// The ledger belongs to one piece of work. Left in place, old decisions would read as if they still bound the next.
|
|
21
|
+
export function clearLedger(root, env = process.env) {
|
|
22
|
+
fs.rmSync(file(root, env), { force: true });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function addToLedger(root, { kind, text }, env = process.env) {
|
|
26
|
+
if (!KINDS.includes(kind)) throw new StateError(`a ledger entry is one of: ${KINDS.join(', ')}`);
|
|
27
|
+
const line = oneLine(text);
|
|
28
|
+
if (line === '') throw new StateError('a ledger entry needs text');
|
|
29
|
+
const current = readLedger(root, env);
|
|
30
|
+
const entry = `- ${kind}: ${line}`;
|
|
31
|
+
if (current.split('\n').includes(entry)) return { lines: current.split('\n').length, added: false };
|
|
32
|
+
const kept = kind === 'pointer' ? current.split('\n').filter((l) => l !== '' && !l.startsWith('- pointer:')) : current.split('\n').filter(Boolean);
|
|
33
|
+
const next = [...kept, entry];
|
|
34
|
+
const text2 = `${next.join('\n')}\n`;
|
|
35
|
+
if (next.length > MAX_LINES || Buffer.byteLength(text2) > MAX_BYTES) throw new StateError(`the ledger is limited to ${MAX_LINES} lines and ${MAX_BYTES} bytes; state fewer, shorter decisions`);
|
|
36
|
+
writeStateFile(root, file(root, env), text2, env);
|
|
37
|
+
return { lines: next.length, added: true };
|
|
38
|
+
}
|