raga-cli 0.0.0-stage → 0.8.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/CHANGELOG.md +103 -0
- package/LICENSE +21 -0
- package/README.md +139 -2
- package/bundled-skills/AGENTS.md +5 -0
- package/bundled-skills/README.md +25 -0
- package/bundled-skills/agents/comment-sicko.json +9 -0
- package/bundled-skills/agents/comment-sicko.md +28 -0
- package/bundled-skills/agents/model-roles.json +41 -0
- package/bundled-skills/agents/poteto-agent.json +9 -0
- package/bundled-skills/agents/poteto-agent.md +4 -0
- package/bundled-skills/agents/worker.json +8 -0
- package/bundled-skills/agents/worker.md +1 -0
- package/bundled-skills/bundle.json +1448 -0
- package/bundled-skills/dependencies.json +40 -0
- package/bundled-skills/docs/guide/01-setup.md +3 -0
- package/bundled-skills/docs/guide/02-peak.md +135 -0
- package/bundled-skills/docs/guide/03-understand.md +79 -0
- package/bundled-skills/docs/guide/04-design.md +133 -0
- package/bundled-skills/docs/guide/05-build-and-clean.md +83 -0
- package/bundled-skills/docs/guide/06-verify-and-ship.md +166 -0
- package/bundled-skills/docs/guide/07-overnight.md +118 -0
- package/bundled-skills/docs/guide/08-principles.md +72 -0
- package/bundled-skills/docs/guide/09-make-it-yours.md +96 -0
- package/bundled-skills/docs/guide/10-recipes-and-pitfalls.md +180 -0
- package/bundled-skills/docs/guide/README.md +38 -0
- package/bundled-skills/docs/guide/images/design.jpg +0 -0
- package/bundled-skills/docs/guide/images/overnight.jpg +0 -0
- package/bundled-skills/docs/guide/images/recipes.jpg +0 -0
- package/bundled-skills/docs/guide/images/router.jpg +0 -0
- package/bundled-skills/docs/guide/images/understanding.jpg +0 -0
- package/bundled-skills/docs/guide/images/verification.jpg +0 -0
- package/bundled-skills/licenses/commander +22 -0
- package/bundled-skills/licenses/cursor-team-kit +21 -0
- package/bundled-skills/licenses/no-mistakes +21 -0
- package/bundled-skills/licenses/pstack +21 -0
- package/bundled-skills/skills/peak/SKILL.md +184 -0
- package/bundled-skills/skills/peak/playbooks/authoring-a-skill.md +12 -0
- package/bundled-skills/skills/peak/playbooks/autonomous-run.md +13 -0
- package/bundled-skills/skills/peak/playbooks/autopilot-full.md +25 -0
- package/bundled-skills/skills/peak/playbooks/autopilot-stack.md +12 -0
- package/bundled-skills/skills/peak/playbooks/babysit.md +18 -0
- package/bundled-skills/skills/peak/playbooks/bug-fix.md +15 -0
- package/bundled-skills/skills/peak/playbooks/eval.md +25 -0
- package/bundled-skills/skills/peak/playbooks/feature.md +21 -0
- package/bundled-skills/skills/peak/playbooks/hillclimb.md +21 -0
- package/bundled-skills/skills/peak/playbooks/investigation.md +14 -0
- package/bundled-skills/skills/peak/playbooks/multi-phase-plan.md +155 -0
- package/bundled-skills/skills/peak/playbooks/opening-a-pr.md +34 -0
- package/bundled-skills/skills/peak/playbooks/orchestrate.md +112 -0
- package/bundled-skills/skills/peak/playbooks/pause-safely.md +10 -0
- package/bundled-skills/skills/peak/playbooks/perf-issue.md +25 -0
- package/bundled-skills/skills/peak/playbooks/prototype.md +14 -0
- package/bundled-skills/skills/peak/playbooks/refactoring.md +16 -0
- package/bundled-skills/skills/peak/playbooks/runtime-forensics.md +11 -0
- package/bundled-skills/skills/peak/playbooks/session-pickup.md +11 -0
- package/bundled-skills/skills/peak/playbooks/shipping.md +12 -0
- package/bundled-skills/skills/peak/playbooks/trace-forensics.md +14 -0
- package/bundled-skills/skills/peak/playbooks/visual-parity.md +11 -0
- package/bundled-skills/skills/peak/playbooks/worktree-cleanup.md +6 -0
- package/bundled-skills/skills/peak/references/architect/SKILL.md +81 -0
- package/bundled-skills/skills/peak/references/architect/references/design-red-flags.md +57 -0
- package/bundled-skills/skills/peak/references/architect/references/rationale-template.md +35 -0
- package/bundled-skills/skills/peak/references/architect/references/runner-prompt.md +20 -0
- package/bundled-skills/skills/peak/references/arena/SKILL.md +50 -0
- package/bundled-skills/skills/peak/references/automate-me/SKILL.md +106 -0
- package/bundled-skills/skills/peak/references/benchmark-checklist/SKILL.md +41 -0
- package/bundled-skills/skills/peak/references/blast-radius/SKILL.md +52 -0
- package/bundled-skills/skills/peak/references/bro/SKILL.md +9 -0
- package/bundled-skills/skills/peak/references/control-cli/SKILL.md +111 -0
- package/bundled-skills/skills/peak/references/control-ui/SKILL.md +111 -0
- package/bundled-skills/skills/peak/references/correct/SKILL.md +34 -0
- package/bundled-skills/skills/peak/references/create-formal-verification-skill/SKILL.md +43 -0
- package/bundled-skills/skills/peak/references/create-skill/SKILL.md +14 -0
- package/bundled-skills/skills/peak/references/create-verification-skill/SKILL.md +46 -0
- package/bundled-skills/skills/peak/references/create-verification-skill/references/feature-map-example/README.md +47 -0
- package/bundled-skills/skills/peak/references/create-verification-skill/references/feature-map-example/create-note.md +39 -0
- package/bundled-skills/skills/peak/references/create-verification-skill/references/feature-map-example/search.md +45 -0
- package/bundled-skills/skills/peak/references/deslop/SKILL.md +24 -0
- package/bundled-skills/skills/peak/references/figure-it-out/SKILL.md +54 -0
- package/bundled-skills/skills/peak/references/how/SKILL.md +38 -0
- package/bundled-skills/skills/peak/references/how/references/explainer-prompt.md +55 -0
- package/bundled-skills/skills/peak/references/how/references/explorer-prompt.md +35 -0
- package/bundled-skills/skills/peak/references/in-your-own-words/SKILL.md +9 -0
- package/bundled-skills/skills/peak/references/interrogate/SKILL.md +76 -0
- package/bundled-skills/skills/peak/references/interrogate/references/code-quality-review.md +47 -0
- package/bundled-skills/skills/peak/references/interrogate/references/lead-judgment.md +39 -0
- package/bundled-skills/skills/peak/references/interrogate/references/reviewer-prompt.md +62 -0
- package/bundled-skills/skills/peak/references/interrogate/references/rubric.md +77 -0
- package/bundled-skills/skills/peak/references/ketchup/SKILL.md +45 -0
- package/bundled-skills/skills/peak/references/maintain-formal-verification-skill/SKILL.md +60 -0
- package/bundled-skills/skills/peak/references/maintain-verification-skill/SKILL.md +41 -0
- package/bundled-skills/skills/peak/references/no-comments/SKILL.md +26 -0
- package/bundled-skills/skills/peak/references/no-mistakes/SKILL.md +20 -0
- package/bundled-skills/skills/peak/references/no-mistakes/upstream/SKILL.md +394 -0
- package/bundled-skills/skills/peak/references/peak-setup/SKILL.md +18 -0
- package/bundled-skills/skills/peak/references/poteto-help/SKILL.md +16 -0
- package/bundled-skills/skills/peak/references/poteto-help/references/prompting.md +51 -0
- package/bundled-skills/skills/peak/references/poteto-help/references/recipes.md +51 -0
- package/bundled-skills/skills/peak/references/principle-attack-the-premise/SKILL.md +23 -0
- package/bundled-skills/skills/peak/references/principle-boundary-discipline/SKILL.md +36 -0
- package/bundled-skills/skills/peak/references/principle-build-the-lever/SKILL.md +25 -0
- package/bundled-skills/skills/peak/references/principle-encode-lessons-in-structure/SKILL.md +13 -0
- package/bundled-skills/skills/peak/references/principle-exhaust-the-design-space/SKILL.md +11 -0
- package/bundled-skills/skills/peak/references/principle-experience-first/SKILL.md +21 -0
- package/bundled-skills/skills/peak/references/principle-explain-the-number/SKILL.md +19 -0
- package/bundled-skills/skills/peak/references/principle-fix-root-causes/SKILL.md +23 -0
- package/bundled-skills/skills/peak/references/principle-foundational-thinking/SKILL.md +23 -0
- package/bundled-skills/skills/peak/references/principle-guard-the-context-window/SKILL.md +14 -0
- package/bundled-skills/skills/peak/references/principle-laziness-protocol/SKILL.md +12 -0
- package/bundled-skills/skills/peak/references/principle-make-operations-idempotent/SKILL.md +24 -0
- package/bundled-skills/skills/peak/references/principle-migrate-callers-then-delete-legacy-apis/SKILL.md +16 -0
- package/bundled-skills/skills/peak/references/principle-minimize-reader-load/SKILL.md +20 -0
- package/bundled-skills/skills/peak/references/principle-model-the-domain/SKILL.md +26 -0
- package/bundled-skills/skills/peak/references/principle-never-block-on-the-human/SKILL.md +17 -0
- package/bundled-skills/skills/peak/references/principle-outcome-oriented-execution/SKILL.md +23 -0
- package/bundled-skills/skills/peak/references/principle-prove-it-works/SKILL.md +24 -0
- package/bundled-skills/skills/peak/references/principle-redesign-from-first-principles/SKILL.md +18 -0
- package/bundled-skills/skills/peak/references/principle-separate-before-serializing-shared-state/SKILL.md +18 -0
- package/bundled-skills/skills/peak/references/principle-sequence-verifiable-units/SKILL.md +19 -0
- package/bundled-skills/skills/peak/references/principle-subtract-before-you-add/SKILL.md +20 -0
- package/bundled-skills/skills/peak/references/principle-test-behavior-not-implementation/SKILL.md +22 -0
- package/bundled-skills/skills/peak/references/principle-type-system-discipline/SKILL.md +15 -0
- package/bundled-skills/skills/peak/references/raga-runtime/SKILL.md +37 -0
- package/bundled-skills/skills/peak/references/raga-runtime/managed-tools.mjs +34 -0
- package/bundled-skills/skills/peak/references/raga-runtime/raga_runtime.py +44 -0
- package/bundled-skills/skills/peak/references/recall/SKILL.md +37 -0
- package/bundled-skills/skills/peak/references/reflect/SKILL.md +63 -0
- package/bundled-skills/skills/peak/references/reflect/references/divergent-reviewer.md +38 -0
- package/bundled-skills/skills/peak/references/reflect/references/judgment-reviewer.md +37 -0
- package/bundled-skills/skills/peak/references/reflect/references/synthesizer.md +56 -0
- package/bundled-skills/skills/peak/references/reflect/references/tooling-reviewer.md +48 -0
- package/bundled-skills/skills/peak/references/reviewer-triage.md +142 -0
- package/bundled-skills/skills/peak/references/sharpen/SKILL.md +18 -0
- package/bundled-skills/skills/peak/references/show-me-your-work/SKILL.md +84 -0
- package/bundled-skills/skills/peak/references/show-me-your-work/references/decision-log-template.tsv +1 -0
- package/bundled-skills/skills/peak/references/show-me-your-work/scripts/log.sh +42 -0
- package/bundled-skills/skills/peak/references/statechart/SKILL.md +38 -0
- package/bundled-skills/skills/peak/references/statechart/scripts/chart-to-tla.mjs +236 -0
- package/bundled-skills/skills/peak/references/statechart/scripts/compare-charts.mjs +104 -0
- package/bundled-skills/skills/peak/references/statechart/scripts/lib.mjs +725 -0
- package/bundled-skills/skills/peak/references/statechart/scripts/model/OutputFolder.cfg +6 -0
- package/bundled-skills/skills/peak/references/statechart/scripts/model/OutputFolder.map.mjs +106 -0
- package/bundled-skills/skills/peak/references/statechart/scripts/model/OutputFolder.tla +176 -0
- package/bundled-skills/skills/peak/references/statechart/scripts/statechart.mjs +749 -0
- package/bundled-skills/skills/peak/references/statechart/scripts/test/statechart.test.mjs +2790 -0
- package/bundled-skills/skills/peak/references/statechart/scripts/test/sync.mmd +19 -0
- package/bundled-skills/skills/peak/references/statechart/scripts/test/upload.mmd +16 -0
- package/bundled-skills/skills/peak/references/statechart/scripts/tlc-to-chart.mjs +1347 -0
- package/bundled-skills/skills/peak/references/swarm/SKILL.md +43 -0
- package/bundled-skills/skills/peak/references/tdd/SKILL.md +44 -0
- package/bundled-skills/skills/peak/references/teach/SKILL.md +23 -0
- package/bundled-skills/skills/peak/references/technical-writing/SKILL.md +108 -0
- package/bundled-skills/skills/peak/references/typescript-best-practices/SKILL.md +33 -0
- package/bundled-skills/skills/peak/references/typescript-best-practices/references/patterns.md +328 -0
- package/bundled-skills/skills/peak/references/unslop/SKILL.md +64 -0
- package/bundled-skills/skills/peak/references/verify-this/SKILL.md +76 -0
- package/bundled-skills/skills/peak/references/why/SKILL.md +100 -0
- package/bundled-skills/skills/peak/references/why/references/epistemics.md +71 -0
- package/bundled-skills/skills/peak/references/why/references/investigator-prompt.md +84 -0
- package/bundled-skills/skills/peak/references/why/references/source-playbook.md +17 -0
- package/bundled-skills/skills/peak/references/why/references/sources/code-archaeology.md +51 -0
- package/bundled-skills/skills/peak/references/why/references/sources/databricks.md +70 -0
- package/bundled-skills/skills/peak/references/why/references/sources/datadog.md +97 -0
- package/bundled-skills/skills/peak/references/why/references/sources/incident-postmortem.md +5 -0
- package/bundled-skills/skills/peak/references/why/references/sources/linear.md +48 -0
- package/bundled-skills/skills/peak/references/why/references/sources/notion.md +55 -0
- package/bundled-skills/skills/peak/references/why/references/sources/sentry.md +66 -0
- package/bundled-skills/skills/peak/references/why/references/sources/slack.md +17 -0
- package/bundled-skills/skills/peak/references/why/references/synthesizer-prompt.md +129 -0
- package/bundled-skills/skills/peak/scripts/check-plan.mjs +205 -0
- package/bundled-skills/skills/peak/scripts/check-plan.test.ts +96 -0
- package/bundled-skills/skills/peak/scripts/orch/orch.test.ts +761 -0
- package/bundled-skills/skills/peak/scripts/orch/orch.ts +588 -0
- package/bundled-skills/skills/peak/scripts/orch/store.ts +1676 -0
- package/bundled-skills/skills/peak/scripts/vendor/commander/LICENSE +22 -0
- package/bundled-skills/skills/peak/scripts/vendor/commander/esm.mjs +16 -0
- package/bundled-skills/skills/peak/scripts/vendor/commander/index.js +24 -0
- package/bundled-skills/skills/peak/scripts/vendor/commander/lib/argument.js +149 -0
- package/bundled-skills/skills/peak/scripts/vendor/commander/lib/command.js +2778 -0
- package/bundled-skills/skills/peak/scripts/vendor/commander/lib/error.js +39 -0
- package/bundled-skills/skills/peak/scripts/vendor/commander/lib/help.js +747 -0
- package/bundled-skills/skills/peak/scripts/vendor/commander/lib/option.js +379 -0
- package/bundled-skills/skills/peak/scripts/vendor/commander/lib/suggestSimilar.js +101 -0
- package/bundled-skills/skills/peak/scripts/vendor/commander/package.json +1 -0
- package/bundled-skills/skills/peak/scripts/vendor/commander/typings/esm.d.mts +3 -0
- package/bundled-skills/skills/peak/scripts/vendor/commander/typings/index.d.ts +1113 -0
- package/bundled-skills/skills/peak/scripts/watch-pr/cli.test.ts +224 -0
- package/bundled-skills/skills/peak/scripts/watch-pr/cli.ts +223 -0
- package/bundled-skills/skills/peak/scripts/watch-pr/fakes.test-helper.ts +129 -0
- package/bundled-skills/skills/peak/scripts/watch-pr/github.test.ts +436 -0
- package/bundled-skills/skills/peak/scripts/watch-pr/github.ts +718 -0
- package/bundled-skills/skills/peak/scripts/watch-pr/policy.test.ts +420 -0
- package/bundled-skills/skills/peak/scripts/watch-pr/policy.ts +836 -0
- package/bundled-skills/skills/peak/scripts/watch-pr/render.ts +169 -0
- package/bundled-skills/skills/peak/scripts/watch-pr/tsconfig.json +13 -0
- package/bundled-skills/skills/peak/scripts/watch-pr/types.compile.ts +93 -0
- package/bundled-skills/skills/peak/scripts/watch-pr/types.ts +413 -0
- package/bundled-skills/skills/peak/scripts/watch-pr/watch-pr +4 -0
- package/bundled-skills/skills/peak/scripts/worktree-audit.sh +4 -0
- package/dist/bundle/chunks/anthropic-messages-BMDYDGHW.js +6 -0
- package/dist/bundle/chunks/anthropic.js +75 -0
- package/dist/bundle/chunks/azure-openai-responses-Q7EZTEHK.js +2 -0
- package/dist/bundle/chunks/bedrock-converse-stream.js +86 -0
- package/dist/bundle/chunks/chunk-3EGDWOKT.js +2 -0
- package/dist/bundle/chunks/chunk-3V45WARH.js +7 -0
- package/dist/bundle/chunks/chunk-5AGIVGSV.js +6 -0
- package/dist/bundle/chunks/chunk-6QGV3IWD.js +6 -0
- package/dist/bundle/chunks/chunk-7CBJINYJ.js +20 -0
- package/dist/bundle/chunks/chunk-7DDKXS2Q.js +2 -0
- package/dist/bundle/chunks/chunk-7ZC4UXSL.js +2 -0
- package/dist/bundle/chunks/chunk-AI2NMHE7.js +1567 -0
- package/dist/bundle/chunks/chunk-C4IJNE7U.js +2 -0
- package/dist/bundle/chunks/chunk-CF5GWZHW.js +31 -0
- package/dist/bundle/chunks/chunk-G54UBZTF.js +44 -0
- package/dist/bundle/chunks/chunk-H76KZMOI.js +2 -0
- package/dist/bundle/chunks/chunk-IOPE2TJ4.js +131 -0
- package/dist/bundle/chunks/chunk-IXDQLPKS.js +11 -0
- package/dist/bundle/chunks/chunk-J22MF7YW.js +64 -0
- package/dist/bundle/chunks/chunk-JLV25LHE.js +2 -0
- package/dist/bundle/chunks/chunk-JXWJOIH4.js +2 -0
- package/dist/bundle/chunks/chunk-KNY3PXQI.js +2 -0
- package/dist/bundle/chunks/chunk-L2ZPNLYD.js +2 -0
- package/dist/bundle/chunks/chunk-LPXNMA2W.js +2 -0
- package/dist/bundle/chunks/chunk-LVVZS2NO.js +12 -0
- package/dist/bundle/chunks/chunk-LX24DVQ5.js +2 -0
- package/dist/bundle/chunks/chunk-P2QCWBFM.js +9 -0
- package/dist/bundle/chunks/chunk-P7FPUEYA.js +2 -0
- package/dist/bundle/chunks/chunk-PGXDEOVV.js +2 -0
- package/dist/bundle/chunks/chunk-PJACZCIR.js +2 -0
- package/dist/bundle/chunks/chunk-PMRZO46Y.js +2 -0
- package/dist/bundle/chunks/chunk-PRRNXB7S.js +2 -0
- package/dist/bundle/chunks/chunk-Q4U25BSY.js +2 -0
- package/dist/bundle/chunks/chunk-RDZVAGPR.js +2 -0
- package/dist/bundle/chunks/chunk-RFPFZTK2.js +7 -0
- package/dist/bundle/chunks/chunk-RP2WKNT7.js +4 -0
- package/dist/bundle/chunks/chunk-TEPMHNKQ.js +2 -0
- package/dist/bundle/chunks/chunk-TMTOQ7H7.js +2 -0
- package/dist/bundle/chunks/chunk-UDT647VB.js +82 -0
- package/dist/bundle/chunks/chunk-UKVNB6C4.js +2 -0
- package/dist/bundle/chunks/chunk-USJZMAIR.js +2 -0
- package/dist/bundle/chunks/chunk-UTB4DTYQ.js +2 -0
- package/dist/bundle/chunks/chunk-WJGLPWUE.js +16 -0
- package/dist/bundle/chunks/chunk-YMZUNB25.js +2 -0
- package/dist/bundle/chunks/cli-4P6FVVLT.js +51 -0
- package/dist/bundle/chunks/cloudflare-workers-ai-system-one-S6CT2FXS.js +2 -0
- package/dist/bundle/chunks/codemode-worker.js +478 -0
- package/dist/bundle/chunks/easter-egg-3d-65VIC4G2.js +2 -0
- package/dist/bundle/chunks/execute-3H5WKMA3.js +505 -0
- package/dist/bundle/chunks/github-copilot.js +2 -0
- package/dist/bundle/chunks/google-generative-ai-35NZKG6S.js +2 -0
- package/dist/bundle/chunks/google-vertex-P33AHYYX.js +2 -0
- package/dist/bundle/chunks/https-proxy-agent-LVOO5TPL.js +13 -0
- package/dist/bundle/chunks/image-resize-worker.js +2 -0
- package/dist/bundle/chunks/jiti-loader-GL4HJFAD.js +21 -0
- package/dist/bundle/chunks/jiti-static-loader-2RCDI6B4.js +2 -0
- package/dist/bundle/chunks/kimi-coding.js +2 -0
- package/dist/bundle/chunks/lib-4AVRLBHM.js +9 -0
- package/dist/bundle/chunks/llama-cpp-classify-U4EH6TAM.js +22 -0
- package/dist/bundle/chunks/meta.js +2 -0
- package/dist/bundle/chunks/mistral-conversations-J62DPS2P.js +5 -0
- package/dist/bundle/chunks/multipart-parser-FMGQ7342.js +3 -0
- package/dist/bundle/chunks/node-AUOGOBCN.js +2 -0
- package/dist/bundle/chunks/node-KCMANYC2.js +16 -0
- package/dist/bundle/chunks/openai-chatgpt.js +75 -0
- package/dist/bundle/chunks/openai-codex-responses-4HXATL2M.js +10 -0
- package/dist/bundle/chunks/openai-codex.js +75 -0
- package/dist/bundle/chunks/openai-completions-75YYY35N.js +7 -0
- package/dist/bundle/chunks/openai-decisions-HEBEVGA2.js +5 -0
- package/dist/bundle/chunks/openai-responses-UWNAKTBV.js +4 -0
- package/dist/bundle/chunks/openrouter-images-HVOPXKHS.js +2 -0
- package/dist/bundle/chunks/openrouter.js +75 -0
- package/dist/bundle/chunks/pi-messages-DG7CALOV.js +8 -0
- package/dist/bundle/chunks/radius.js +75 -0
- package/dist/bundle/chunks/runtime-435R6IKY.js +2 -0
- package/dist/bundle/chunks/src-QKGKDFSU.js +4 -0
- package/dist/bundle/chunks/typesafe-system-one-24HEGHNN.js +2 -0
- package/dist/bundle/chunks/virtual-modules-U3JBUDP7.js +2 -0
- package/dist/bundle/chunks/xai.js +2 -0
- package/dist/bundle/cli-runtime.js +3 -0
- package/dist/bundle/cli.js +5 -0
- package/dist/bundle/index.js +2 -0
- package/dist/bundle/raga-runtime.js +3 -0
- package/dist/bundle/raga.js +5 -0
- package/dist/bundle/rpc-entry.js +3 -0
- package/dist/core/export-html/template.css +1085 -0
- package/dist/core/export-html/template.html +56 -0
- package/dist/core/export-html/template.js +2044 -0
- package/dist/core/export-html/vendor/highlight.min.js +1213 -0
- package/dist/core/export-html/vendor/marked-cjk-friendly.min.js +6 -0
- package/dist/core/export-html/vendor/marked.min.js +79 -0
- package/dist/modes/interactive/assets/clankolas.png +0 -0
- package/dist/modes/interactive/theme/dark.json +78 -0
- package/dist/modes/interactive/theme/light.json +78 -0
- package/docs/cli-integration.md +106 -0
- package/docs/cli.md +337 -0
- package/docs/codemode.md +230 -0
- package/docs/compaction.md +463 -0
- package/docs/configuration.md +62 -0
- package/docs/containerization.md +183 -0
- package/docs/custom-provider.md +227 -0
- package/docs/docs.json +220 -0
- package/docs/environment-variables.md +101 -0
- package/docs/extensions.md +400 -0
- package/docs/how-pi-works.md +49 -0
- package/docs/images/doom-extension.png +0 -0
- package/docs/images/exy.png +0 -0
- package/docs/images/interactive-mode.png +0 -0
- package/docs/images/tree-view.png +0 -0
- package/docs/index.md +39 -0
- package/docs/json.md +226 -0
- package/docs/keybindings.md +195 -0
- package/docs/llama-cpp.md +121 -0
- package/docs/mcp.md +272 -0
- package/docs/message-types.md +279 -0
- package/docs/models-configuration.md +196 -0
- package/docs/models.md +225 -0
- package/docs/nvidia-rtx-llama-cpp.md +96 -0
- package/docs/packages.md +129 -0
- package/docs/prompt-templates.md +59 -0
- package/docs/providers.md +247 -0
- package/docs/quickstart.md +136 -0
- package/docs/rpc-commands.md +860 -0
- package/docs/rpc-extension-ui.md +200 -0
- package/docs/rpc.md +193 -0
- package/docs/sdk.md +148 -0
- package/docs/security.md +99 -0
- package/docs/session-format.md +293 -0
- package/docs/sessions.md +66 -0
- package/docs/settings.md +184 -0
- package/docs/shell-aliases.md +93 -0
- package/docs/skills.md +93 -0
- package/docs/slash-commands.md +61 -0
- package/docs/terminal-setup.md +233 -0
- package/docs/termux.md +117 -0
- package/docs/themes.md +138 -0
- package/docs/tmux.md +55 -0
- package/docs/tui.md +195 -0
- package/docs/usage.md +94 -0
- package/docs/virtual-models.md +114 -0
- package/docs/windows.md +81 -0
- package/examples/README.md +36 -0
- package/examples/extensions/README.md +214 -0
- package/examples/extensions/auto-commit-on-exit.ts +49 -0
- package/examples/extensions/bash-spawn-hook.ts +30 -0
- package/examples/extensions/bookmark.ts +50 -0
- package/examples/extensions/border-status-editor.ts +150 -0
- package/examples/extensions/built-in-tool-renderer.ts +225 -0
- package/examples/extensions/claude-rules.ts +86 -0
- package/examples/extensions/commands.ts +72 -0
- package/examples/extensions/confirm-destructive.ts +59 -0
- package/examples/extensions/custom-compaction.ts +117 -0
- package/examples/extensions/custom-footer.ts +64 -0
- package/examples/extensions/custom-header.ts +73 -0
- package/examples/extensions/custom-provider-anthropic/index.ts +617 -0
- package/examples/extensions/custom-provider-anthropic/package-lock.json +24 -0
- package/examples/extensions/custom-provider-anthropic/package.json +19 -0
- package/examples/extensions/custom-provider-gitlab-duo/index.ts +405 -0
- package/examples/extensions/custom-provider-gitlab-duo/package.json +16 -0
- package/examples/extensions/custom-provider-gitlab-duo/test.ts +82 -0
- package/examples/extensions/debug-provider.ts +90 -0
- package/examples/extensions/dirty-repo-guard.ts +56 -0
- package/examples/extensions/doom-overlay/README.md +46 -0
- package/examples/extensions/doom-overlay/doom/build/doom.js +21 -0
- package/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
- package/examples/extensions/doom-overlay/doom/build.sh +152 -0
- package/examples/extensions/doom-overlay/doom/doomgeneric_pi.c +72 -0
- package/examples/extensions/doom-overlay/doom-component.ts +132 -0
- package/examples/extensions/doom-overlay/doom-engine.ts +173 -0
- package/examples/extensions/doom-overlay/doom-keys.ts +104 -0
- package/examples/extensions/doom-overlay/index.ts +74 -0
- package/examples/extensions/doom-overlay/wad-finder.ts +55 -0
- package/examples/extensions/dynamic-resources/SKILL.md +8 -0
- package/examples/extensions/dynamic-resources/dynamic.json +81 -0
- package/examples/extensions/dynamic-resources/dynamic.md +5 -0
- package/examples/extensions/dynamic-resources/index.ts +15 -0
- package/examples/extensions/dynamic-tools.ts +74 -0
- package/examples/extensions/entry-renderer.ts +41 -0
- package/examples/extensions/event-bus.ts +43 -0
- package/examples/extensions/file-trigger.ts +41 -0
- package/examples/extensions/git-checkpoint.ts +53 -0
- package/examples/extensions/git-merge-and-resolve.ts +115 -0
- package/examples/extensions/github-issue-autocomplete.ts +185 -0
- package/examples/extensions/gondolin/index.ts +531 -0
- package/examples/extensions/gondolin/package-lock.json +175 -0
- package/examples/extensions/gondolin/package.json +19 -0
- package/examples/extensions/handoff.ts +190 -0
- package/examples/extensions/hello.ts +26 -0
- package/examples/extensions/hidden-thinking-label.ts +53 -0
- package/examples/extensions/inline-bash.ts +94 -0
- package/examples/extensions/input-transform-streaming.ts +39 -0
- package/examples/extensions/input-transform.ts +43 -0
- package/examples/extensions/interactive-shell.ts +196 -0
- package/examples/extensions/jev-router.ts +113 -0
- package/examples/extensions/mac-system-theme.ts +47 -0
- package/examples/extensions/message-renderer.ts +59 -0
- package/examples/extensions/minimal-mode.ts +353 -0
- package/examples/extensions/modal-editor.ts +85 -0
- package/examples/extensions/model-status.ts +31 -0
- package/examples/extensions/notify.ts +57 -0
- package/examples/extensions/overlay-qa-tests.ts +1450 -0
- package/examples/extensions/overlay-test.ts +153 -0
- package/examples/extensions/permission-gate.ts +34 -0
- package/examples/extensions/pirate.ts +47 -0
- package/examples/extensions/plan-mode/README.md +66 -0
- package/examples/extensions/plan-mode/index.ts +394 -0
- package/examples/extensions/plan-mode/utils.ts +168 -0
- package/examples/extensions/preset.ts +436 -0
- package/examples/extensions/project-trust.ts +64 -0
- package/examples/extensions/prompt-customizer.ts +49 -0
- package/examples/extensions/protected-paths.ts +30 -0
- package/examples/extensions/provider-payload.ts +18 -0
- package/examples/extensions/qna.ts +118 -0
- package/examples/extensions/question.ts +286 -0
- package/examples/extensions/questionnaire.ts +448 -0
- package/examples/extensions/rainbow-editor.ts +88 -0
- package/examples/extensions/reload-runtime.ts +37 -0
- package/examples/extensions/rpc-demo.ts +118 -0
- package/examples/extensions/sandbox/index.ts +326 -0
- package/examples/extensions/sandbox/package-lock.json +92 -0
- package/examples/extensions/sandbox/package.json +19 -0
- package/examples/extensions/send-user-message.ts +97 -0
- package/examples/extensions/session-name.ts +27 -0
- package/examples/extensions/shutdown-command.ts +63 -0
- package/examples/extensions/snake.ts +343 -0
- package/examples/extensions/space-invaders.ts +560 -0
- package/examples/extensions/ssh.ts +220 -0
- package/examples/extensions/status-line.ts +32 -0
- package/examples/extensions/structured-output.ts +65 -0
- package/examples/extensions/subagent/README.md +177 -0
- package/examples/extensions/subagent/agents/planner.md +37 -0
- package/examples/extensions/subagent/agents/reviewer.md +35 -0
- package/examples/extensions/subagent/agents/scout.md +50 -0
- package/examples/extensions/subagent/agents/worker.md +24 -0
- package/examples/extensions/subagent/agents.ts +157 -0
- package/examples/extensions/subagent/index.ts +1038 -0
- package/examples/extensions/subagent/prompts/implement-and-review.md +10 -0
- package/examples/extensions/subagent/prompts/implement.md +10 -0
- package/examples/extensions/subagent/prompts/scout-and-plan.md +9 -0
- package/examples/extensions/summarize.ts +199 -0
- package/examples/extensions/system-prompt-header.ts +17 -0
- package/examples/extensions/tic-tac-toe.ts +1008 -0
- package/examples/extensions/timed-confirm.ts +70 -0
- package/examples/extensions/titlebar-spinner.ts +58 -0
- package/examples/extensions/todo.ts +297 -0
- package/examples/extensions/tool-override.ts +144 -0
- package/examples/extensions/tools.ts +146 -0
- package/examples/extensions/trigger-compact.ts +50 -0
- package/examples/extensions/truncated-tool.ts +195 -0
- package/examples/extensions/widget-placement.ts +9 -0
- package/examples/extensions/with-deps/index.ts +32 -0
- package/examples/extensions/with-deps/package-lock.json +31 -0
- package/examples/extensions/with-deps/package.json +22 -0
- package/examples/extensions/working-indicator.ts +123 -0
- package/examples/extensions/working-message-test.ts +25 -0
- package/examples/rpc-client.ts +35 -0
- package/examples/rpc-extension-ui.ts +661 -0
- package/examples/sdk/01-minimal.ts +26 -0
- package/examples/sdk/02-custom-model.ts +49 -0
- package/examples/sdk/03-custom-prompt.ts +75 -0
- package/examples/sdk/04-skills.ts +55 -0
- package/examples/sdk/05-tools.ts +48 -0
- package/examples/sdk/06-extensions.ts +99 -0
- package/examples/sdk/07-context-files.ts +47 -0
- package/examples/sdk/08-prompt-templates.ts +51 -0
- package/examples/sdk/09-api-keys-and-oauth.ts +34 -0
- package/examples/sdk/10-settings.ts +53 -0
- package/examples/sdk/11-sessions.ts +52 -0
- package/examples/sdk/12-full-control.ts +74 -0
- package/examples/sdk/13-session-runtime.ts +67 -0
- package/examples/sdk/14-codemode-mcp.ts +61 -0
- package/examples/sdk/README.md +141 -0
- package/package.json +21 -5
- package/python/raga_rlm/__init__.py +336 -0
- package/python/raga_rlm/repl.py +920 -0
- package/schemas/keybindings.schema.json +393 -0
- package/schemas/models.schema.json +1211 -0
- package/schemas/settings.schema.json +815 -0
- package/schemas/theme.schema.json +365 -0
|
@@ -0,0 +1,725 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import process from "node:process";
|
|
4
|
+
|
|
5
|
+
export function findTlc() {
|
|
6
|
+
const { TLA2TOOLS, JAVA } = process.env;
|
|
7
|
+
if (!TLA2TOOLS)
|
|
8
|
+
throw new Error(
|
|
9
|
+
"Cannot find TLC. Download tla2tools.jar from a TLA+ release:\n https://github.com/tlaplus/tlaplus/releases/download/v1.8.0/tla2tools.jar\nThen set TLA2TOOLS to the path of tla2tools.jar, and JAVA to a java binary (Java 11 or later).",
|
|
10
|
+
);
|
|
11
|
+
if (!fs.existsSync(TLA2TOOLS)) throw new Error(`TLA2TOOLS is ${TLA2TOOLS}, which does not exist.`);
|
|
12
|
+
if (createHash("sha256").update(fs.readFileSync(TLA2TOOLS)).digest("hex") !== "d15655eeaff4b3f7b3d65c46b838bc0f35d131b2ef4b1e473689b62c98d4726f") throw new Error("TLC checksum mismatch. Request managed provisioning of TLA+ v1.8.0.");
|
|
13
|
+
return { jar: TLA2TOOLS, java: JAVA || "java" };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function parseValue(text) {
|
|
17
|
+
const src = text.trim();
|
|
18
|
+
let i = 0;
|
|
19
|
+
const ws = () => {
|
|
20
|
+
while (i < src.length && /\s/.test(src[i])) i++;
|
|
21
|
+
};
|
|
22
|
+
const peek = (s) => src.startsWith(s, i);
|
|
23
|
+
const eat = (s) => {
|
|
24
|
+
ws();
|
|
25
|
+
if (!peek(s)) throw new Error(`expected ${s} at ${i} in ${src}`);
|
|
26
|
+
i += s.length;
|
|
27
|
+
};
|
|
28
|
+
const list = (close, item) => {
|
|
29
|
+
const out = [];
|
|
30
|
+
ws();
|
|
31
|
+
if (peek(close)) {
|
|
32
|
+
i += close.length;
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
for (;;) {
|
|
36
|
+
out.push(item());
|
|
37
|
+
ws();
|
|
38
|
+
if (peek(",")) {
|
|
39
|
+
i++;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
eat(close);
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const value = () => {
|
|
47
|
+
ws();
|
|
48
|
+
if (peek("<<")) {
|
|
49
|
+
i += 2;
|
|
50
|
+
return list(">>", value);
|
|
51
|
+
}
|
|
52
|
+
if (peek("{")) {
|
|
53
|
+
i++;
|
|
54
|
+
return list("}", value);
|
|
55
|
+
}
|
|
56
|
+
if (peek("[")) {
|
|
57
|
+
i++;
|
|
58
|
+
const pairs = list("]", () => {
|
|
59
|
+
ws();
|
|
60
|
+
const m = /^[A-Za-z_][A-Za-z0-9_]*/.exec(src.slice(i));
|
|
61
|
+
if (!m) throw new Error(`bad record field at ${i}`);
|
|
62
|
+
i += m[0].length;
|
|
63
|
+
eat("|->");
|
|
64
|
+
return [m[0], value()];
|
|
65
|
+
});
|
|
66
|
+
return Object.fromEntries(pairs);
|
|
67
|
+
}
|
|
68
|
+
if (peek("(")) {
|
|
69
|
+
i++;
|
|
70
|
+
const fn = {};
|
|
71
|
+
for (;;) {
|
|
72
|
+
const k = value();
|
|
73
|
+
eat(":>");
|
|
74
|
+
fn[typeof k === "string" ? k : JSON.stringify(k)] = value();
|
|
75
|
+
ws();
|
|
76
|
+
if (peek("@@")) {
|
|
77
|
+
i += 2;
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
eat(")");
|
|
81
|
+
return fn;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (peek('"')) {
|
|
85
|
+
i++;
|
|
86
|
+
let s = "";
|
|
87
|
+
while (i < src.length && src[i] !== '"') {
|
|
88
|
+
if (src[i] === "\\") i++;
|
|
89
|
+
s += src[i++];
|
|
90
|
+
}
|
|
91
|
+
i++;
|
|
92
|
+
return s;
|
|
93
|
+
}
|
|
94
|
+
const m = /^-?\d+|^[A-Za-z_][A-Za-z0-9_]*/.exec(src.slice(i));
|
|
95
|
+
if (!m) throw new Error(`bad value at ${i} in ${src}`);
|
|
96
|
+
i += m[0].length;
|
|
97
|
+
if (m[0] === "TRUE") return true;
|
|
98
|
+
if (m[0] === "FALSE") return false;
|
|
99
|
+
return /^-?\d+$/.test(m[0]) ? Number(m[0]) : m[0];
|
|
100
|
+
};
|
|
101
|
+
try {
|
|
102
|
+
const v = value();
|
|
103
|
+
ws();
|
|
104
|
+
return i === src.length ? v : src;
|
|
105
|
+
} catch {
|
|
106
|
+
return src;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// One state as TLC prints it: "/\ x = 1" lines, or "x = 1" for one variable.
|
|
111
|
+
function parseState(text) {
|
|
112
|
+
const lines = text.split("\n").filter((l) => l.trim() !== "");
|
|
113
|
+
const conjuncts = [];
|
|
114
|
+
for (const line of lines) {
|
|
115
|
+
if (/^\s*\/\\ /.test(line) || conjuncts.length === 0)
|
|
116
|
+
conjuncts.push(line.replace(/^\s*\/\\ /, ""));
|
|
117
|
+
else conjuncts[conjuncts.length - 1] += ` ${line.trim()}`;
|
|
118
|
+
}
|
|
119
|
+
const vars = {};
|
|
120
|
+
for (const c of conjuncts) {
|
|
121
|
+
const eq = c.indexOf(" = ");
|
|
122
|
+
if (eq < 0) continue;
|
|
123
|
+
vars[c.slice(0, eq).trim()] = parseValue(c.slice(eq + 3));
|
|
124
|
+
}
|
|
125
|
+
return vars;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export const isRecord = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
129
|
+
const canon = (v) =>
|
|
130
|
+
Array.isArray(v)
|
|
131
|
+
? v.map(canon)
|
|
132
|
+
: isRecord(v)
|
|
133
|
+
? Object.fromEntries(
|
|
134
|
+
Object.keys(v)
|
|
135
|
+
.sort()
|
|
136
|
+
.map((k) => [k, canon(v[k])]),
|
|
137
|
+
)
|
|
138
|
+
: v;
|
|
139
|
+
export const stateKey = (vars) => JSON.stringify(canon(vars));
|
|
140
|
+
|
|
141
|
+
export function ruleSentences(tla) {
|
|
142
|
+
const out = new Map();
|
|
143
|
+
const lines = tla.split("\n");
|
|
144
|
+
lines.forEach((line, i) => {
|
|
145
|
+
const name = /^([A-Za-z_]\w*)\s*==/.exec(line)?.[1];
|
|
146
|
+
if (!name) return;
|
|
147
|
+
const said = [];
|
|
148
|
+
for (let j = i - 1; j >= 0 && /^\s*\\\*/.test(lines[j]); j--)
|
|
149
|
+
said.unshift(lines[j].replace(/^\s*\\\*\s?/, "").trim());
|
|
150
|
+
const sentence = said.filter(Boolean).join(" ");
|
|
151
|
+
if (sentence) out.set(name, sentence);
|
|
152
|
+
});
|
|
153
|
+
return out;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function unescapeDot(s) {
|
|
157
|
+
let out = "";
|
|
158
|
+
for (let i = 0; i < s.length; i++) {
|
|
159
|
+
if (s[i] === "\\" && i + 1 < s.length) {
|
|
160
|
+
const n = s[++i];
|
|
161
|
+
out += n === "n" ? "\n" : n;
|
|
162
|
+
} else out += s[i];
|
|
163
|
+
}
|
|
164
|
+
return out;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export function parseDot(text) {
|
|
168
|
+
const nodes = new Map();
|
|
169
|
+
const edges = [];
|
|
170
|
+
const loops = [];
|
|
171
|
+
const seen = new Set();
|
|
172
|
+
const LABEL = '"((?:[^"\\\\]|\\\\.)*)"';
|
|
173
|
+
const nodeRe = new RegExp(`^(-?\\d+) \\[label=${LABEL}(.*)\\];?\\s*$`);
|
|
174
|
+
const edgeRe = new RegExp(`^(-?\\d+) -> (-?\\d+)(?: \\[label=${LABEL})?`);
|
|
175
|
+
for (const line of text.split("\n")) {
|
|
176
|
+
let m = edgeRe.exec(line);
|
|
177
|
+
if (m) {
|
|
178
|
+
const e = { from: m[1], to: m[2], action: m[3] ? unescapeDot(m[3]) : "" };
|
|
179
|
+
const id = `${e.from} ${e.to} ${e.action}`;
|
|
180
|
+
if (seen.has(id)) continue;
|
|
181
|
+
seen.add(id);
|
|
182
|
+
(e.from === e.to ? loops : edges).push(e);
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
m = nodeRe.exec(line);
|
|
186
|
+
if (m)
|
|
187
|
+
nodes.set(m[1], {
|
|
188
|
+
id: m[1],
|
|
189
|
+
vars: parseState(unescapeDot(m[2])),
|
|
190
|
+
init: /style\s*=\s*filled/.test(m[3]),
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
if (nodes.size === 0)
|
|
194
|
+
throw new Error("no states found; dump the graph with TLC -dump dot,actionlabels <file>");
|
|
195
|
+
const missing = [...edges, ...loops].find((e) => !nodes.has(e.from) || !nodes.has(e.to));
|
|
196
|
+
if (missing)
|
|
197
|
+
throw new Error(
|
|
198
|
+
`transition ${missing.from} -> ${missing.to} names a state the file does not define`,
|
|
199
|
+
);
|
|
200
|
+
if (edges.length > 0 && [...edges, ...loops].every((e) => !e.action))
|
|
201
|
+
throw new Error(
|
|
202
|
+
"the graph has no action names; dump it with TLC -dump dot,actionlabels <file>",
|
|
203
|
+
);
|
|
204
|
+
return { nodes, edges, loops };
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export function parseTraces(text) {
|
|
208
|
+
const traces = [];
|
|
209
|
+
let invariant = null;
|
|
210
|
+
let current = null;
|
|
211
|
+
const lines = text.split("\n");
|
|
212
|
+
const stateAt = (i) => {
|
|
213
|
+
const body = [];
|
|
214
|
+
while (i + 1 < lines.length && lines[i + 1].trim() !== "") body.push(lines[++i]);
|
|
215
|
+
return [parseState(body.join("\n")), i];
|
|
216
|
+
};
|
|
217
|
+
for (let i = 0; i < lines.length; i++) {
|
|
218
|
+
const line = lines[i];
|
|
219
|
+
const inv = /^Error: Invariant (\S+) is violated( by the initial state:)?/.exec(line);
|
|
220
|
+
if (inv) {
|
|
221
|
+
invariant = inv[1];
|
|
222
|
+
if (inv[2]) {
|
|
223
|
+
const [vars, end] = stateAt(i);
|
|
224
|
+
traces.push({ invariant, steps: [{ action: null, vars }] });
|
|
225
|
+
i = end;
|
|
226
|
+
}
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
if (line.startsWith("Error: ") && !line.startsWith("Error: The behavior up to this point is"))
|
|
230
|
+
invariant = null;
|
|
231
|
+
const head = /^State (\d+): <([^\s>(]+)/.exec(line);
|
|
232
|
+
if (!head) continue;
|
|
233
|
+
const [vars, end] = stateAt(i);
|
|
234
|
+
i = end;
|
|
235
|
+
if (head[1] === "1") {
|
|
236
|
+
current = { invariant, steps: [] };
|
|
237
|
+
traces.push(current);
|
|
238
|
+
}
|
|
239
|
+
current?.steps.push({ action: head[2] === "Initial" ? null : head[2], vars });
|
|
240
|
+
}
|
|
241
|
+
return traces;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// With -continue, TLC prints "Model checking completed" even after broken invariants, and not
|
|
245
|
+
// when it stopped early.
|
|
246
|
+
export function checkTlcOutput(text, file) {
|
|
247
|
+
const other = text
|
|
248
|
+
.split("\n")
|
|
249
|
+
.find(
|
|
250
|
+
(l) =>
|
|
251
|
+
l.startsWith("Error: ") &&
|
|
252
|
+
!/^Error: (Invariant \S+ is violated|The behavior up to this point is)/.test(l),
|
|
253
|
+
);
|
|
254
|
+
if (other)
|
|
255
|
+
throw new Error(
|
|
256
|
+
`${file}: TLC stopped on an error that is not a broken rule: ${other.slice(7)}`,
|
|
257
|
+
);
|
|
258
|
+
if (!/^Model checking completed\./m.test(text))
|
|
259
|
+
throw new Error(
|
|
260
|
+
`${file}: TLC did not finish, so its counterexamples are not all there; read the file`,
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export function wrap(text, width = 26) {
|
|
265
|
+
const words = String(text).split(/\s+/);
|
|
266
|
+
const rows = [];
|
|
267
|
+
let row = "";
|
|
268
|
+
for (const w of words) {
|
|
269
|
+
if (row && (row + " " + w).length > width) {
|
|
270
|
+
rows.push(row);
|
|
271
|
+
row = w;
|
|
272
|
+
} else row = row ? `${row} ${w}` : w;
|
|
273
|
+
}
|
|
274
|
+
if (row) rows.push(row);
|
|
275
|
+
return rows.join("<br/>");
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const OPENS_A_PHRASE = new Set(
|
|
279
|
+
"a an the your my our their its this that to of in on at for with from by and or".split(" "),
|
|
280
|
+
);
|
|
281
|
+
export function joinLabels(labels) {
|
|
282
|
+
if (labels.length < 2) return labels.join(" or ");
|
|
283
|
+
const words = labels.map((l) => String(l).split(" "));
|
|
284
|
+
let n = 0;
|
|
285
|
+
while (words.every((w) => n < w.length - 1 && w[n] === words[0][n])) n++;
|
|
286
|
+
while (n > 0 && OPENS_A_PHRASE.has(words[0][n - 1])) n--;
|
|
287
|
+
if (n < 2) return labels.join(" or ");
|
|
288
|
+
const rest = words.map((w) => w.slice(n).join(" "));
|
|
289
|
+
const list =
|
|
290
|
+
rest.length === 2 ? rest.join(" or ") : `${rest.slice(0, -1).join(", ")}, or ${rest.at(-1)}`;
|
|
291
|
+
return `${words[0].slice(0, n).join(" ")} ${list}`;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const unwrap = (s) =>
|
|
295
|
+
s
|
|
296
|
+
.replace(/<br\s*\/?>|#160;/g, " ")
|
|
297
|
+
.replace(/#(quot|34);/g, '"')
|
|
298
|
+
.replace(/\s+/g, " ")
|
|
299
|
+
.trim();
|
|
300
|
+
|
|
301
|
+
// Mermaid ends a quoted state caption at the first ", so a caption writes " as #quot;.
|
|
302
|
+
export const quote = (s) => String(s).replaceAll('"', "#quot;");
|
|
303
|
+
|
|
304
|
+
export const LEGEND_ID = "legend";
|
|
305
|
+
export const FULL_LABELS = "%% labels in full";
|
|
306
|
+
|
|
307
|
+
export function parseMermaid(text) {
|
|
308
|
+
const names = new Map();
|
|
309
|
+
const nevers = [];
|
|
310
|
+
let last = null;
|
|
311
|
+
const newPart = () => ({ children: [], transitions: [] });
|
|
312
|
+
const root = { name: "", parts: [newPart()] };
|
|
313
|
+
const stack = [root];
|
|
314
|
+
const part = () => stack[stack.length - 1].parts.at(-1);
|
|
315
|
+
const display = (id) => names.get(id) ?? id;
|
|
316
|
+
const implicit = new Map();
|
|
317
|
+
const declare = (id) => {
|
|
318
|
+
const prev = implicit.get(id);
|
|
319
|
+
if (prev)
|
|
320
|
+
prev.children.splice(
|
|
321
|
+
prev.children.findIndex((c) => c.name === id),
|
|
322
|
+
1,
|
|
323
|
+
);
|
|
324
|
+
implicit.set(id, null);
|
|
325
|
+
};
|
|
326
|
+
const mention = (id) => {
|
|
327
|
+
if (id === "[*]" || implicit.has(id)) return;
|
|
328
|
+
part().children.push({ name: id, leaf: true });
|
|
329
|
+
implicit.set(id, part());
|
|
330
|
+
};
|
|
331
|
+
const body = text.replace(/^\s*---[ \t]*\r?\n[^]*?\r?\n---[ \t]*(\r?\n|$)/, "");
|
|
332
|
+
for (const raw of body.split("\n")) {
|
|
333
|
+
const line = raw.trim().replace(/(\[\*\]|[A-Za-z_]\w*):::[\w-]+/g, "$1");
|
|
334
|
+
const when = /^%%\s*when\s+(not\s+)?(.+)$/.exec(line);
|
|
335
|
+
if (when) {
|
|
336
|
+
if (!last) throw new Error(`a %% when line must come right after a transition: ${line}`);
|
|
337
|
+
if (!last.words)
|
|
338
|
+
throw new Error(
|
|
339
|
+
`the guarded step "${last.label}" must end its label with the guard's words in [ ]`,
|
|
340
|
+
);
|
|
341
|
+
last.when = { not: Boolean(when[1]), ids: when[2].split(",").map((s) => s.trim()) };
|
|
342
|
+
last = null;
|
|
343
|
+
continue;
|
|
344
|
+
}
|
|
345
|
+
last = null;
|
|
346
|
+
const never = /^%%\s*never\s+([A-Za-z_][A-Za-z0-9_]*)\s*:\s*(.+?)(?:\s+--\s+(.*))?$/.exec(line);
|
|
347
|
+
if (never) {
|
|
348
|
+
nevers.push({
|
|
349
|
+
name: never[1],
|
|
350
|
+
states: never[2].split("&").map((s) => s.trim()),
|
|
351
|
+
sentence: never[3] ?? "",
|
|
352
|
+
});
|
|
353
|
+
continue;
|
|
354
|
+
}
|
|
355
|
+
if (
|
|
356
|
+
!line ||
|
|
357
|
+
line.startsWith("%%") ||
|
|
358
|
+
/^(stateDiagram|direction|classDef|class |note)/.test(line)
|
|
359
|
+
)
|
|
360
|
+
continue;
|
|
361
|
+
let m = /^state\s+"([^"]*)"\s+as\s+([A-Za-z_]\w*)\s*(\{)?\s*$/.exec(line);
|
|
362
|
+
if (!m) {
|
|
363
|
+
const plain = /^state\s+([A-Za-z_]\w*)\s*(\{)?\s*$/.exec(line);
|
|
364
|
+
if (plain) m = [line, null, plain[1], plain[2]];
|
|
365
|
+
}
|
|
366
|
+
if (m) {
|
|
367
|
+
if (m[1] !== null && !names.has(m[2])) names.set(m[2], unwrap(m[1]));
|
|
368
|
+
declare(m[2]);
|
|
369
|
+
if (m[3]) {
|
|
370
|
+
const node = { name: m[2], parts: [newPart()] };
|
|
371
|
+
part().children.push(node);
|
|
372
|
+
stack.push(node);
|
|
373
|
+
} else part().children.push({ name: m[2], leaf: true });
|
|
374
|
+
continue;
|
|
375
|
+
}
|
|
376
|
+
if (line === "}") {
|
|
377
|
+
if (stack.length === 1) throw new Error("unmatched } in the chart");
|
|
378
|
+
stack.pop();
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
if (line === "--") {
|
|
382
|
+
stack[stack.length - 1].parts.push(newPart());
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
m = /^(\[\*\]|[A-Za-z_]\w*)\s*-->\s*(\[\*\]|[A-Za-z_]\w*)(?:\s*:\s*(.*))?$/.exec(line);
|
|
386
|
+
if (m) {
|
|
387
|
+
if (m[2] === "[*]" && m[1] !== "[*]")
|
|
388
|
+
throw new Error(
|
|
389
|
+
`cannot read final state in "${line}"; draw the step to the state the reader sees next`,
|
|
390
|
+
);
|
|
391
|
+
mention(m[1]);
|
|
392
|
+
mention(m[2]);
|
|
393
|
+
const said = m[3] ? unwrap(m[3]) : "";
|
|
394
|
+
const label = said.replace(/\s*\[[^\]]*\]/g, "");
|
|
395
|
+
last = { from: m[1], to: m[2], label, words: label !== said };
|
|
396
|
+
part().transitions.push(last);
|
|
397
|
+
continue;
|
|
398
|
+
}
|
|
399
|
+
m = /^([A-Za-z_]\w*)\s*:\s*(.*)$/.exec(line);
|
|
400
|
+
if (m) {
|
|
401
|
+
if (!names.has(m[1])) names.set(m[1], unwrap(m[2]));
|
|
402
|
+
if (implicit.get(m[1]) === null) continue;
|
|
403
|
+
declare(m[1]);
|
|
404
|
+
part().children.push({ name: m[1], leaf: true });
|
|
405
|
+
continue;
|
|
406
|
+
}
|
|
407
|
+
throw new Error(`cannot read chart line: ${line}`);
|
|
408
|
+
}
|
|
409
|
+
if (stack.length !== 1) throw new Error("the chart has an unclosed {");
|
|
410
|
+
if (root.parts.length > 1)
|
|
411
|
+
throw new Error(
|
|
412
|
+
"the chart has -- outside a composite; to make parallel regions, split one top-level composite with --",
|
|
413
|
+
);
|
|
414
|
+
|
|
415
|
+
// Ids are global, as in Mermaid: a transition may name a state declared inside another composite.
|
|
416
|
+
function region(p) {
|
|
417
|
+
const out = { states: new Set(), initial: new Set(), transitions: [] };
|
|
418
|
+
const info = new Map();
|
|
419
|
+
const declared = new Set();
|
|
420
|
+
(function collect(q) {
|
|
421
|
+
for (const c of q.children) {
|
|
422
|
+
if (c.name === LEGEND_ID) continue;
|
|
423
|
+
declared.add(c.name);
|
|
424
|
+
if (!c.leaf) for (const sub of c.parts) collect(sub);
|
|
425
|
+
}
|
|
426
|
+
})(p);
|
|
427
|
+
const transitions = [];
|
|
428
|
+
const lookup = (id) => {
|
|
429
|
+
const found = info.get(id);
|
|
430
|
+
if (!found) throw new Error(`transition names ${id}, which is not in this region`);
|
|
431
|
+
return found;
|
|
432
|
+
};
|
|
433
|
+
function states(q, prefix, depth) {
|
|
434
|
+
const local = q.children.filter((c) => c.name !== LEGEND_ID);
|
|
435
|
+
for (const t of q.transitions) {
|
|
436
|
+
for (const end of [t.from, t.to]) {
|
|
437
|
+
if (end === "[*]" || declared.has(end)) continue;
|
|
438
|
+
declared.add(end);
|
|
439
|
+
local.push({ name: end, leaf: true });
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
const all = [];
|
|
443
|
+
for (const c of local) {
|
|
444
|
+
if (info.has(c.name)) {
|
|
445
|
+
if (local.indexOf(c) !== local.findIndex((x) => x.name === c.name)) continue;
|
|
446
|
+
throw new Error(`state id ${c.name} is declared in two places`);
|
|
447
|
+
}
|
|
448
|
+
const full = `${prefix}${display(c.name)}`;
|
|
449
|
+
if (c.leaf) {
|
|
450
|
+
if (out.states.has(full))
|
|
451
|
+
throw new Error(`two states have the caption "${full}"; give each its own caption`);
|
|
452
|
+
out.states.add(full);
|
|
453
|
+
info.set(c.name, { all: [full], initial: [full], depth });
|
|
454
|
+
all.push(full);
|
|
455
|
+
continue;
|
|
456
|
+
}
|
|
457
|
+
if (c.parts.length > 1)
|
|
458
|
+
throw new Error(
|
|
459
|
+
`${display(c.name)} splits into regions below the top level; make each region a top-level region`,
|
|
460
|
+
);
|
|
461
|
+
const inner = states(c.parts[0], `${full}.`, depth + 1);
|
|
462
|
+
const initial = c.parts[0].transitions
|
|
463
|
+
.filter((t) => t.from === "[*]")
|
|
464
|
+
.flatMap((t) => lookup(t.to).initial);
|
|
465
|
+
if (initial.length === 0)
|
|
466
|
+
throw new Error(
|
|
467
|
+
`${display(c.name)} has no [*] --> start, so a transition into it has nowhere to land`,
|
|
468
|
+
);
|
|
469
|
+
info.set(c.name, { all: inner, initial, depth });
|
|
470
|
+
all.push(...inner);
|
|
471
|
+
}
|
|
472
|
+
for (const t of q.transitions) if (t.from !== "[*]" && t.to !== "[*]") transitions.push(t);
|
|
473
|
+
return all;
|
|
474
|
+
}
|
|
475
|
+
states(p, "", 0);
|
|
476
|
+
for (const t of p.transitions)
|
|
477
|
+
if (t.from === "[*]") for (const s of lookup(t.to).initial) out.initial.add(s);
|
|
478
|
+
transitions.sort((a, b) => lookup(b.from).depth - lookup(a.from).depth);
|
|
479
|
+
const handled = new Set();
|
|
480
|
+
let pending = [];
|
|
481
|
+
let depth = null;
|
|
482
|
+
for (const t of transitions) {
|
|
483
|
+
const from = lookup(t.from);
|
|
484
|
+
if (from.depth !== depth) {
|
|
485
|
+
for (const h of pending) handled.add(h);
|
|
486
|
+
pending = [];
|
|
487
|
+
depth = from.depth;
|
|
488
|
+
}
|
|
489
|
+
for (const f of from.all) {
|
|
490
|
+
const key = `${f}\u0000${t.label}`;
|
|
491
|
+
if (t.label && handled.has(key)) continue;
|
|
492
|
+
for (const to of lookup(t.to).initial)
|
|
493
|
+
out.transitions.push({
|
|
494
|
+
from: f,
|
|
495
|
+
to,
|
|
496
|
+
label: t.label,
|
|
497
|
+
...(t.when ? { when: t.when } : {}),
|
|
498
|
+
});
|
|
499
|
+
if (t.label) pending.push(key);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
return [out, info];
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
const owners = new Map();
|
|
506
|
+
const regions = {};
|
|
507
|
+
const top = root.parts[0];
|
|
508
|
+
const machine = top.children.filter((c) => c.name !== LEGEND_ID);
|
|
509
|
+
const parallel =
|
|
510
|
+
machine.length === 1 &&
|
|
511
|
+
!machine[0].leaf &&
|
|
512
|
+
machine[0].parts.length > 1 &&
|
|
513
|
+
top.transitions.every((t) => t.from === "[*]");
|
|
514
|
+
if (parallel) {
|
|
515
|
+
for (const p of machine[0].parts) {
|
|
516
|
+
const [only] = p.children;
|
|
517
|
+
const holder =
|
|
518
|
+
p.children.length === 1 &&
|
|
519
|
+
!only.leaf &&
|
|
520
|
+
p.transitions.every((t) => t.from === "[*]" && t.to === only.name)
|
|
521
|
+
? only
|
|
522
|
+
: null;
|
|
523
|
+
if (holder && holder.parts.length > 1)
|
|
524
|
+
throw new Error(`${display(holder.name)} splits into regions below the top level`);
|
|
525
|
+
const name = holder ? display(holder.name) : `Region${Object.keys(regions).length + 1}`;
|
|
526
|
+
const [r, ids] = region(holder ? holder.parts[0] : p);
|
|
527
|
+
regions[name] = r;
|
|
528
|
+
for (const [id, { all }] of ids) owners.set(id, { name, all });
|
|
529
|
+
}
|
|
530
|
+
} else {
|
|
531
|
+
const [r, ids] = region(top);
|
|
532
|
+
regions.Main = r;
|
|
533
|
+
for (const [id, { all }] of ids) owners.set(id, { name: "Main", all });
|
|
534
|
+
}
|
|
535
|
+
for (const [name, r] of Object.entries(regions))
|
|
536
|
+
for (const t of r.transitions) {
|
|
537
|
+
if (!t.when) continue;
|
|
538
|
+
if (!parallel)
|
|
539
|
+
throw new Error("a %% when line guards a step on other regions, and the chart has none");
|
|
540
|
+
const states = {};
|
|
541
|
+
for (const id of t.when.ids) {
|
|
542
|
+
const at = owners.get(id);
|
|
543
|
+
if (!at)
|
|
544
|
+
throw new Error(`a %% when line names ${id}, which is not a state id in the chart`);
|
|
545
|
+
if (at.name === name)
|
|
546
|
+
throw new Error(
|
|
547
|
+
`a %% when line names ${display(id)}, which is in the step's own region; a guard reads other regions`,
|
|
548
|
+
);
|
|
549
|
+
states[at.name] = [...new Set([...(states[at.name] ?? []), ...at.all])].sort();
|
|
550
|
+
}
|
|
551
|
+
t.guard = { not: t.when.not, states };
|
|
552
|
+
delete t.when;
|
|
553
|
+
}
|
|
554
|
+
return { regions, nevers };
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
function guardHolds(guard, at) {
|
|
558
|
+
if (!guard) return true;
|
|
559
|
+
const hits = Object.entries(guard.states).map(([r, states]) => states.includes(at[r]));
|
|
560
|
+
return guard.not ? !hits.some(Boolean) : hits.every(Boolean);
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
export function productOf(regions) {
|
|
564
|
+
const names = Object.keys(regions);
|
|
565
|
+
const rs = Object.values(regions);
|
|
566
|
+
const join = (parts) => parts.join(" | ");
|
|
567
|
+
const byLabel = new Map();
|
|
568
|
+
const unlabeled = [];
|
|
569
|
+
rs.forEach((r, ri) => {
|
|
570
|
+
for (const t of r.transitions) {
|
|
571
|
+
if (!t.label) {
|
|
572
|
+
unlabeled.push({ ri, from: t.from, to: t.to, guard: t.guard });
|
|
573
|
+
continue;
|
|
574
|
+
}
|
|
575
|
+
if (!byLabel.has(t.label))
|
|
576
|
+
byLabel.set(
|
|
577
|
+
t.label,
|
|
578
|
+
rs.map(() => new Map()),
|
|
579
|
+
);
|
|
580
|
+
const moves = byLabel.get(t.label)[ri];
|
|
581
|
+
if (!moves.has(t.from)) moves.set(t.from, []);
|
|
582
|
+
moves.get(t.from).push({ to: t.to, guard: t.guard });
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
let starts = [[]];
|
|
586
|
+
for (const r of rs) starts = starts.flatMap((p) => [...r.initial].map((s) => [...p, s]));
|
|
587
|
+
const out = { states: new Set(), initial: new Set(starts.map(join)), transitions: [] };
|
|
588
|
+
const seen = new Set(starts.map(join));
|
|
589
|
+
const queue = [...starts];
|
|
590
|
+
const step = (from, to, label) => {
|
|
591
|
+
const [a, b] = [join(from), join(to)];
|
|
592
|
+
if (a === b) return;
|
|
593
|
+
out.transitions.push({ from: a, to: b, label });
|
|
594
|
+
if (!seen.has(b)) {
|
|
595
|
+
seen.add(b);
|
|
596
|
+
queue.push(to);
|
|
597
|
+
}
|
|
598
|
+
};
|
|
599
|
+
while (queue.length) {
|
|
600
|
+
const cur = queue.shift();
|
|
601
|
+
out.states.add(join(cur));
|
|
602
|
+
const at = Object.fromEntries(names.map((n, ri) => [n, cur[ri]]));
|
|
603
|
+
for (const u of unlabeled) {
|
|
604
|
+
if (cur[u.ri] !== u.from || !guardHolds(u.guard, at)) continue;
|
|
605
|
+
const next = [...cur];
|
|
606
|
+
next[u.ri] = u.to;
|
|
607
|
+
step(cur, next, "");
|
|
608
|
+
}
|
|
609
|
+
for (const [label, perRegion] of byLabel) {
|
|
610
|
+
const open = perRegion.map((moves, ri) =>
|
|
611
|
+
(moves.get(cur[ri]) ?? []).filter((m) => guardHolds(m.guard, at)).map((m) => m.to),
|
|
612
|
+
);
|
|
613
|
+
if (open.every((tos) => tos.length === 0)) continue;
|
|
614
|
+
let nexts = [[]];
|
|
615
|
+
open.forEach((tos, ri) => {
|
|
616
|
+
const options = tos.length ? [...new Set(tos)] : [cur[ri]];
|
|
617
|
+
nexts = nexts.flatMap((p) => options.map((s) => [...p, s]));
|
|
618
|
+
});
|
|
619
|
+
for (const next of nexts) step(cur, next, label);
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
return out;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
export function compareCharts(expectedRegions, actualRegions) {
|
|
626
|
+
const expected = productOf(expectedRegions);
|
|
627
|
+
const actual = productOf(actualRegions);
|
|
628
|
+
const edgeSet = (m) => {
|
|
629
|
+
const labeled = new Set();
|
|
630
|
+
const out = new Set();
|
|
631
|
+
for (const t of m.transitions) {
|
|
632
|
+
if (!t.label) continue;
|
|
633
|
+
labeled.add(`${t.from} --> ${t.to}`);
|
|
634
|
+
for (const l of t.label.split(" or ")) out.add(`${t.from} --> ${t.to} : ${l}`);
|
|
635
|
+
}
|
|
636
|
+
for (const t of m.transitions)
|
|
637
|
+
if (!t.label && !labeled.has(`${t.from} --> ${t.to}`)) out.add(`${t.from} --> ${t.to}`);
|
|
638
|
+
return out;
|
|
639
|
+
};
|
|
640
|
+
const minus = (a, b) => [...a].filter((x) => !b.has(x)).sort();
|
|
641
|
+
const unreached = [];
|
|
642
|
+
const regionEntries = Object.entries(expectedRegions);
|
|
643
|
+
if (regionEntries.length === 1) {
|
|
644
|
+
for (const s of regionEntries[0][1].states) if (!expected.states.has(s)) unreached.push(s);
|
|
645
|
+
} else {
|
|
646
|
+
regionEntries.forEach(([name, r], ri) => {
|
|
647
|
+
const seen = new Set([...expected.states].map((s) => s.split(" | ")[ri]));
|
|
648
|
+
for (const s of r.states) if (!seen.has(s)) unreached.push(`${name}: ${s}`);
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
return [
|
|
652
|
+
["states the agreed chart's own steps never reach", unreached.sort()],
|
|
653
|
+
[
|
|
654
|
+
"states only in EXPECTED (no path from the start reaches them in the spec, or the spec renamed them)",
|
|
655
|
+
minus(expected.states, actual.states),
|
|
656
|
+
],
|
|
657
|
+
["states only in ACTUAL", minus(actual.states, expected.states)],
|
|
658
|
+
["start states only in EXPECTED", minus(expected.initial, actual.initial)],
|
|
659
|
+
["start states only in ACTUAL", minus(actual.initial, expected.initial)],
|
|
660
|
+
[
|
|
661
|
+
"transitions only in EXPECTED (a guard in the spec blocks them, or the spec renamed the step)",
|
|
662
|
+
minus(edgeSet(expected), edgeSet(actual)),
|
|
663
|
+
],
|
|
664
|
+
["transitions only in ACTUAL", minus(edgeSet(actual), edgeSet(expected))],
|
|
665
|
+
].filter(([, xs]) => xs.length > 0);
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
export const STATUS_CLASSES = [
|
|
669
|
+
"classDef works fill:#f4f6f7,stroke:#566573,color:#1b2631",
|
|
670
|
+
"classDef wrong fill:#fdedec,stroke:#c0392b,color:#7b241c",
|
|
671
|
+
"classDef fixed fill:#e9f7ef,stroke:#1e8449,color:#145a32",
|
|
672
|
+
"classDef worksPath fill:#f4f6f7,stroke:#1f3a93,stroke-width:4px,color:#1b2631",
|
|
673
|
+
"classDef wrongPath fill:#fdedec,stroke:#1f3a93,stroke-width:4px,color:#7b241c",
|
|
674
|
+
"classDef fixedPath fill:#e9f7ef,stroke:#1f3a93,stroke-width:4px,color:#145a32",
|
|
675
|
+
];
|
|
676
|
+
|
|
677
|
+
export const GROUP_PALETTE = [
|
|
678
|
+
"#d6eaf8",
|
|
679
|
+
"#fdebd0",
|
|
680
|
+
"#e8daef",
|
|
681
|
+
"#fcf3cf",
|
|
682
|
+
"#d1f2eb",
|
|
683
|
+
"#ede0d4",
|
|
684
|
+
"#f6e0ef",
|
|
685
|
+
];
|
|
686
|
+
export const PLAIN_FILL = "#f4f6f7";
|
|
687
|
+
|
|
688
|
+
const rgb = (hex) => {
|
|
689
|
+
const h = hex.length === 4 ? [...hex.slice(1)].map((c) => c + c).join("") : hex.slice(1);
|
|
690
|
+
return [0, 2, 4].map((i) => parseInt(h.slice(i, i + 2), 16));
|
|
691
|
+
};
|
|
692
|
+
// WCAG relative luminance: 0 for black, 1 for white.
|
|
693
|
+
function luminance(hex) {
|
|
694
|
+
const [r, g, b] = rgb(hex).map((c) => {
|
|
695
|
+
const s = c / 255;
|
|
696
|
+
return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
|
|
697
|
+
});
|
|
698
|
+
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
699
|
+
}
|
|
700
|
+
export function groupColorProblem(color) {
|
|
701
|
+
if (typeof color !== "string" || !/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(color))
|
|
702
|
+
return 'is not "#rgb" or "#rrggbb"';
|
|
703
|
+
if (luminance(color) < 0.5) return "is too dark for the status borders to show on it";
|
|
704
|
+
return null;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
const BORDERS = {
|
|
708
|
+
Wrong: ["stroke:#c0392b,stroke-width:4px", "#7b241c"],
|
|
709
|
+
Fixed: ["stroke:#1e8449,stroke-width:4px", "#145a32"],
|
|
710
|
+
Path: ["stroke:#1f3a93,stroke-width:4px", "#1b2631"],
|
|
711
|
+
};
|
|
712
|
+
export function groupClassDef(base, fill, border) {
|
|
713
|
+
const darker = `#${rgb(fill)
|
|
714
|
+
.map((c) =>
|
|
715
|
+
Math.round(c / 2)
|
|
716
|
+
.toString(16)
|
|
717
|
+
.padStart(2, "0"),
|
|
718
|
+
)
|
|
719
|
+
.join("")}`;
|
|
720
|
+
const [stroke, color] = BORDERS[border] ?? [
|
|
721
|
+
`stroke:${fill === PLAIN_FILL ? "#566573" : darker}`,
|
|
722
|
+
"#1b2631",
|
|
723
|
+
];
|
|
724
|
+
return `classDef ${base}${border} fill:${fill},${stroke},color:${color}`;
|
|
725
|
+
}
|