raga-cli 0.0.0-stage → 0.9.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 +118 -0
- package/LICENSE +21 -0
- package/README.md +162 -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 +1514 -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/bend/SKILL.md +58 -0
- package/bundled-skills/skills/bend/bend_tool.py +144 -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 +51 -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 +55 -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/bundled-skills/skills/raga-artifacts/SKILL.md +117 -0
- package/bundled-skills/skills/raga-artifacts/artifact.mjs +254 -0
- package/bundled-skills/skills/raga-artifacts/artifact_tool.py +55 -0
- package/bundled-skills/skills/raga-artifacts/diagrams.md +641 -0
- package/bundled-skills/skills/raga-artifacts/templates/doc.html +124 -0
- package/bundled-skills/skills/raga-artifacts/templates/slides.html +138 -0
- package/dist/bundle/chunks/anthropic-messages-BMDYDGHW.js +6 -0
- package/dist/bundle/chunks/anthropic.js +68 -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-3MNXTBQ3.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-CF5GWZHW.js +31 -0
- package/dist/bundle/chunks/chunk-ENUUAC3O.js +131 -0
- package/dist/bundle/chunks/chunk-F7LFZTHT.js +1591 -0
- package/dist/bundle/chunks/chunk-G54UBZTF.js +44 -0
- package/dist/bundle/chunks/chunk-H76KZMOI.js +2 -0
- package/dist/bundle/chunks/chunk-IXDQLPKS.js +11 -0
- package/dist/bundle/chunks/chunk-JLV25LHE.js +2 -0
- package/dist/bundle/chunks/chunk-JQDZ4Z7L.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-NP6TH6UT.js +64 -0
- package/dist/bundle/chunks/chunk-OPPYO2IE.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-S5J3UB5O.js +75 -0
- package/dist/bundle/chunks/chunk-TEPMHNKQ.js +2 -0
- package/dist/bundle/chunks/chunk-TMTOQ7H7.js +2 -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/cli-QLDCDYOR.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-NPDBBPPF.js +2 -0
- package/dist/bundle/chunks/execute-WPTMS4XG.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 +68 -0
- package/dist/bundle/chunks/openai-codex-responses-4HXATL2M.js +10 -0
- package/dist/bundle/chunks/openai-codex.js +68 -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 +68 -0
- package/dist/bundle/chunks/pi-messages-DG7CALOV.js +8 -0
- package/dist/bundle/chunks/radius.js +68 -0
- package/dist/bundle/chunks/runtime-N5MUH2WA.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-4I6Y6DPQ.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 +343 -0
- package/docs/codemode.md +230 -0
- package/docs/compaction.md +489 -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 +149 -0
- package/docs/security.md +99 -0
- package/docs/session-format.md +293 -0
- package/docs/sessions.md +66 -0
- package/docs/settings.md +185 -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 +352 -0
- package/python/raga_rlm/mlx_models.py +265 -0
- package/python/raga_rlm/repl.py +920 -0
- package/schemas/keybindings.schema.json +441 -0
- package/schemas/models.schema.json +1211 -0
- package/schemas/settings.schema.json +829 -0
- package/schemas/theme.schema.json +365 -0
|
@@ -0,0 +1,836 @@
|
|
|
1
|
+
import {
|
|
2
|
+
WatcherQueryError,
|
|
3
|
+
resolveChecks,
|
|
4
|
+
resolveReviewThreads,
|
|
5
|
+
} from "./github.ts";
|
|
6
|
+
import type * as T from "./types.ts";
|
|
7
|
+
import { nonEmpty } from "./types.ts";
|
|
8
|
+
export function assessGitHubMerge(args: {
|
|
9
|
+
readonly mergeStateStatus: T.MergeStateStatus;
|
|
10
|
+
readonly headRollupState: T.RollupState;
|
|
11
|
+
}): T.GitHubMergeAssessment {
|
|
12
|
+
if (args.mergeStateStatus === "BLOCKED") {
|
|
13
|
+
if (args.headRollupState === "ERROR" || args.headRollupState === "FAILURE")
|
|
14
|
+
return {
|
|
15
|
+
kind: "refused",
|
|
16
|
+
mergeStateStatus: args.mergeStateStatus,
|
|
17
|
+
headRollupState: args.headRollupState,
|
|
18
|
+
};
|
|
19
|
+
return {
|
|
20
|
+
kind: "allowed",
|
|
21
|
+
basis: "rollup",
|
|
22
|
+
mergeStateStatus: args.mergeStateStatus,
|
|
23
|
+
headRollupState: args.headRollupState,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
kind: "allowed",
|
|
28
|
+
basis: "merge-state",
|
|
29
|
+
mergeStateStatus: args.mergeStateStatus,
|
|
30
|
+
headRollupState: args.headRollupState,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
async function mergeAssessment(
|
|
34
|
+
reader: T.GitHubReader,
|
|
35
|
+
facts: T.PullRequestFacts
|
|
36
|
+
) {
|
|
37
|
+
const commits = await reader.commitRollups(facts.context);
|
|
38
|
+
const headRollupState =
|
|
39
|
+
facts.headRefOid === null
|
|
40
|
+
? null
|
|
41
|
+
: (commits.find((commit) => commit.oid === facts.headRefOid)?.state ??
|
|
42
|
+
null);
|
|
43
|
+
return {
|
|
44
|
+
hadPreviousPassingCi: commits.some(
|
|
45
|
+
(commit) => commit.oid !== facts.headRefOid && commit.state === "SUCCESS"
|
|
46
|
+
),
|
|
47
|
+
github: assessGitHubMerge({
|
|
48
|
+
mergeStateStatus: facts.mergeStateStatus,
|
|
49
|
+
headRollupState,
|
|
50
|
+
}),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
const AUTOMATION_TOKENS = [
|
|
54
|
+
"reviewer",
|
|
55
|
+
"security review",
|
|
56
|
+
"pr review automation",
|
|
57
|
+
"review automation",
|
|
58
|
+
] as const;
|
|
59
|
+
export async function readSnapshot(args: {
|
|
60
|
+
readonly reader: T.GitHubReader;
|
|
61
|
+
readonly context: T.PrContext;
|
|
62
|
+
readonly pendingHistory: "include" | "omit";
|
|
63
|
+
readonly allowDraft: boolean;
|
|
64
|
+
}): Promise<T.PrSnapshot> {
|
|
65
|
+
const facts = await args.reader.pullRequest(args.context);
|
|
66
|
+
if (facts.state === "MERGED" || facts.mergedAt !== null)
|
|
67
|
+
return { kind: "merged", context: args.context, facts };
|
|
68
|
+
if (facts.state === "CLOSED")
|
|
69
|
+
return { kind: "closed", context: args.context, facts };
|
|
70
|
+
const threads = await resolveReviewThreads(args.reader, args.context);
|
|
71
|
+
const checks = await resolveChecks(args.reader, args.context);
|
|
72
|
+
const failed = nonEmpty(
|
|
73
|
+
checks.checks.filter(
|
|
74
|
+
(check): check is T.FailedCheck => check.kind === "failed"
|
|
75
|
+
)
|
|
76
|
+
);
|
|
77
|
+
const pending = nonEmpty(
|
|
78
|
+
checks.checks.filter(
|
|
79
|
+
(check): check is T.PendingCheck => check.kind === "pending"
|
|
80
|
+
)
|
|
81
|
+
);
|
|
82
|
+
let ci: T.CiState;
|
|
83
|
+
if (failed === null && pending !== null && args.pendingHistory === "omit")
|
|
84
|
+
ci = {
|
|
85
|
+
kind: "ci-pending",
|
|
86
|
+
source: checks.source,
|
|
87
|
+
all: checks.checks,
|
|
88
|
+
failed: [],
|
|
89
|
+
pending,
|
|
90
|
+
hadPreviousPassingCi: false,
|
|
91
|
+
};
|
|
92
|
+
else {
|
|
93
|
+
const merge = await mergeAssessment(args.reader, facts);
|
|
94
|
+
const base = {
|
|
95
|
+
source: checks.source,
|
|
96
|
+
all: checks.checks,
|
|
97
|
+
hadPreviousPassingCi: merge.hadPreviousPassingCi,
|
|
98
|
+
};
|
|
99
|
+
if (failed !== null)
|
|
100
|
+
ci = {
|
|
101
|
+
...base,
|
|
102
|
+
kind: "ci-failing",
|
|
103
|
+
failed,
|
|
104
|
+
pending: pending ?? [],
|
|
105
|
+
github: merge.github,
|
|
106
|
+
};
|
|
107
|
+
else if (merge.github.kind === "refused")
|
|
108
|
+
ci = {
|
|
109
|
+
...base,
|
|
110
|
+
kind: "ci-github-rejected",
|
|
111
|
+
failed: [],
|
|
112
|
+
pending: pending ?? [],
|
|
113
|
+
github: merge.github,
|
|
114
|
+
};
|
|
115
|
+
else if (pending !== null)
|
|
116
|
+
ci = { ...base, kind: "ci-pending", failed: [], pending };
|
|
117
|
+
else
|
|
118
|
+
ci = {
|
|
119
|
+
...base,
|
|
120
|
+
kind: "ci-clean",
|
|
121
|
+
failed: [],
|
|
122
|
+
pending: [],
|
|
123
|
+
github: merge.github,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
kind: "open",
|
|
128
|
+
context: args.context,
|
|
129
|
+
facts,
|
|
130
|
+
threads,
|
|
131
|
+
ci,
|
|
132
|
+
reviewAutomationRunning: checks.checks.some(
|
|
133
|
+
(check) =>
|
|
134
|
+
check.kind === "pending" &&
|
|
135
|
+
AUTOMATION_TOKENS.some((token) =>
|
|
136
|
+
check.name.toLowerCase().includes(token)
|
|
137
|
+
)
|
|
138
|
+
),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
const conflictBlocker = (row: T.PrSnapshot): T.MergeBlocker | null =>
|
|
142
|
+
row.kind === "open" &&
|
|
143
|
+
(row.facts.mergeable === "CONFLICTING" ||
|
|
144
|
+
row.facts.mergeStateStatus === "DIRTY" ||
|
|
145
|
+
row.facts.mergeStateStatus === "CONFLICTING")
|
|
146
|
+
? { kind: "merge-conflicts", pr: row.context, facts: row.facts }
|
|
147
|
+
: null;
|
|
148
|
+
function threadBlocker(row: T.PrSnapshot): T.MergeBlocker | null {
|
|
149
|
+
if (row.kind !== "open") return null;
|
|
150
|
+
const threads = nonEmpty(row.threads);
|
|
151
|
+
return threads === null
|
|
152
|
+
? null
|
|
153
|
+
: { kind: "review-threads", pr: row.context, threads };
|
|
154
|
+
}
|
|
155
|
+
const ciBlocker = (row: T.PrSnapshot): T.MergeBlocker | null =>
|
|
156
|
+
row.kind === "open" &&
|
|
157
|
+
(row.ci.kind === "ci-failing" || row.ci.kind === "ci-github-rejected")
|
|
158
|
+
? { kind: "failing-checks", pr: row.context, ci: row.ci }
|
|
159
|
+
: null;
|
|
160
|
+
function gateReason(
|
|
161
|
+
row: T.PrSnapshot,
|
|
162
|
+
allowDraft: boolean
|
|
163
|
+
): T.MergeGateReason | null {
|
|
164
|
+
if (row.kind === "merged") return null;
|
|
165
|
+
if (row.kind === "closed") return "closed-without-merge";
|
|
166
|
+
if (row.facts.isDraft && !allowDraft) return "draft-pr";
|
|
167
|
+
return row.facts.reviewDecision === "CHANGES_REQUESTED"
|
|
168
|
+
? "changes-requested"
|
|
169
|
+
: null;
|
|
170
|
+
}
|
|
171
|
+
function gateBlocker(
|
|
172
|
+
row: T.PrSnapshot,
|
|
173
|
+
allowDraft: boolean
|
|
174
|
+
): T.MergeBlocker | null {
|
|
175
|
+
const reason = gateReason(row, allowDraft);
|
|
176
|
+
return reason === null ||
|
|
177
|
+
(reason === "draft-pr" &&
|
|
178
|
+
row.kind === "open" &&
|
|
179
|
+
row.ci.kind === "ci-pending")
|
|
180
|
+
? null
|
|
181
|
+
: { kind: "merge-gate", pr: row.context, reason };
|
|
182
|
+
}
|
|
183
|
+
function readyContribution(
|
|
184
|
+
row: T.PrSnapshot,
|
|
185
|
+
allowDraft: boolean
|
|
186
|
+
): T.ReadyPr | T.MergedPr | null {
|
|
187
|
+
if (row.kind === "merged")
|
|
188
|
+
return {
|
|
189
|
+
kind: "merged-pr",
|
|
190
|
+
context: row.context,
|
|
191
|
+
mergedAt: row.facts.mergedAt,
|
|
192
|
+
};
|
|
193
|
+
if (
|
|
194
|
+
row.kind !== "open" ||
|
|
195
|
+
row.ci.kind !== "ci-clean" ||
|
|
196
|
+
row.threads.length !== 0 ||
|
|
197
|
+
conflictBlocker(row) !== null ||
|
|
198
|
+
gateReason(row, allowDraft) !== null
|
|
199
|
+
)
|
|
200
|
+
return null;
|
|
201
|
+
const reviewDecision = row.facts.reviewDecision;
|
|
202
|
+
if (reviewDecision === "CHANGES_REQUESTED") return null;
|
|
203
|
+
return {
|
|
204
|
+
kind: "ready-pr",
|
|
205
|
+
context: row.context,
|
|
206
|
+
proof: {
|
|
207
|
+
mergeability: "clear",
|
|
208
|
+
threads: [],
|
|
209
|
+
ci: row.ci,
|
|
210
|
+
gate: {
|
|
211
|
+
state: "OPEN",
|
|
212
|
+
reviewDecision,
|
|
213
|
+
draft: row.facts.isDraft ? "draft-allowed" : "not-draft",
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
export function classifyPr(
|
|
219
|
+
row: T.PrSnapshot,
|
|
220
|
+
allowDraft = false
|
|
221
|
+
): T.PrDecision {
|
|
222
|
+
for (const blocker of [
|
|
223
|
+
conflictBlocker(row),
|
|
224
|
+
threadBlocker(row),
|
|
225
|
+
ciBlocker(row),
|
|
226
|
+
gateBlocker(row, allowDraft),
|
|
227
|
+
])
|
|
228
|
+
if (blocker !== null) return { kind: "blocker", blocker };
|
|
229
|
+
if (row.kind === "open" && row.ci.kind === "ci-pending")
|
|
230
|
+
return { kind: "waiting", frontier: row.context, pending: row.ci.pending };
|
|
231
|
+
const ready = readyContribution(row, allowDraft);
|
|
232
|
+
if (ready === null) throw new Error("snapshot has no classified decision");
|
|
233
|
+
return ready.kind === "merged-pr"
|
|
234
|
+
? { kind: "merged", pr: ready }
|
|
235
|
+
: { kind: "ready", pr: ready };
|
|
236
|
+
}
|
|
237
|
+
export function selectTierMajorStackDecision(
|
|
238
|
+
rows: T.NonEmpty<T.PrSnapshot>,
|
|
239
|
+
allowDraft = false
|
|
240
|
+
): T.StackDecision {
|
|
241
|
+
for (const tier of [conflictBlocker, threadBlocker, ciBlocker])
|
|
242
|
+
for (const row of rows) {
|
|
243
|
+
const blocker = tier(row);
|
|
244
|
+
if (blocker !== null) return { kind: "blocker", blocker };
|
|
245
|
+
}
|
|
246
|
+
for (const row of rows) {
|
|
247
|
+
const blocker = gateBlocker(row, allowDraft);
|
|
248
|
+
if (blocker !== null) return { kind: "blocker", blocker };
|
|
249
|
+
}
|
|
250
|
+
for (const row of rows)
|
|
251
|
+
if (row.kind === "open" && row.ci.kind === "ci-pending")
|
|
252
|
+
return {
|
|
253
|
+
kind: "waiting",
|
|
254
|
+
frontier: row.context,
|
|
255
|
+
pending: row.ci.pending,
|
|
256
|
+
};
|
|
257
|
+
const prs = nonEmpty(
|
|
258
|
+
rows
|
|
259
|
+
.map((row) => readyContribution(row, allowDraft))
|
|
260
|
+
.filter((row): row is T.ReadyPr | T.MergedPr => row !== null)
|
|
261
|
+
);
|
|
262
|
+
if (prs === null || prs.length !== rows.length)
|
|
263
|
+
throw new Error("stack has no classified decision");
|
|
264
|
+
return { kind: "clear", prs };
|
|
265
|
+
}
|
|
266
|
+
export const queryBackoffSeconds = (
|
|
267
|
+
interval: number,
|
|
268
|
+
failures: number
|
|
269
|
+
): number => Math.min(Math.max(interval, 60) * 2 ** (failures - 1), 300);
|
|
270
|
+
interface Envelope<M extends T.WatchMode> {
|
|
271
|
+
readonly schemaVersion: 1;
|
|
272
|
+
readonly sequence: number;
|
|
273
|
+
readonly observedAt: string;
|
|
274
|
+
readonly mode: M;
|
|
275
|
+
}
|
|
276
|
+
type Payload<V> = V extends unknown
|
|
277
|
+
? Omit<V, keyof Envelope<T.WatchMode>>
|
|
278
|
+
: never;
|
|
279
|
+
type VerdictPayload = Payload<T.WatcherVerdict>;
|
|
280
|
+
export interface VerdictStamp<M extends T.WatchMode = T.WatchMode> {
|
|
281
|
+
<const P extends VerdictPayload>(payload: P): Envelope<M> & P;
|
|
282
|
+
<const P extends VerdictPayload, M2 extends T.WatchMode>(
|
|
283
|
+
payload: P,
|
|
284
|
+
mode: M2
|
|
285
|
+
): Envelope<M2> & P;
|
|
286
|
+
}
|
|
287
|
+
export function verdictFactory<M extends T.WatchMode>(
|
|
288
|
+
clock: WatchClock,
|
|
289
|
+
mode: M
|
|
290
|
+
): VerdictStamp<M> {
|
|
291
|
+
let sequence = 0;
|
|
292
|
+
function stamp<const P extends VerdictPayload>(payload: P): Envelope<M> & P;
|
|
293
|
+
function stamp<const P extends VerdictPayload, M2 extends T.WatchMode>(
|
|
294
|
+
payload: P,
|
|
295
|
+
mode: M2
|
|
296
|
+
): Envelope<M2> & P;
|
|
297
|
+
function stamp<const P extends VerdictPayload>(
|
|
298
|
+
payload: P,
|
|
299
|
+
override?: T.WatchMode
|
|
300
|
+
): Envelope<T.WatchMode> & P {
|
|
301
|
+
return {
|
|
302
|
+
schemaVersion: 1,
|
|
303
|
+
sequence: (sequence += 1),
|
|
304
|
+
observedAt: clock.observedAt(),
|
|
305
|
+
mode: override ?? mode,
|
|
306
|
+
...payload,
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
return stamp;
|
|
310
|
+
}
|
|
311
|
+
function blockerVerdict(
|
|
312
|
+
stamp: VerdictStamp,
|
|
313
|
+
blocker: T.MergeBlocker
|
|
314
|
+
): T.BlockerVerdict {
|
|
315
|
+
switch (blocker.kind) {
|
|
316
|
+
case "merge-conflicts":
|
|
317
|
+
return stamp({ kind: "BLOCKER", terminal: true, exitCode: 2, blocker });
|
|
318
|
+
case "review-threads":
|
|
319
|
+
return stamp({ kind: "BLOCKER", terminal: true, exitCode: 3, blocker });
|
|
320
|
+
case "failing-checks":
|
|
321
|
+
return stamp({ kind: "BLOCKER", terminal: true, exitCode: 4, blocker });
|
|
322
|
+
case "merge-gate":
|
|
323
|
+
return stamp({ kind: "BLOCKER", terminal: true, exitCode: 6, blocker });
|
|
324
|
+
default: {
|
|
325
|
+
const exhaustive: never = blocker;
|
|
326
|
+
return exhaustive;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
export function statusQueryVerdict(
|
|
331
|
+
stamp: VerdictStamp,
|
|
332
|
+
failures: number,
|
|
333
|
+
failure: T.QueryFailure
|
|
334
|
+
): T.BlockerVerdict {
|
|
335
|
+
return stamp({
|
|
336
|
+
kind: "BLOCKER",
|
|
337
|
+
terminal: true,
|
|
338
|
+
exitCode: 7,
|
|
339
|
+
blocker: { kind: "status-query", failures, failure },
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
export interface WatchClock {
|
|
343
|
+
now(): number;
|
|
344
|
+
observedAt(): string;
|
|
345
|
+
sleep(seconds: number): Promise<void>;
|
|
346
|
+
}
|
|
347
|
+
export interface RunDependencies {
|
|
348
|
+
readonly reader: T.GitHubReader;
|
|
349
|
+
readonly clock: WatchClock;
|
|
350
|
+
readonly emit: (verdict: T.ProgressVerdict) => void;
|
|
351
|
+
}
|
|
352
|
+
const deadlinePassed = (
|
|
353
|
+
started: number,
|
|
354
|
+
options: T.PollingOptions,
|
|
355
|
+
now: number
|
|
356
|
+
): boolean => options.timeout > 0 && now - started >= options.timeout;
|
|
357
|
+
type StepResult<V> =
|
|
358
|
+
| { readonly kind: "terminal"; readonly verdict: V }
|
|
359
|
+
| {
|
|
360
|
+
readonly kind: "sleep";
|
|
361
|
+
readonly seconds: number;
|
|
362
|
+
readonly onDeadline?: () => V;
|
|
363
|
+
}
|
|
364
|
+
| { readonly kind: "continue" };
|
|
365
|
+
async function pollUntilTerminal<V>(args: {
|
|
366
|
+
readonly dependencies: RunDependencies;
|
|
367
|
+
readonly options: T.PollingOptions;
|
|
368
|
+
readonly stamp: VerdictStamp;
|
|
369
|
+
readonly step: () => Promise<StepResult<V>>;
|
|
370
|
+
}): Promise<V | T.BlockerVerdict | T.TimeoutVerdict> {
|
|
371
|
+
let failures = 0;
|
|
372
|
+
const started = args.dependencies.clock.now();
|
|
373
|
+
while (true) {
|
|
374
|
+
let result: StepResult<V>;
|
|
375
|
+
try {
|
|
376
|
+
result = await args.step();
|
|
377
|
+
failures = 0;
|
|
378
|
+
} catch (error) {
|
|
379
|
+
if (!(error instanceof WatcherQueryError)) throw error;
|
|
380
|
+
failures += 1;
|
|
381
|
+
if (!error.failure.retryable || failures >= args.options.maxQueryErrors)
|
|
382
|
+
return statusQueryVerdict(args.stamp, failures, error.failure);
|
|
383
|
+
const retryInSeconds = queryBackoffSeconds(
|
|
384
|
+
args.options.interval,
|
|
385
|
+
failures
|
|
386
|
+
);
|
|
387
|
+
args.dependencies.emit(
|
|
388
|
+
args.stamp({
|
|
389
|
+
kind: "RETRY",
|
|
390
|
+
terminal: false,
|
|
391
|
+
failure: error.failure,
|
|
392
|
+
consecutiveFailures: failures,
|
|
393
|
+
retryInSeconds,
|
|
394
|
+
})
|
|
395
|
+
);
|
|
396
|
+
if (deadlinePassed(started, args.options, args.dependencies.clock.now()))
|
|
397
|
+
return args.stamp({
|
|
398
|
+
kind: "TIMEOUT",
|
|
399
|
+
terminal: true,
|
|
400
|
+
exitCode: 5,
|
|
401
|
+
reason: { kind: "status-unavailable", failure: error.failure },
|
|
402
|
+
});
|
|
403
|
+
await args.dependencies.clock.sleep(retryInSeconds);
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
if (result.kind === "terminal") return result.verdict;
|
|
407
|
+
if (result.kind === "sleep") {
|
|
408
|
+
if (
|
|
409
|
+
result.onDeadline !== undefined &&
|
|
410
|
+
deadlinePassed(started, args.options, args.dependencies.clock.now())
|
|
411
|
+
)
|
|
412
|
+
return result.onDeadline();
|
|
413
|
+
await args.dependencies.clock.sleep(result.seconds);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
export async function runSimple(args: {
|
|
418
|
+
readonly dependencies: RunDependencies;
|
|
419
|
+
readonly contexts: T.NonEmpty<T.PrContext>;
|
|
420
|
+
readonly mode: T.WatchMode;
|
|
421
|
+
readonly statusOnly: boolean;
|
|
422
|
+
readonly options: T.PollingOptions;
|
|
423
|
+
}): Promise<T.TerminalVerdict> {
|
|
424
|
+
const stamp = verdictFactory(args.dependencies.clock, args.mode);
|
|
425
|
+
const step = async (): Promise<StepResult<T.TerminalVerdict>> => {
|
|
426
|
+
const rows: T.PrSnapshot[] = [];
|
|
427
|
+
for (const context of args.contexts)
|
|
428
|
+
rows.push(
|
|
429
|
+
await readSnapshot({
|
|
430
|
+
reader: args.dependencies.reader,
|
|
431
|
+
context,
|
|
432
|
+
pendingHistory: "include",
|
|
433
|
+
allowDraft: args.options.allowDraft,
|
|
434
|
+
})
|
|
435
|
+
);
|
|
436
|
+
const complete = nonEmpty(rows);
|
|
437
|
+
if (complete === null) throw new Error("watch context cannot be empty");
|
|
438
|
+
if (args.statusOnly)
|
|
439
|
+
return {
|
|
440
|
+
kind: "terminal",
|
|
441
|
+
verdict: stamp({
|
|
442
|
+
kind: "STATUS",
|
|
443
|
+
terminal: true,
|
|
444
|
+
exitCode: 0,
|
|
445
|
+
reason: "status-only",
|
|
446
|
+
rows: complete,
|
|
447
|
+
}),
|
|
448
|
+
};
|
|
449
|
+
if (args.mode === "queued-stack")
|
|
450
|
+
throw new Error("queued-stack requires status-only in the simple runner");
|
|
451
|
+
if (args.mode === "stack")
|
|
452
|
+
args.dependencies.emit(
|
|
453
|
+
stamp(
|
|
454
|
+
{ kind: "STATUS", terminal: false, reason: "poll", rows: complete },
|
|
455
|
+
args.mode
|
|
456
|
+
)
|
|
457
|
+
);
|
|
458
|
+
const decision =
|
|
459
|
+
args.mode === "single"
|
|
460
|
+
? classifyPr(complete[0], args.options.allowDraft)
|
|
461
|
+
: selectTierMajorStackDecision(complete, args.options.allowDraft);
|
|
462
|
+
if (decision.kind === "blocker")
|
|
463
|
+
return {
|
|
464
|
+
kind: "terminal",
|
|
465
|
+
verdict: blockerVerdict(stamp, decision.blocker),
|
|
466
|
+
};
|
|
467
|
+
if (decision.kind === "ready" || decision.kind === "merged")
|
|
468
|
+
return {
|
|
469
|
+
kind: "terminal",
|
|
470
|
+
verdict: stamp(
|
|
471
|
+
{
|
|
472
|
+
kind: "READY",
|
|
473
|
+
terminal: true,
|
|
474
|
+
exitCode: 0,
|
|
475
|
+
scope: { kind: "single", pr: decision.pr },
|
|
476
|
+
},
|
|
477
|
+
args.mode
|
|
478
|
+
),
|
|
479
|
+
};
|
|
480
|
+
if (decision.kind === "clear")
|
|
481
|
+
return {
|
|
482
|
+
kind: "terminal",
|
|
483
|
+
verdict: stamp(
|
|
484
|
+
{
|
|
485
|
+
kind: "READY",
|
|
486
|
+
terminal: true,
|
|
487
|
+
exitCode: 0,
|
|
488
|
+
scope: { kind: "stack", prs: decision.prs },
|
|
489
|
+
},
|
|
490
|
+
args.mode
|
|
491
|
+
),
|
|
492
|
+
};
|
|
493
|
+
args.dependencies.emit(
|
|
494
|
+
stamp({
|
|
495
|
+
kind: "WAITING",
|
|
496
|
+
terminal: false,
|
|
497
|
+
frontier: decision.frontier,
|
|
498
|
+
reason: { kind: "pending-checks", pending: decision.pending },
|
|
499
|
+
})
|
|
500
|
+
);
|
|
501
|
+
return {
|
|
502
|
+
kind: "sleep",
|
|
503
|
+
seconds: args.options.interval,
|
|
504
|
+
onDeadline: () =>
|
|
505
|
+
stamp({
|
|
506
|
+
kind: "TIMEOUT",
|
|
507
|
+
terminal: true,
|
|
508
|
+
exitCode: 5,
|
|
509
|
+
reason: { kind: "pending-checks", pending: decision.pending },
|
|
510
|
+
}),
|
|
511
|
+
};
|
|
512
|
+
};
|
|
513
|
+
return pollUntilTerminal({
|
|
514
|
+
dependencies: args.dependencies,
|
|
515
|
+
options: args.options,
|
|
516
|
+
stamp,
|
|
517
|
+
step,
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
export type QueueWork =
|
|
521
|
+
| {
|
|
522
|
+
readonly kind: "whole-stack-sweep";
|
|
523
|
+
readonly remaining: T.NonEmpty<T.PrContext>;
|
|
524
|
+
}
|
|
525
|
+
| { readonly kind: "frontier-poll"; readonly frontier: T.PrContext };
|
|
526
|
+
export interface QueueState {
|
|
527
|
+
readonly queue: T.NonEmpty<T.PrContext>;
|
|
528
|
+
readonly snapshots: ReadonlyMap<T.PrNumber, T.PrSnapshot>;
|
|
529
|
+
readonly work: QueueWork | null;
|
|
530
|
+
readonly nextSweepAt: number;
|
|
531
|
+
readonly frontier: T.PrContext | null;
|
|
532
|
+
readonly lastWaitKey: string | null;
|
|
533
|
+
readonly startedAt: number;
|
|
534
|
+
}
|
|
535
|
+
export const createQueueState = (
|
|
536
|
+
queue: T.NonEmpty<T.PrContext>,
|
|
537
|
+
now: number
|
|
538
|
+
): QueueState => ({
|
|
539
|
+
queue,
|
|
540
|
+
snapshots: new Map(),
|
|
541
|
+
work: { kind: "whole-stack-sweep", remaining: queue },
|
|
542
|
+
nextSweepAt: now,
|
|
543
|
+
frontier: null,
|
|
544
|
+
lastWaitKey: null,
|
|
545
|
+
startedAt: now,
|
|
546
|
+
});
|
|
547
|
+
const orderedRows = (state: QueueState): T.PrSnapshot[] =>
|
|
548
|
+
state.queue.flatMap((context) => {
|
|
549
|
+
const row = state.snapshots.get(context.number);
|
|
550
|
+
return row === undefined ? [] : [row];
|
|
551
|
+
});
|
|
552
|
+
const activeRows = (state: QueueState): T.PrSnapshot[] =>
|
|
553
|
+
orderedRows(state).filter((row) => row.kind !== "merged");
|
|
554
|
+
export function planQueue(state: QueueState, now: number): QueueState {
|
|
555
|
+
if (state.work !== null) return state;
|
|
556
|
+
if (state.snapshots.size === 0 || now >= state.nextSweepAt) {
|
|
557
|
+
const remaining = nonEmpty(
|
|
558
|
+
state.queue.filter(
|
|
559
|
+
(context) => state.snapshots.get(context.number)?.kind !== "merged"
|
|
560
|
+
)
|
|
561
|
+
);
|
|
562
|
+
if (remaining !== null)
|
|
563
|
+
return { ...state, work: { kind: "whole-stack-sweep", remaining } };
|
|
564
|
+
}
|
|
565
|
+
const frontier = activeRows(state)[0]?.context;
|
|
566
|
+
return frontier === undefined
|
|
567
|
+
? state
|
|
568
|
+
: { ...state, work: { kind: "frontier-poll", frontier } };
|
|
569
|
+
}
|
|
570
|
+
export interface QueueSnapshotResult {
|
|
571
|
+
readonly state: QueueState;
|
|
572
|
+
readonly completedSweepRows: T.NonEmpty<T.PrSnapshot> | null;
|
|
573
|
+
}
|
|
574
|
+
export function applyQueueSnapshot(
|
|
575
|
+
state: QueueState,
|
|
576
|
+
snapshot: T.PrSnapshot,
|
|
577
|
+
now: number,
|
|
578
|
+
options: T.PollingOptions
|
|
579
|
+
): QueueSnapshotResult {
|
|
580
|
+
if (state.work === null) throw new Error("queue has no read in flight");
|
|
581
|
+
const snapshots = new Map(state.snapshots);
|
|
582
|
+
snapshots.set(snapshot.context.number, snapshot);
|
|
583
|
+
const base = { ...state, snapshots };
|
|
584
|
+
if (state.work.kind === "frontier-poll")
|
|
585
|
+
return { state: { ...base, work: null }, completedSweepRows: null };
|
|
586
|
+
const [head, ...tail] = state.work.remaining;
|
|
587
|
+
if (head.number !== snapshot.context.number)
|
|
588
|
+
throw new Error("snapshot does not match sweep head");
|
|
589
|
+
const remaining = nonEmpty(tail);
|
|
590
|
+
if (remaining !== null)
|
|
591
|
+
return {
|
|
592
|
+
state: { ...base, work: { kind: "whole-stack-sweep", remaining } },
|
|
593
|
+
completedSweepRows: null,
|
|
594
|
+
};
|
|
595
|
+
const rows = nonEmpty(
|
|
596
|
+
state.queue.flatMap((context) => {
|
|
597
|
+
const row = snapshots.get(context.number);
|
|
598
|
+
return row === undefined ? [] : [row];
|
|
599
|
+
})
|
|
600
|
+
);
|
|
601
|
+
if (rows === null || rows.length !== state.queue.length)
|
|
602
|
+
throw new Error("sweep completed without every snapshot");
|
|
603
|
+
return {
|
|
604
|
+
state: { ...base, work: null, nextSweepAt: now + options.sweepInterval },
|
|
605
|
+
completedSweepRows: rows,
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
export type QueueEvaluation =
|
|
609
|
+
| {
|
|
610
|
+
readonly kind: "complete";
|
|
611
|
+
readonly state: QueueState;
|
|
612
|
+
readonly merged: T.NonEmpty<T.MergedPr>;
|
|
613
|
+
}
|
|
614
|
+
| {
|
|
615
|
+
readonly kind: "blocker";
|
|
616
|
+
readonly state: QueueState;
|
|
617
|
+
readonly blocker: T.MergeBlocker;
|
|
618
|
+
}
|
|
619
|
+
| {
|
|
620
|
+
readonly kind: "advance";
|
|
621
|
+
readonly state: QueueState;
|
|
622
|
+
readonly merged: T.PrContext;
|
|
623
|
+
readonly frontier: T.PrContext;
|
|
624
|
+
readonly remaining: number;
|
|
625
|
+
}
|
|
626
|
+
| {
|
|
627
|
+
readonly kind: "timeout";
|
|
628
|
+
readonly state: QueueState;
|
|
629
|
+
readonly frontier: T.PrContext;
|
|
630
|
+
readonly unmergedCount: number;
|
|
631
|
+
}
|
|
632
|
+
| {
|
|
633
|
+
readonly kind: "waiting";
|
|
634
|
+
readonly state: QueueState;
|
|
635
|
+
readonly frontier: T.PrContext;
|
|
636
|
+
readonly reason:
|
|
637
|
+
| {
|
|
638
|
+
readonly kind: "pending-checks";
|
|
639
|
+
readonly pending: T.NonEmpty<T.PendingCheck>;
|
|
640
|
+
}
|
|
641
|
+
| { readonly kind: "merge-queue"; readonly unmergedCount: number };
|
|
642
|
+
readonly emit: boolean;
|
|
643
|
+
};
|
|
644
|
+
export function evaluateQueue(
|
|
645
|
+
state: QueueState,
|
|
646
|
+
now: number,
|
|
647
|
+
options: T.PollingOptions
|
|
648
|
+
): QueueEvaluation {
|
|
649
|
+
const active = activeRows(state);
|
|
650
|
+
if (active.length === 0) {
|
|
651
|
+
const merged = nonEmpty(
|
|
652
|
+
orderedRows(state).flatMap((row) =>
|
|
653
|
+
row.kind === "merged"
|
|
654
|
+
? [
|
|
655
|
+
{
|
|
656
|
+
kind: "merged-pr" as const,
|
|
657
|
+
context: row.context,
|
|
658
|
+
mergedAt: row.facts.mergedAt,
|
|
659
|
+
},
|
|
660
|
+
]
|
|
661
|
+
: []
|
|
662
|
+
)
|
|
663
|
+
);
|
|
664
|
+
if (merged === null) throw new Error("empty queue cannot complete");
|
|
665
|
+
return { kind: "complete", state, merged };
|
|
666
|
+
}
|
|
667
|
+
const rows = nonEmpty(active);
|
|
668
|
+
if (rows === null) throw new Error("active queue cannot be empty");
|
|
669
|
+
const decision = selectTierMajorStackDecision(rows, options.allowDraft);
|
|
670
|
+
if (decision.kind === "blocker")
|
|
671
|
+
return { kind: "blocker", state, blocker: decision.blocker };
|
|
672
|
+
const frontier = rows[0].context;
|
|
673
|
+
if (state.frontier !== null && state.frontier.number !== frontier.number)
|
|
674
|
+
return {
|
|
675
|
+
kind: "advance",
|
|
676
|
+
state: { ...state, frontier, lastWaitKey: null },
|
|
677
|
+
merged: state.frontier,
|
|
678
|
+
frontier,
|
|
679
|
+
remaining: active.length,
|
|
680
|
+
};
|
|
681
|
+
if (deadlinePassed(state.startedAt, options, now))
|
|
682
|
+
return {
|
|
683
|
+
kind: "timeout",
|
|
684
|
+
state: { ...state, frontier },
|
|
685
|
+
frontier,
|
|
686
|
+
unmergedCount: active.length,
|
|
687
|
+
};
|
|
688
|
+
const row = rows[0];
|
|
689
|
+
const pending =
|
|
690
|
+
row.kind === "open" && row.ci.kind === "ci-pending" ? row.ci.pending : null;
|
|
691
|
+
const reason =
|
|
692
|
+
pending === null
|
|
693
|
+
? ({ kind: "merge-queue", unmergedCount: active.length } as const)
|
|
694
|
+
: ({ kind: "pending-checks", pending } as const);
|
|
695
|
+
const key =
|
|
696
|
+
reason.kind === "pending-checks"
|
|
697
|
+
? `pending:${frontier.number}:${reason.pending.length}`
|
|
698
|
+
: `queue:${frontier.number}:${reason.unmergedCount}`;
|
|
699
|
+
return {
|
|
700
|
+
kind: "waiting",
|
|
701
|
+
state: { ...state, frontier, lastWaitKey: key },
|
|
702
|
+
frontier,
|
|
703
|
+
reason,
|
|
704
|
+
emit: state.lastWaitKey !== key,
|
|
705
|
+
};
|
|
706
|
+
}
|
|
707
|
+
export async function runQueued(args: {
|
|
708
|
+
readonly dependencies: RunDependencies;
|
|
709
|
+
readonly contexts: T.NonEmpty<T.PrContext>;
|
|
710
|
+
readonly options: T.PollingOptions;
|
|
711
|
+
}): Promise<T.QueueTerminalVerdict> {
|
|
712
|
+
let state = createQueueState(args.contexts, args.dependencies.clock.now());
|
|
713
|
+
const stamp = verdictFactory(args.dependencies.clock, "queued-stack");
|
|
714
|
+
args.dependencies.emit(
|
|
715
|
+
stamp({ kind: "QUEUE", terminal: false, queue: args.contexts })
|
|
716
|
+
);
|
|
717
|
+
const step = async (): Promise<StepResult<T.QueueTerminalVerdict>> => {
|
|
718
|
+
state = planQueue(state, args.dependencies.clock.now());
|
|
719
|
+
if (state.work === null) {
|
|
720
|
+
const complete = evaluateQueue(
|
|
721
|
+
state,
|
|
722
|
+
args.dependencies.clock.now(),
|
|
723
|
+
args.options
|
|
724
|
+
);
|
|
725
|
+
if (complete.kind !== "complete")
|
|
726
|
+
throw new Error("queue has no work while active");
|
|
727
|
+
return {
|
|
728
|
+
kind: "terminal",
|
|
729
|
+
verdict: stamp({
|
|
730
|
+
kind: "COMPLETE",
|
|
731
|
+
terminal: true,
|
|
732
|
+
exitCode: 0,
|
|
733
|
+
queue: state.queue,
|
|
734
|
+
merged: complete.merged,
|
|
735
|
+
}),
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
const context =
|
|
739
|
+
state.work.kind === "whole-stack-sweep"
|
|
740
|
+
? state.work.remaining[0]
|
|
741
|
+
: state.work.frontier;
|
|
742
|
+
const snapshot = await readSnapshot({
|
|
743
|
+
reader: args.dependencies.reader,
|
|
744
|
+
context,
|
|
745
|
+
pendingHistory: "omit",
|
|
746
|
+
allowDraft: args.options.allowDraft,
|
|
747
|
+
});
|
|
748
|
+
const applied = applyQueueSnapshot(
|
|
749
|
+
state,
|
|
750
|
+
snapshot,
|
|
751
|
+
args.dependencies.clock.now(),
|
|
752
|
+
args.options
|
|
753
|
+
);
|
|
754
|
+
state = applied.state;
|
|
755
|
+
if (applied.completedSweepRows !== null)
|
|
756
|
+
args.dependencies.emit(
|
|
757
|
+
stamp({
|
|
758
|
+
kind: "STATUS",
|
|
759
|
+
terminal: false,
|
|
760
|
+
reason: "whole-stack-sweep",
|
|
761
|
+
rows: applied.completedSweepRows,
|
|
762
|
+
})
|
|
763
|
+
);
|
|
764
|
+
if (state.work !== null) return { kind: "continue" };
|
|
765
|
+
const evaluation = evaluateQueue(
|
|
766
|
+
state,
|
|
767
|
+
args.dependencies.clock.now(),
|
|
768
|
+
args.options
|
|
769
|
+
);
|
|
770
|
+
state = evaluation.state;
|
|
771
|
+
switch (evaluation.kind) {
|
|
772
|
+
case "complete":
|
|
773
|
+
return {
|
|
774
|
+
kind: "terminal",
|
|
775
|
+
verdict: stamp({
|
|
776
|
+
kind: "COMPLETE",
|
|
777
|
+
terminal: true,
|
|
778
|
+
exitCode: 0,
|
|
779
|
+
queue: state.queue,
|
|
780
|
+
merged: evaluation.merged,
|
|
781
|
+
}),
|
|
782
|
+
};
|
|
783
|
+
case "blocker":
|
|
784
|
+
return {
|
|
785
|
+
kind: "terminal",
|
|
786
|
+
verdict: blockerVerdict(stamp, evaluation.blocker),
|
|
787
|
+
};
|
|
788
|
+
case "advance":
|
|
789
|
+
args.dependencies.emit(
|
|
790
|
+
stamp({
|
|
791
|
+
kind: "ADVANCE",
|
|
792
|
+
terminal: false,
|
|
793
|
+
merged: evaluation.merged,
|
|
794
|
+
frontier: evaluation.frontier,
|
|
795
|
+
remaining: evaluation.remaining,
|
|
796
|
+
})
|
|
797
|
+
);
|
|
798
|
+
return { kind: "continue" };
|
|
799
|
+
case "timeout":
|
|
800
|
+
return {
|
|
801
|
+
kind: "terminal",
|
|
802
|
+
verdict: stamp({
|
|
803
|
+
kind: "TIMEOUT",
|
|
804
|
+
terminal: true,
|
|
805
|
+
exitCode: 5,
|
|
806
|
+
reason: {
|
|
807
|
+
kind: "queued-stack",
|
|
808
|
+
frontier: evaluation.frontier,
|
|
809
|
+
unmergedCount: evaluation.unmergedCount,
|
|
810
|
+
},
|
|
811
|
+
}),
|
|
812
|
+
};
|
|
813
|
+
case "waiting":
|
|
814
|
+
if (evaluation.emit)
|
|
815
|
+
args.dependencies.emit(
|
|
816
|
+
stamp({
|
|
817
|
+
kind: "WAITING",
|
|
818
|
+
terminal: false,
|
|
819
|
+
frontier: evaluation.frontier,
|
|
820
|
+
reason: evaluation.reason,
|
|
821
|
+
})
|
|
822
|
+
);
|
|
823
|
+
return { kind: "sleep", seconds: args.options.interval };
|
|
824
|
+
default: {
|
|
825
|
+
const exhaustive: never = evaluation;
|
|
826
|
+
return exhaustive;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
};
|
|
830
|
+
return pollUntilTerminal({
|
|
831
|
+
dependencies: args.dependencies,
|
|
832
|
+
options: args.options,
|
|
833
|
+
stamp,
|
|
834
|
+
step,
|
|
835
|
+
});
|
|
836
|
+
}
|