@rt-tools/agent-kit 0.37.1 → 0.39.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/README.md +5 -5
- package/assets/checks/action-of.mjs +154 -0
- package/assets/checks/board-runs.github.mjs +40 -5
- package/assets/checks/check-board.github.mjs +38 -7
- package/assets/checks/check-state-next.mjs +22 -10
- package/assets/checks/check-turn-map.mjs +26 -6
- package/assets/checks/check-work-steps.mjs +4 -173
- package/assets/checks/decide.mjs +285 -0
- package/assets/checks/decision-table.json +21432 -0
- package/assets/checks/decision-table.mjs +495 -0
- package/assets/checks/epic-window.mjs +98 -0
- package/assets/checks/flow-condition.mjs +64 -0
- package/assets/checks/flow-data.mjs +135 -0
- package/assets/checks/flow-forecast.mjs +334 -0
- package/assets/checks/flow-guard-run.mjs +90 -0
- package/assets/checks/flow-guard.mjs +496 -0
- package/assets/checks/flow-model.mjs +271 -0
- package/assets/checks/flow-override.mjs +130 -0
- package/assets/checks/flow-plan.mjs +206 -0
- package/assets/checks/flow-scaffold.mjs +224 -0
- package/assets/checks/flow-step.mjs +495 -0
- package/assets/checks/flow-sync.mjs +296 -0
- package/assets/checks/flow-syntax.mjs +292 -0
- package/assets/checks/flow-verdict.mjs +227 -0
- package/assets/checks/merge-read.mjs +239 -0
- package/assets/checks/owner-nudges.mjs +389 -0
- package/assets/checks/push-inputs.mjs +59 -16
- package/assets/checks/record-count.mjs +437 -0
- package/assets/checks/record-recount.mjs +187 -0
- package/assets/checks/record-turn.mjs +155 -0
- package/assets/checks/task-flow-script.mjs +318 -0
- package/assets/checks/tree-assignment.mjs +26 -7
- package/assets/checks/work-result.mjs +362 -0
- package/assets/checks/work-steps-lib.mjs +205 -0
- package/assets/commands/night.md +6 -6
- package/assets/defaults/gate-map.sh +39 -12
- package/assets/defaults/merges.sh +48 -0
- package/assets/defaults/project.sh +6 -5
- package/assets/defaults/turn-map.md +23 -22
- package/assets/docs/GLOSSARY.md +5 -1
- package/assets/hooks/ask-judge.md +67 -0
- package/assets/hooks/browser-guard-device-id.sh +11 -9
- package/assets/hooks/browser-guard-no-asking.sh +12 -6
- package/assets/hooks/browser-guard-no-listing.sh +13 -7
- package/assets/hooks/browser-guard-no-other-drivers.sh +25 -17
- package/assets/hooks/browser-guard-require-select.sh +15 -15
- package/assets/hooks/commit-msg.sh +13 -3
- package/assets/hooks/conscience-guard.sh +9 -25
- package/assets/hooks/decide.sh +141 -0
- package/assets/hooks/deny-tail.sh +16 -11
- package/assets/hooks/dev-server-guard.sh +27 -20
- package/assets/hooks/dispatch.sh +47 -4
- package/assets/hooks/docs-guard.sh +31 -200
- package/assets/hooks/end-conversation-guard.sh +12 -21
- package/assets/hooks/epic-stop-guard.sh +54 -152
- package/assets/hooks/exam-guard.sh +32 -65
- package/assets/hooks/facts-docs.sh +221 -0
- package/assets/hooks/facts-flow.sh +173 -0
- package/assets/hooks/facts.sh +374 -0
- package/assets/hooks/flow-step-guard.sh +93 -0
- package/assets/hooks/git-guard-delivery-body.sh +4 -4
- package/assets/hooks/git-guard-delivery-conflict.sh +16 -10
- package/assets/hooks/git-guard-delivery-draft.sh +3 -3
- package/assets/hooks/git-guard-delivery-epic.sh +18 -9
- package/assets/hooks/git-guard-delivery-folder.sh +32 -7
- package/assets/hooks/git-guard-delivery-merge.sh +2 -2
- package/assets/hooks/git-guard-delivery-merged.sh +12 -1
- package/assets/hooks/git-guard-delivery-pipeline.sh +1 -1
- package/assets/hooks/git-guard-delivery-rerun.sh +44 -0
- package/assets/hooks/git-guard-delivery-signature.sh +82 -45
- package/assets/hooks/git-guard-delivery-task.sh +47 -0
- package/assets/hooks/git-guard-delivery.sh +112 -101
- package/assets/hooks/git-guard-discard.sh +8 -18
- package/assets/hooks/git-guard-main.sh +13 -19
- package/assets/hooks/git-guard-no-verify.sh +56 -16
- package/assets/hooks/git-guard-push-ahead.sh +39 -6
- package/assets/hooks/git-guard-push-marks.sh +262 -13
- package/assets/hooks/git-guard-push-tests.sh +58 -52
- package/assets/hooks/git-guard-tree-assignment.sh +7 -4
- package/assets/hooks/guard-note.sh +8 -6
- package/assets/hooks/handoff-entry-guard.sh +19 -38
- package/assets/hooks/handoff-write.sh +3 -1
- package/assets/hooks/hook-input.sh +0 -41
- package/assets/hooks/metric-marks.sh +19 -7
- package/assets/hooks/observe.sh +1 -1
- package/assets/hooks/override-write-guard.sh +27 -9
- package/assets/hooks/pre-push.sh +40 -12
- package/assets/hooks/prose-style-guard.sh +6 -19
- package/assets/hooks/pull-merges.sh +76 -0
- package/assets/hooks/push-ahead-call-guard.sh +447 -0
- package/assets/hooks/push-set.sh +38 -8
- package/assets/hooks/qa-dataid-guard.sh +7 -17
- package/assets/hooks/record-turn.sh +52 -0
- package/assets/hooks/rerun-guard.sh +11 -16
- package/assets/hooks/reuse-first-guard.sh +7 -21
- package/assets/hooks/role-calls.sh +25 -3
- package/assets/hooks/rule-source-guard.sh +54 -21
- package/assets/hooks/skill-gate-rearm.sh +18 -5
- package/assets/hooks/skill-gate.sh +156 -20
- package/assets/hooks/skill-loaded.sh +18 -3
- package/assets/hooks/sql-guard-target.sh +2 -2
- package/assets/hooks/sql-guard-write.sh +12 -12
- package/assets/hooks/sql-guard.sh +58 -16
- package/assets/hooks/task-context-load.sh +3 -1
- package/assets/hooks/task-flow-context.sh +5 -18
- package/assets/hooks/task-flow-draft-guard.sh +25 -74
- package/assets/hooks/task-flow-guard.sh +28 -130
- package/assets/hooks/tree-assignment-guard.sh +25 -14
- package/assets/hooks/turn-entry-load.sh +3 -1
- package/assets/hooks/turn-exit-guard.sh +92 -452
- package/assets/hooks/turn-exit-role.sh +3 -1
- package/assets/hooks/turn-judge.md +113 -0
- package/assets/hooks/window-fill-guard.sh +22 -41
- package/assets/patterns/doc-style-human.md +36 -76
- package/assets/patterns/git-workflow-commit.azure.md +9 -155
- package/assets/patterns/git-workflow-commit.github.md +11 -269
- package/assets/patterns/git-workflow-commit.gitlab.md +9 -161
- package/assets/patterns/git-workflow-docker.md +8 -231
- package/assets/patterns/git-workflow-freshness.md +8 -56
- package/assets/patterns/git-workflow-merge.md +6 -176
- package/assets/patterns/git-workflow-migration.md +5 -75
- package/assets/patterns/git-workflow-pr-body.github.md +6 -159
- package/assets/patterns/git-workflow-pr-ready.md +9 -70
- package/assets/patterns/git-workflow-pr.azure.md +13 -285
- package/assets/patterns/git-workflow-pr.github.md +13 -251
- package/assets/patterns/git-workflow-pr.gitlab.md +13 -286
- package/assets/patterns/git-workflow-restart.md +5 -42
- package/assets/patterns/git-workflow-secrets.md +10 -76
- package/assets/patterns/git-workflow-stack.md +7 -207
- package/assets/patterns/status-report-table.github.md +1 -1
- package/assets/patterns/task-flow-archive.md +12 -233
- package/assets/patterns/task-flow-close.md +16 -292
- package/assets/patterns/task-flow-cycle.md +13 -39
- package/assets/patterns/task-flow-graph.needs-graph.md +8 -62
- package/assets/patterns/task-flow-handoff.md +13 -161
- package/assets/patterns/task-flow-resume.md +18 -218
- package/assets/patterns/task-flow-start.md +9 -247
- package/assets/patterns/turn-entry-map.md +2 -2
- package/assets/pitfalls/agent-kit-extend.md +200 -0
- package/assets/pitfalls/agent-kit.2.md +323 -0
- package/assets/pitfalls/angular-patterns.md +98 -0
- package/assets/pitfalls/browser-verification.md +265 -0
- package/assets/pitfalls/component-structure.md +98 -0
- package/assets/pitfalls/dependencies.md +92 -0
- package/assets/pitfalls/deploy-flow.azure.md +171 -0
- package/assets/pitfalls/deploy-flow.github.md +211 -0
- package/assets/pitfalls/deploy-flow.gitlab.md +173 -0
- package/assets/pitfalls/doc-style-human.md +112 -0
- package/assets/pitfalls/doc-style.2.md +286 -0
- package/assets/pitfalls/entity-conventions.needs-admin.md +96 -0
- package/assets/pitfalls/entity-models.md +89 -0
- package/assets/pitfalls/epic-flow.md +92 -0
- package/assets/pitfalls/git-workflow-commit.azure.md +190 -0
- package/assets/pitfalls/git-workflow-commit.github.md +307 -0
- package/assets/pitfalls/git-workflow-commit.gitlab.md +196 -0
- package/assets/pitfalls/git-workflow-docker.md +275 -0
- package/assets/pitfalls/git-workflow-freshness.md +88 -0
- package/assets/pitfalls/git-workflow-hosting.azure.md +31 -0
- package/assets/pitfalls/git-workflow-hosting.github.md +32 -0
- package/assets/pitfalls/git-workflow-hosting.gitlab.md +31 -0
- package/assets/pitfalls/git-workflow-merge.md +220 -0
- package/assets/pitfalls/git-workflow-migration.md +103 -0
- package/assets/pitfalls/git-workflow-pr-body.github.md +185 -0
- package/assets/pitfalls/git-workflow-pr-ready.md +104 -0
- package/assets/pitfalls/git-workflow-pr.2.azure.md +172 -0
- package/assets/pitfalls/git-workflow-pr.2.github.md +184 -0
- package/assets/pitfalls/git-workflow-pr.2.gitlab.md +180 -0
- package/assets/pitfalls/git-workflow-pr.azure.md +159 -0
- package/assets/pitfalls/git-workflow-pr.github.md +107 -0
- package/assets/pitfalls/git-workflow-pr.gitlab.md +151 -0
- package/assets/pitfalls/git-workflow-push.azure.md +30 -0
- package/assets/pitfalls/git-workflow-push.github.md +30 -0
- package/assets/pitfalls/git-workflow-push.gitlab.md +30 -0
- package/assets/pitfalls/git-workflow-queue.azure.md +30 -0
- package/assets/pitfalls/git-workflow-queue.github.md +30 -0
- package/assets/pitfalls/git-workflow-queue.gitlab.md +30 -0
- package/assets/pitfalls/git-workflow-restart.md +72 -0
- package/assets/pitfalls/git-workflow-secrets.md +114 -0
- package/assets/pitfalls/git-workflow-stack.md +254 -0
- package/assets/pitfalls/git-workflow.2.azure.md +291 -0
- package/assets/pitfalls/git-workflow.2.github.md +294 -0
- package/assets/pitfalls/git-workflow.2.gitlab.md +278 -0
- package/assets/pitfalls/lib-layers.md +114 -0
- package/assets/pitfalls/lists.md +117 -0
- package/assets/pitfalls/mockups.needs-mockups.md +87 -0
- package/assets/pitfalls/navigation.md +94 -0
- package/assets/pitfalls/observability.needs-app.md +186 -0
- package/assets/pitfalls/platform-access.md +94 -0
- package/assets/pitfalls/queue-audit.github.md +78 -0
- package/assets/pitfalls/reuse-first.md +201 -0
- package/assets/pitfalls/spec-driven.2.md +318 -0
- package/assets/pitfalls/styling-bem.2.md +125 -0
- package/assets/pitfalls/task-flow-archive.md +265 -0
- package/assets/pitfalls/task-flow-close.2.md +166 -0
- package/assets/pitfalls/task-flow-close.md +167 -0
- package/assets/pitfalls/task-flow-cycle.md +73 -0
- package/assets/pitfalls/task-flow-graph.needs-graph.md +98 -0
- package/assets/pitfalls/task-flow-handoff.md +200 -0
- package/assets/pitfalls/task-flow-handover.md +30 -0
- package/assets/pitfalls/task-flow-owner.md +58 -0
- package/assets/pitfalls/task-flow-plan.md +29 -0
- package/assets/pitfalls/task-flow-resume.md +257 -0
- package/assets/pitfalls/task-flow-start.md +287 -0
- package/assets/pitfalls/task-flow.2.md +303 -0
- package/assets/pitfalls/task-flow.md +4 -4
- package/assets/pitfalls/testing.2.md +279 -0
- package/assets/pitfalls/turn-conduct.md +16 -17
- package/assets/pitfalls/typescript-conventions.md +161 -0
- package/assets/pitfalls/write-a-skill.md +128 -0
- package/assets/rules/angular-patterns.md +21 -86
- package/assets/rules/autonomous-work.md +2 -2
- package/assets/rules/browser-verification.md +28 -256
- package/assets/rules/component-structure.md +25 -87
- package/assets/rules/dependencies.md +20 -78
- package/assets/rules/deploy-flow.azure.md +26 -156
- package/assets/rules/deploy-flow.github.md +34 -200
- package/assets/rules/deploy-flow.gitlab.md +27 -159
- package/assets/rules/doc-style.md +32 -286
- package/assets/rules/entity-conventions.needs-admin.md +26 -82
- package/assets/rules/entity-models.md +14 -63
- package/assets/rules/epic-flow.md +24 -63
- package/assets/rules/git-workflow-hosting.azure.md +26 -0
- package/assets/rules/git-workflow-hosting.github.md +38 -0
- package/assets/rules/git-workflow-hosting.gitlab.md +27 -0
- package/assets/rules/git-workflow-push.azure.md +28 -0
- package/assets/rules/git-workflow-push.github.md +28 -0
- package/assets/rules/git-workflow-push.gitlab.md +28 -0
- package/assets/rules/git-workflow-queue.azure.md +23 -0
- package/assets/rules/git-workflow-queue.github.md +30 -0
- package/assets/rules/git-workflow-queue.gitlab.md +23 -0
- package/assets/rules/git-workflow.azure.md +21 -282
- package/assets/rules/git-workflow.github.md +24 -284
- package/assets/rules/git-workflow.gitlab.md +21 -269
- package/assets/rules/lib-layers.md +30 -103
- package/assets/rules/lists.md +21 -105
- package/assets/rules/mockups.needs-mockups.md +25 -64
- package/assets/rules/navigation.md +10 -69
- package/assets/rules/observability.needs-app.md +43 -172
- package/assets/rules/platform-access.md +28 -75
- package/assets/rules/queue-audit.github.md +25 -52
- package/assets/rules/reuse-first.md +20 -195
- package/assets/rules/spec-driven.md +35 -308
- package/assets/rules/styling-bem.md +20 -117
- package/assets/rules/task-flow-handover.md +24 -0
- package/assets/rules/task-flow-owner.md +34 -0
- package/assets/rules/task-flow-plan.md +38 -0
- package/assets/rules/task-flow.md +22 -300
- package/assets/rules/testing.md +32 -273
- package/assets/rules/turn-conduct.md +105 -106
- package/assets/rules/turn-entry.md +2 -2
- package/assets/rules/typescript-conventions.md +41 -147
- package/assets/samples/tasks/_template/plan.md +30 -6
- package/assets/samples/tasks/_template/progress.md +0 -1
- package/assets/skills/agent-kit-extend.md +25 -168
- package/assets/skills/agent-kit.md +27 -299
- package/assets/skills/write-a-skill.md +20 -106
- package/assets/task-flow/flow.js +184 -0
- package/assets/task-flow/flow.md +101 -0
- package/assets/task-flow/measure/agreement.mjs +24 -0
- package/assets/task-flow/measure/ci.mjs +184 -0
- package/assets/task-flow/measure/copy.mjs +22 -0
- package/assets/task-flow/measure/epic-of.mjs +50 -0
- package/assets/task-flow/measure/epic-text.mjs +35 -0
- package/assets/task-flow/measure/epic.mjs +114 -0
- package/assets/task-flow/measure/folder.mjs +16 -0
- package/assets/task-flow/measure/footprint.mjs +28 -0
- package/assets/task-flow/measure/grill.mjs +21 -0
- package/assets/task-flow/measure/host.mjs +8 -0
- package/assets/task-flow/measure/owner.mjs +27 -0
- package/assets/task-flow/measure/plan.mjs +27 -0
- package/assets/task-flow/measure/pr.mjs +20 -0
- package/assets/task-flow/measure/progress.mjs +50 -0
- package/assets/task-flow/measure/session.mjs +252 -0
- package/assets/task-flow/measure/task.mjs +23 -0
- package/assets/task-flow/measure/text.mjs +77 -0
- package/assets/task-flow/source/git.mjs +254 -0
- package/assets/task-flow/source/host.mjs +277 -0
- package/assets/task-flow/source/marks.mjs +56 -0
- package/assets/task-flow/source/owner.mjs +94 -0
- package/assets/task-flow/source/records.mjs +116 -0
- package/assets/task-flow/source/session.mjs +269 -0
- package/assets/task-flow/source/steps.mjs +28 -0
- package/assets/task-flow/source/tree.mjs +42 -0
- package/bin/agent-kit.d.ts.map +1 -1
- package/bin/agent-kit.js +30 -0
- package/bin/agent-kit.js.map +1 -1
- package/lib/agent-checks.d.ts +55 -0
- package/lib/agent-checks.d.ts.map +1 -0
- package/lib/agent-checks.js +221 -0
- package/lib/agent-checks.js.map +1 -0
- package/lib/assets.d.ts.map +1 -1
- package/lib/assets.js +7 -2
- package/lib/assets.js.map +1 -1
- package/lib/cargo.d.ts +29 -0
- package/lib/cargo.d.ts.map +1 -1
- package/lib/cargo.js +27 -1
- package/lib/cargo.js.map +1 -1
- package/lib/cascade.d.ts.map +1 -1
- package/lib/cascade.js +3 -1
- package/lib/cascade.js.map +1 -1
- package/lib/commands.d.ts.map +1 -1
- package/lib/commands.js +78 -2
- package/lib/commands.js.map +1 -1
- package/lib/config.d.ts +18 -0
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +18 -1
- package/lib/config.js.map +1 -1
- package/lib/epic-window-send.d.ts +74 -0
- package/lib/epic-window-send.d.ts.map +1 -0
- package/lib/epic-window-send.js +166 -0
- package/lib/epic-window-send.js.map +1 -0
- package/lib/hooks-map.d.ts +4 -0
- package/lib/hooks-map.d.ts.map +1 -1
- package/lib/hooks-map.js +2 -2
- package/lib/hooks-map.js.map +1 -1
- package/lib/integrity.d.ts +3 -0
- package/lib/integrity.d.ts.map +1 -1
- package/lib/integrity.js +7 -0
- package/lib/integrity.js.map +1 -1
- package/lib/metric-lines.d.ts +2 -1
- package/lib/metric-lines.d.ts.map +1 -1
- package/lib/metric-lines.js +49 -1
- package/lib/metric-lines.js.map +1 -1
- package/lib/metric-send-mark.d.ts +6 -3
- package/lib/metric-send-mark.d.ts.map +1 -1
- package/lib/metric-send-mark.js +15 -5
- package/lib/metric-send-mark.js.map +1 -1
- package/lib/metric-send.d.ts +6 -2
- package/lib/metric-send.d.ts.map +1 -1
- package/lib/metric-send.js +47 -13
- package/lib/metric-send.js.map +1 -1
- package/lib/metrics.d.ts +17 -0
- package/lib/metrics.d.ts.map +1 -1
- package/lib/metrics.js +26 -15
- package/lib/metrics.js.map +1 -1
- package/lib/observations.js +3 -3
- package/lib/observations.js.map +1 -1
- package/lib/outcomes.d.ts +5 -2
- package/lib/outcomes.d.ts.map +1 -1
- package/lib/outcomes.js +5 -4
- package/lib/outcomes.js.map +1 -1
- package/lib/push-gate.d.ts +13 -0
- package/lib/push-gate.d.ts.map +1 -1
- package/lib/push-gate.js +11 -7
- package/lib/push-gate.js.map +1 -1
- package/lib/push-set-usefulness.d.ts +78 -0
- package/lib/push-set-usefulness.d.ts.map +1 -0
- package/lib/push-set-usefulness.js +225 -0
- package/lib/push-set-usefulness.js.map +1 -0
- package/lib/sync.d.ts +10 -0
- package/lib/sync.d.ts.map +1 -1
- package/lib/sync.js +14 -1
- package/lib/sync.js.map +1 -1
- package/lib/work-result.d.ts +43 -0
- package/lib/work-result.d.ts.map +1 -0
- package/lib/work-result.js +39 -0
- package/lib/work-result.js.map +1 -0
- package/package.json +1 -1
- package/assets/hooks/claim-guard.sh +0 -212
- package/assets/hooks/grill-gate-ask.sh +0 -26
- package/assets/hooks/grill-gate-bypass.sh +0 -61
- package/assets/hooks/grill-gate-options.sh +0 -50
- package/assets/hooks/grill-gate.sh +0 -482
- package/assets/hooks/postmortem-guard.sh +0 -124
- package/assets/hooks/proposal-guard.sh +0 -154
- package/assets/hooks/stand-login-guard.sh +0 -107
- package/assets/hooks/turn-exit-epic.sh +0 -173
- package/assets/hooks/turn-exit-patterns.sh +0 -123
- package/assets/hooks/turn-exit-verdict.sh +0 -149
- package/assets/hooks/waiting-turn-guard.sh +0 -320
- package/assets/hooks/work-start-guard.sh +0 -175
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The verdict at the end of a turn — the engine command `verdict`, called by the hook on Stop.
|
|
3
|
+
*
|
|
4
|
+
* The turn is released by the first release case of the description whose condition is met, in the
|
|
5
|
+
* order of the cases; otherwise it is held, and the refusal names one move: the next step of the
|
|
6
|
+
* scenario. In the state where the stages go on, that move is the current step of the progress and
|
|
7
|
+
* the command that measures it.
|
|
8
|
+
*
|
|
9
|
+
* When another check refused the same step twice for the same reason, or the executor stopped again
|
|
10
|
+
* with no call after a refusal of the engine itself,
|
|
11
|
+
* the one move is the owner's menu: the options of `words.menu`, with the number of the task put in.
|
|
12
|
+
* A stop again after refusals of other stop hooks only names those hooks and the move instead.
|
|
13
|
+
*
|
|
14
|
+
* The case of the silent hosting counts only when the measurement itself stopped on the silence: a
|
|
15
|
+
* read that failed for a state passed over says nothing when a later local exit is unmet. Any other
|
|
16
|
+
* case the hosting could not answer is not met.
|
|
17
|
+
*/
|
|
18
|
+
import { evaluateCondition } from './flow-condition.mjs';
|
|
19
|
+
import { stepsOfPlan, stepsOfProgress } from './work-steps-lib.mjs';
|
|
20
|
+
|
|
21
|
+
/** The measurer whose answer depends on where the measurement stopped. */
|
|
22
|
+
const SILENCE = 'measure.host.silent';
|
|
23
|
+
|
|
24
|
+
/** The measurers that name why the next move is the owner's menu. */
|
|
25
|
+
const MENU_CAUSES = { unread: 'measure.session.unread', hung: 'measure.session.hung', forbidden: 'measure.session.forbidden', idle: 'measure.session.idle' };
|
|
26
|
+
|
|
27
|
+
/** The measurer of the CI hold, read before the release cases and before the cause of the menu. */
|
|
28
|
+
const CI_HOLD = 'measure.ci.hold';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The CI hold: { kind, pr, run } of `measure.ci.hold`, or null. A description without the measurer
|
|
32
|
+
* holds nothing; a hosting that did not answer holds nothing either — the release cases decide then.
|
|
33
|
+
*/
|
|
34
|
+
export function ciHold(model, read) {
|
|
35
|
+
if (!(model.measures ?? []).some((m) => m.entry === 'ci' && m.caps?.hold)) return null;
|
|
36
|
+
try {
|
|
37
|
+
return read(CI_HOLD) || null;
|
|
38
|
+
} catch (error) {
|
|
39
|
+
if (error?.name === 'HostSilent') return null;
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The refusal of a CI hold: the run, the PR, and the one move with its ready command. */
|
|
45
|
+
export function ciHoldReason(hold) {
|
|
46
|
+
const { pr, run } = hold;
|
|
47
|
+
const where = `PR #${pr.number} (\`${pr.head}\` into \`${pr.base}\`)`;
|
|
48
|
+
if (hold.kind === 'running') {
|
|
49
|
+
return [
|
|
50
|
+
`The CI run ${run.id} of ${where} is running, and no background task of this session watches it.`,
|
|
51
|
+
`The one move is to watch it in the background: \`command gh run watch ${run.id} --exit-status --interval 30\` with run_in_background — its notice wakes the session when the run ends. The watch lifts this hold; the scenario decides the rest of the turn.`,
|
|
52
|
+
].join('\n');
|
|
53
|
+
}
|
|
54
|
+
if (hold.kind === 'fresh') {
|
|
55
|
+
const sha = String(pr.headRefOid ?? '');
|
|
56
|
+
const workflow = String(hold.file ?? '').split('/').pop();
|
|
57
|
+
const list = `command gh run list --commit ${sha}${workflow ? ` --workflow ${workflow}` : ''} --json databaseId --jq '.[0].databaseId'`;
|
|
58
|
+
return [
|
|
59
|
+
`The head ${sha.slice(0, 7)} of ${where} was pushed less than two minutes ago, and the hosting shows no CI run on it yet.`,
|
|
60
|
+
`The one move is a background watch of that head: \`for i in $(seq 30); do id=$(${list}); [ -n "$id" ] && break; sleep 10; done; [ -n "$id" ] && command gh run watch "$id" --exit-status --interval 30\` with run_in_background.`,
|
|
61
|
+
].join('\n');
|
|
62
|
+
}
|
|
63
|
+
return [
|
|
64
|
+
`The CI run ${run.id} of ${where} ended «${run.conclusion}», and no call after its end has read it.`,
|
|
65
|
+
`The one move is to read it: \`command gh run view ${run.id} --log-failed | tail -n 200\` — then fix what fell when it is this session's work, or name the run in the reply when another session already fixes it. No owner's menu is offered while the run is unread.`,
|
|
66
|
+
].join('\n');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The verdict on a measured branch: { block } of a CI hold first — the end of the scenario does not
|
|
71
|
+
* pass it — then { release } of the first release case, or null when the turn is held by the
|
|
72
|
+
* scenario.
|
|
73
|
+
*/
|
|
74
|
+
export function decide(model, read, result) {
|
|
75
|
+
const hold = ciHold(model, read);
|
|
76
|
+
if (hold) return { block: ciHoldReason(hold) };
|
|
77
|
+
const released = releaseCase(model, read, result);
|
|
78
|
+
return released ? { release: released.log ?? released.key } : null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** The first release case met, or null. `read` answers a measurer by its reference. */
|
|
82
|
+
export function releaseCase(model, read, result) {
|
|
83
|
+
const stoppedOnSilence = result.state !== null && result.reason !== null;
|
|
84
|
+
const answer = (name) => {
|
|
85
|
+
try {
|
|
86
|
+
return read(name);
|
|
87
|
+
} catch (error) {
|
|
88
|
+
// A case the hosting could not answer is not met: an unknown fact releases nothing.
|
|
89
|
+
if (error?.name === 'HostSilent') return false;
|
|
90
|
+
throw error;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const reader = (name) => (name === SILENCE ? stoppedOnSilence && answer(name) : answer(name));
|
|
94
|
+
return model.release.find((entry) => evaluateCondition(entry.when, reader)) ?? null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Why the next move is the owner's menu: { by: '<guard>' }, { idle: true }, or null. A measurer the
|
|
99
|
+
* description does not declare, or the hosting could not answer, names no cause. An unread
|
|
100
|
+
* background task comes first, { unread: { task, output, agent } }: while it is unread the move is to
|
|
101
|
+
* read it, and no menu is offered. A stop refused only by other hooks gives { foreign: ['<hook>', …] }:
|
|
102
|
+
* the hold names those hooks and the move of the state, not the menu.
|
|
103
|
+
*/
|
|
104
|
+
export function menuCause(read) {
|
|
105
|
+
const answer = (name) => {
|
|
106
|
+
try {
|
|
107
|
+
return read(name);
|
|
108
|
+
} catch {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
const unread = answer(MENU_CAUSES.unread);
|
|
113
|
+
if (unread) return { unread };
|
|
114
|
+
const by = answer(MENU_CAUSES.forbidden);
|
|
115
|
+
if (by) return { by: String(by) };
|
|
116
|
+
// A task past the bound of the wait is hung: the move is to deal with it, not the owner's menu.
|
|
117
|
+
// A step another check refused twice still goes to the owner's menu above.
|
|
118
|
+
const hung = answer(MENU_CAUSES.hung);
|
|
119
|
+
if (hung && typeof hung === 'object') return { hung };
|
|
120
|
+
const idle = answer(MENU_CAUSES.idle);
|
|
121
|
+
// A stop refused only by other hooks is no idle one: no menu, the refusal is named in one line.
|
|
122
|
+
const foreign = idle && typeof idle === 'object' ? [idle.foreign ?? []].flat().filter(Boolean).map(String) : [];
|
|
123
|
+
if (foreign.length > 0) return { foreign };
|
|
124
|
+
return idle ? { idle: true } : null;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** The options of the owner's menu: `words.menu`, the number of the task put in place of N. */
|
|
128
|
+
export function menuOptions(words, task) {
|
|
129
|
+
return (words.menu ?? []).map((option) => (task ? option.replace(/RT-N$/, `RT-${task}`) : option));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** The current step of a progress text and the count of steps not done: { number, name, left }, or null. */
|
|
133
|
+
export function currentStep(progress) {
|
|
134
|
+
const steps = stepsOfProgress(progress ?? '').steps;
|
|
135
|
+
const step = steps.find((s) => s.mark === '>');
|
|
136
|
+
return step ? { number: step.number, name: step.name, left: steps.filter((s) => s.mark !== 'x').length } : null;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* The step the stages wait for: the current one of the progress, else the first step of the plan that
|
|
141
|
+
* the progress does not mark done or that has no matched mark. `{ number, name, left, done }`, or null;
|
|
142
|
+
* `matched(number)` answers the mark of a step.
|
|
143
|
+
*/
|
|
144
|
+
export function pendingStep(progress, matched, plan = '') {
|
|
145
|
+
const marked = stepsOfProgress(progress ?? '').steps;
|
|
146
|
+
const planned = plan ? stepsOfPlan(plan).map((s) => ({ ...s, mark: marked.find((m) => m.number === s.number)?.mark ?? ' ' })) : marked;
|
|
147
|
+
const open = planned.filter((s) => s.mark !== 'x' || !matched(s.number));
|
|
148
|
+
const step = marked.find((s) => s.mark === '>') ?? open[0];
|
|
149
|
+
return step ? { number: step.number, name: step.name, left: open.length, done: step.mark === 'x' } : null;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* The step of a running stage with no current step: from `text`, the progress on disk, or with no
|
|
154
|
+
* folder from the last progress of the history, with the commit that took the folder apart. Null when
|
|
155
|
+
* no progress is found.
|
|
156
|
+
*/
|
|
157
|
+
export function stageStep(git, marks, folder, branch, text = null) {
|
|
158
|
+
const progress = text ?? git.lastVersion(`${folder}/progress.md`);
|
|
159
|
+
const plan = git.lastVersion(`${folder}/plan.md`) ?? '';
|
|
160
|
+
const pending = progress === null ? null : pendingStep(progress, (number) => marks.step(branch, number)?.matched === true, plan);
|
|
161
|
+
return pending ? { ...pending, removedBy: text === null ? git.removedAt(folder) : null } : null;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** The lines of the step the stages wait for; `removedBy` names the commit that took the folder apart. */
|
|
165
|
+
function stepLines(step) {
|
|
166
|
+
const measure = `\`node tools/task-flow-script.mjs step ${step.number}\``;
|
|
167
|
+
const back = step.removedBy ? `\`git revert --no-edit ${step.removedBy}\`` : null;
|
|
168
|
+
if (!back) {
|
|
169
|
+
// A step read with the marks: its count is not the one of `check-work-steps`, which reads the progress alone.
|
|
170
|
+
const count = step.done === undefined ? 'are not done, counted by `node tools/check-work-steps.mjs`' : 'are not done or have no matched mark';
|
|
171
|
+
return [`${step.left} steps of the plan ${count}.`, `The next move is step ${step.number} «${step.name}»: do it, then measure it — ${measure}.`];
|
|
172
|
+
}
|
|
173
|
+
const lines = [`${step.left} steps of the plan are not done or have no matched mark, read from the last progress of the history: the task folder is taken apart by ${step.removedBy.slice(0, 9)}.`];
|
|
174
|
+
if (!step.done) {
|
|
175
|
+
lines.push(`The next move is step ${step.number} «${step.name}»: the history does not mark it done, so bring the folder back — ${back} — then do the step and measure it — ${measure}.`);
|
|
176
|
+
} else {
|
|
177
|
+
lines.push(`The next move is step ${step.number} «${step.name}»: measure it — ${measure}; the command puts the folder back for the run.`);
|
|
178
|
+
lines.push(`A step that does not match again is fixed where its check reads; a fix that lies in the folder — a check replaced in the progress — needs the folder back — ${back} — then take it apart again.`);
|
|
179
|
+
}
|
|
180
|
+
return lines;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* The reason of a held turn: the measured state, its action, and the step when the stages go on. With a
|
|
185
|
+
* cause of the menu the one move is the owner's menu instead.
|
|
186
|
+
*/
|
|
187
|
+
export function holdReason(model, result, step, menu = null) {
|
|
188
|
+
const total = model.states.length;
|
|
189
|
+
const state = model.states[result.index - 1];
|
|
190
|
+
const lines = [`The scenario is not over: the work stands in the state \`${result.state}\` (${result.index} of ${total}), whose exit is not met.`];
|
|
191
|
+
if (menu?.cause?.unread) {
|
|
192
|
+
const { task, output, agent } = menu.cause.unread;
|
|
193
|
+
if (agent) {
|
|
194
|
+
lines.push(`The background agent \`${task}\` ended after the last call, and its notice has not been read.`);
|
|
195
|
+
lines.push('The first move is to take its report from the notice and act on it. No owner\'s menu is offered while it is unread.');
|
|
196
|
+
} else {
|
|
197
|
+
const where = output ? ` — its output is \`${output}\`` : '';
|
|
198
|
+
lines.push(`The background task \`${task}\` ended after the last call, and its notice has not been read${where}.`);
|
|
199
|
+
lines.push('The first move is to read that output and act on it: a red result is fixed now. No owner\'s menu is offered while the task is unread.');
|
|
200
|
+
}
|
|
201
|
+
} else if (menu?.cause?.hung) {
|
|
202
|
+
const { task, minutes, output } = menu.cause.hung;
|
|
203
|
+
const where = output ? ` — its output is \`${output}\`` : '';
|
|
204
|
+
lines.push(`The background task \`${task}\` runs ${minutes} minutes with no notice, past the bound of the wait: it is hung${where}.`);
|
|
205
|
+
lines.push('The first move is to read its output, then stop it or start it again, and go on with the step. No owner\'s menu is offered while it hangs.');
|
|
206
|
+
} else if (menu?.cause?.foreign) {
|
|
207
|
+
const hooks = menu.cause.foreign.map((hook) => `\`${hook}\``).join(', ');
|
|
208
|
+
lines.push(`The previous refusal came from ${hooks}, not from this check, and no owner's menu is offered for it. Do what it named; when it is not yours, say so in one line and make the move below in the same turn: a stop with no call after this refusal gives the menu.`);
|
|
209
|
+
} else if (menu?.cause) {
|
|
210
|
+
lines.push(
|
|
211
|
+
menu.cause.idle
|
|
212
|
+
? 'The previous refusal named a move, and no call followed it.'
|
|
213
|
+
: `The check \`${menu.cause.by}\` refused the same step twice for the same reason.`,
|
|
214
|
+
);
|
|
215
|
+
const options = menuOptions(model.words, menu.task);
|
|
216
|
+
lines.push(`The one move is the owner's menu: ask through the question tool with exactly these options — ${options.map((o) => `«${o}»`).join(', ')} — and say in the question that the way goes into its free field.`);
|
|
217
|
+
lines.push('Then do what the owner chose: a deferral marks the task «отложено» in the plan of the epic and takes the next unblocked task; a way written by the owner is taken in the same step. A bare «подскажу путь» with no text is followed by one question with a free field only.');
|
|
218
|
+
return lines.join('\n');
|
|
219
|
+
}
|
|
220
|
+
if (step && state?.key === 'stage') {
|
|
221
|
+
lines.push(...stepLines(step));
|
|
222
|
+
} else {
|
|
223
|
+
lines.push(`The next move is the action of this state: ${state?.action ?? ''} (pattern \`${state?.pattern ?? ''}\`).`);
|
|
224
|
+
}
|
|
225
|
+
lines.push('`node tools/task-flow-script.mjs measure` names the exits read.');
|
|
226
|
+
return lines.join('\n');
|
|
227
|
+
}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* The merges of requests and the editions of packages, read from the hosting and the registry and
|
|
4
|
+
* written as observations: what the day line and the epic windows are counted by.
|
|
5
|
+
*
|
|
6
|
+
* node merge-read.mjs --pulls <file> --observations <dir>
|
|
7
|
+
* [--main <branch>] [--packages <dir>,<dir>] [--ignore <pattern>] [--editions <pkg>=<file>]...
|
|
8
|
+
*
|
|
9
|
+
* `--pulls` holds the requests the hosting gave, one JSON object per line: `{number, state,
|
|
10
|
+
* headRefName, baseRefName, mergedAt, title, files}`, open requests included — they tell a task
|
|
11
|
+
* branch from an epic branch before the epic merges. `--editions` holds the answer of the registry
|
|
12
|
+
* for one package: the map of versions to their moments.
|
|
13
|
+
*
|
|
14
|
+
* What is written, by the day of the moment:
|
|
15
|
+
* task-merged a task request merged; `opens: "1"` when its base is an epic branch, `epic` its key
|
|
16
|
+
* epic-merged an epic request merged into the main branch; `pkg` the packages it changed
|
|
17
|
+
* edition a published version of a package of the tree
|
|
18
|
+
*
|
|
19
|
+
* A request and an edition are written once: a second read of the same fact replaces the line of the
|
|
20
|
+
* first, so a read that judged a fact anew corrects it. An answer that does not parse whole writes
|
|
21
|
+
* nothing: a broken read is taken again by the next one.
|
|
22
|
+
*/
|
|
23
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
24
|
+
import { join } from 'node:path';
|
|
25
|
+
|
|
26
|
+
import { taskOf } from './record-count.mjs';
|
|
27
|
+
|
|
28
|
+
const MINUTE = 60 * 1000;
|
|
29
|
+
|
|
30
|
+
const option = (argv, name) => {
|
|
31
|
+
const at = argv.indexOf(name);
|
|
32
|
+
return at >= 0 ? argv[at + 1] : undefined;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const options = (argv, name) => argv.flatMap((value, at) => (value === name && argv[at + 1] ? [argv[at + 1]] : []));
|
|
36
|
+
|
|
37
|
+
/** A value of an observation: no path, no text, a name of 48 characters at most. */
|
|
38
|
+
const clean = (value) => String(value ?? '').includes('/') ? '' : String(value ?? '').replace(/[^A-Za-z0-9._:-]/g, '').slice(0, 48);
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The branches that are task branches: the head of a request whose base is not the main branch. A
|
|
42
|
+
* request merged into such a branch is a stack step, and it opens no window.
|
|
43
|
+
*/
|
|
44
|
+
export function taskBranchesOf(pulls, main = 'main') {
|
|
45
|
+
return new Set(pulls.filter((p) => p.baseRefName && p.baseRefName !== main).map((p) => p.headRefName));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** The branches that are epic branches: a base of a request that is no task branch and no main branch. */
|
|
49
|
+
export function epicBranchesOf(pulls, main = 'main') {
|
|
50
|
+
const tasks = taskBranchesOf(pulls, main);
|
|
51
|
+
return new Set(pulls.map((p) => p.baseRefName).filter((base) => base && base !== main && !tasks.has(base)));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The packages a request changed: the directories of `packages` that hold one of its files. A file
|
|
56
|
+
* the `ignore` pattern matches is no part of a package: a code graph lies in every package directory
|
|
57
|
+
* and is never published.
|
|
58
|
+
*/
|
|
59
|
+
export const packagesOf = (pull, packages, ignore = null) =>
|
|
60
|
+
packages
|
|
61
|
+
.filter((dir) => (pull.files ?? []).some((file) => (file === dir || file.startsWith(`${dir}/`)) && !(ignore && ignore.test(file))))
|
|
62
|
+
.map((dir) => dir.split('/').pop());
|
|
63
|
+
|
|
64
|
+
/** The observations of the merged requests: one per request, by its merge moment. */
|
|
65
|
+
export function mergesOf(pulls, { main = 'main', packages = [], ignore = null } = {}) {
|
|
66
|
+
const epics = epicBranchesOf(pulls, main);
|
|
67
|
+
const out = [];
|
|
68
|
+
for (const pull of pulls) {
|
|
69
|
+
if (!pull.mergedAt) continue;
|
|
70
|
+
const task = clean(taskOf(pull.headRefName));
|
|
71
|
+
if (pull.baseRefName === main && epics.has(pull.headRefName)) {
|
|
72
|
+
out.push({ number: pull.number, line: { t: pull.mergedAt, ev: 'epic-merged', task, pkg: packagesOf(pull, packages, ignore).map(clean).join(',') } });
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const line = { t: pull.mergedAt, ev: 'task-merged', task };
|
|
76
|
+
if (epics.has(pull.baseRefName)) {
|
|
77
|
+
line.opens = '1';
|
|
78
|
+
line.epic = clean(taskOf(pull.baseRefName));
|
|
79
|
+
}
|
|
80
|
+
out.push({ number: pull.number, line });
|
|
81
|
+
}
|
|
82
|
+
return out;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** The observations of the editions of one package: the registry map without its service keys. */
|
|
86
|
+
export const editionsOf = (pkg, times) =>
|
|
87
|
+
Object.entries(times ?? {})
|
|
88
|
+
.filter(([version, at]) => /^\d+\.\d+\.\d+/.test(version) && typeof at === 'string')
|
|
89
|
+
.map(([version, at]) => ({ key: `${pkg}@${version}`, line: { t: at, ev: 'edition', pkg: clean(pkg), ver: clean(version) } }));
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* The merges of a day for the day line: the merged tasks, those with a taking seen on this machine,
|
|
93
|
+
* and their whole minutes from the taking. The taking of a task is its earliest `task-taken`.
|
|
94
|
+
*/
|
|
95
|
+
export function dayMerges(observations, day) {
|
|
96
|
+
const taken = new Map();
|
|
97
|
+
for (const o of observations) {
|
|
98
|
+
if (o.ev !== 'task-taken' || !o.task) continue;
|
|
99
|
+
if (!taken.has(o.task) || o.t < taken.get(o.task)) taken.set(o.task, o.t);
|
|
100
|
+
}
|
|
101
|
+
let tasksMerged = 0;
|
|
102
|
+
let tasksTimed = 0;
|
|
103
|
+
let takenMinutes = 0;
|
|
104
|
+
for (const o of observations) {
|
|
105
|
+
if (o.ev !== 'task-merged' || !String(o.t).startsWith(day)) continue;
|
|
106
|
+
tasksMerged += 1;
|
|
107
|
+
const from = taken.get(o.task);
|
|
108
|
+
if (!from || from > o.t) continue;
|
|
109
|
+
tasksTimed += 1;
|
|
110
|
+
takenMinutes += Math.floor((Date.parse(o.t) - Date.parse(from)) / MINUTE);
|
|
111
|
+
}
|
|
112
|
+
return { tasksMerged, tasksTimed, takenMinutes };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** The end of a day of UTC: what was true at it is what the report of the day says. */
|
|
116
|
+
const endOf = (day) => `${day}T23:59:59.999Z`;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* The epics of a report day, judged by the end of that day: each epic merged into the main branch
|
|
120
|
+
* by then, and each epic whose window opened by then with no merge yet.
|
|
121
|
+
*
|
|
122
|
+
* status `released` — every package the epic changed has an edition after the merge, or it
|
|
123
|
+
* changed none; `not-released` — a package has no such edition; `merged` — the tree
|
|
124
|
+
* publishes no package; `open` — no merge into the main branch yet
|
|
125
|
+
* minutes whole minutes from the taking to the release, to the merge while not released, and
|
|
126
|
+
* null for an open epic or one with no taking seen; the taking of an epic is the earliest
|
|
127
|
+
* taking of the epic branch or of a task merged into it
|
|
128
|
+
*/
|
|
129
|
+
export function dayEpics(observations, day, { publishes = true } = {}) {
|
|
130
|
+
const end = endOf(day);
|
|
131
|
+
const until = observations.filter((o) => String(o.t) <= end);
|
|
132
|
+
const tasksOf = new Map();
|
|
133
|
+
const opened = new Set();
|
|
134
|
+
for (const o of until) {
|
|
135
|
+
if (o.ev !== 'task-merged' || !o.epic) continue;
|
|
136
|
+
if (!tasksOf.has(o.epic)) tasksOf.set(o.epic, new Set());
|
|
137
|
+
tasksOf.get(o.epic).add(o.task);
|
|
138
|
+
if (o.opens) opened.add(o.epic);
|
|
139
|
+
}
|
|
140
|
+
const takenAt = (epic) =>
|
|
141
|
+
until
|
|
142
|
+
.filter((o) => o.ev === 'task-taken' && (o.task === epic || tasksOf.get(epic)?.has(o.task)))
|
|
143
|
+
.map((o) => o.t)
|
|
144
|
+
.sort()[0] ?? null;
|
|
145
|
+
const minutesBetween = (from, to) => (from && to ? Math.floor((Date.parse(to) - Date.parse(from)) / MINUTE) : null);
|
|
146
|
+
const merged = new Map(until.filter((o) => o.ev === 'epic-merged').map((o) => [o.task, o]));
|
|
147
|
+
const out = [];
|
|
148
|
+
for (const [epic, merge] of merged) {
|
|
149
|
+
const packages = String(merge.pkg ?? '').split(',').filter(Boolean);
|
|
150
|
+
const editions = packages.map((pkg) =>
|
|
151
|
+
until.filter((o) => o.ev === 'edition' && o.pkg === pkg && o.t > merge.t).map((o) => o.t).sort()[0] ?? null,
|
|
152
|
+
);
|
|
153
|
+
let status = 'released';
|
|
154
|
+
let releasedAt = merge.t;
|
|
155
|
+
if (!publishes) {
|
|
156
|
+
status = 'merged';
|
|
157
|
+
releasedAt = null;
|
|
158
|
+
} else if (editions.some((at) => at === null)) {
|
|
159
|
+
status = 'not-released';
|
|
160
|
+
releasedAt = null;
|
|
161
|
+
} else if (editions.length > 0) {
|
|
162
|
+
releasedAt = editions.sort().at(-1);
|
|
163
|
+
}
|
|
164
|
+
out.push({ epic, status, mergedAt: merge.t, releasedAt, minutes: minutesBetween(takenAt(epic), releasedAt ?? merge.t) });
|
|
165
|
+
}
|
|
166
|
+
for (const epic of opened) {
|
|
167
|
+
if (!merged.has(epic)) out.push({ epic, status: 'open', mergedAt: null, releasedAt: null, minutes: null });
|
|
168
|
+
}
|
|
169
|
+
return out;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** The lines of a file of JSON lines, or null when one of them does not parse. */
|
|
173
|
+
function linesOf(file) {
|
|
174
|
+
const out = [];
|
|
175
|
+
for (const line of readFileSync(file, 'utf8').split('\n')) {
|
|
176
|
+
if (!line.trim()) continue;
|
|
177
|
+
try {
|
|
178
|
+
out.push(JSON.parse(line));
|
|
179
|
+
} catch {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return out;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** The key of a merge or an edition line: a second read of the same fact replaces the first. */
|
|
187
|
+
export const factKey = (line) => [line.ev, line.task ?? '', line.pkg && line.ev === 'edition' ? `${line.pkg}@${line.ver}` : '', line.t].join('|');
|
|
188
|
+
|
|
189
|
+
const FACTS = new Set(['task-merged', 'epic-merged', 'edition']);
|
|
190
|
+
|
|
191
|
+
/** Writes the facts into the day files: a line with the key of a new one is replaced, the rest is kept. */
|
|
192
|
+
export function writeFacts(dir, lines) {
|
|
193
|
+
const byDay = new Map();
|
|
194
|
+
for (const line of lines) {
|
|
195
|
+
const day = String(line.t).slice(0, 10);
|
|
196
|
+
if (!byDay.has(day)) byDay.set(day, []);
|
|
197
|
+
byDay.get(day).push(line);
|
|
198
|
+
}
|
|
199
|
+
mkdirSync(dir, { recursive: true });
|
|
200
|
+
for (const [day, fresh] of byDay) {
|
|
201
|
+
const file = join(dir, `${day}.jsonl`);
|
|
202
|
+
const keys = new Set(fresh.map(factKey));
|
|
203
|
+
const kept = existsSync(file)
|
|
204
|
+
? readFileSync(file, 'utf8').split('\n').filter((text) => {
|
|
205
|
+
if (!text.trim()) return false;
|
|
206
|
+
try {
|
|
207
|
+
const old = JSON.parse(text);
|
|
208
|
+
return !(FACTS.has(old.ev) && keys.has(factKey(old)));
|
|
209
|
+
} catch {
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
212
|
+
})
|
|
213
|
+
: [];
|
|
214
|
+
writeFileSync(file, [...kept, ...fresh.map((line) => JSON.stringify(line))].join('\n') + '\n');
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function main(argv) {
|
|
219
|
+
const dir = option(argv, '--observations');
|
|
220
|
+
const pullsFile = option(argv, '--pulls');
|
|
221
|
+
if (!dir || !pullsFile || !existsSync(pullsFile)) return 0;
|
|
222
|
+
const pulls = linesOf(pullsFile);
|
|
223
|
+
const editions = [];
|
|
224
|
+
for (const pair of options(argv, '--editions')) {
|
|
225
|
+
const [pkg, file] = pair.split('=');
|
|
226
|
+
try {
|
|
227
|
+
editions.push(...editionsOf(pkg, JSON.parse(readFileSync(file, 'utf8'))));
|
|
228
|
+
} catch {
|
|
229
|
+
return 0;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (pulls === null) return 0;
|
|
233
|
+
const packages = (option(argv, '--packages') ?? '').split(',').filter(Boolean);
|
|
234
|
+
const ignore = option(argv, '--ignore') ? new RegExp(option(argv, '--ignore')) : null;
|
|
235
|
+
writeFacts(dir, [...mergesOf(pulls, { main: option(argv, '--main') ?? 'main', packages, ignore }), ...editions].map((item) => item.line));
|
|
236
|
+
return 0;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (process.argv[1] && import.meta.url === new URL(`file://${process.argv[1]}`).href) process.exit(main(process.argv.slice(2)));
|