@rt-tools/agent-kit 0.37.1 → 0.38.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 +21365 -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 +136 -0
- package/assets/checks/flow-forecast.mjs +330 -0
- package/assets/checks/flow-guard-run.mjs +90 -0
- package/assets/checks/flow-guard.mjs +294 -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 +365 -0
- package/assets/checks/flow-sync.mjs +296 -0
- package/assets/checks/flow-syntax.mjs +292 -0
- package/assets/checks/flow-verdict.mjs +112 -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 +410 -0
- package/assets/checks/record-recount.mjs +187 -0
- package/assets/checks/record-turn.mjs +155 -0
- package/assets/checks/task-flow-script.mjs +292 -0
- package/assets/checks/tree-assignment.mjs +26 -7
- package/assets/checks/work-result.mjs +281 -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 +21 -22
- package/assets/docs/GLOSSARY.md +5 -1
- package/assets/hooks/ask-judge.md +65 -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 +308 -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 +32 -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 +15 -4
- package/assets/hooks/git-guard-push-marks.sh +53 -1
- package/assets/hooks/git-guard-push-tests.sh +30 -51
- 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 +14 -10
- package/assets/hooks/prose-style-guard.sh +6 -19
- package/assets/hooks/pull-merges.sh +76 -0
- package/assets/hooks/push-set.sh +11 -4
- 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 +103 -0
- package/assets/hooks/window-fill-guard.sh +22 -41
- 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.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/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/navigation.md +94 -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 +264 -0
- package/assets/pitfalls/task-flow-close.2.md +165 -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 +29 -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/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/navigation.md +10 -69
- 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 +100 -104
- 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 +188 -0
- package/assets/task-flow/flow.md +102 -0
- package/assets/task-flow/measure/agreement.mjs +24 -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 +20 -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 +175 -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 +86 -0
- package/assets/task-flow/source/host.mjs +172 -0
- package/assets/task-flow/source/marks.mjs +56 -0
- package/assets/task-flow/source/owner.mjs +74 -0
- package/assets/task-flow/source/records.mjs +116 -0
- package/assets/task-flow/source/session.mjs +232 -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 +209 -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,292 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* The parser of the task flow description language.
|
|
4
|
+
*
|
|
5
|
+
* The description is one object in parentheses closed by a semicolon: `({ … });`. It is read token
|
|
6
|
+
* by token and nothing in it is executed — a description that could run code would let any tree
|
|
7
|
+
* that installs the package run anything at the minute the engine reads it, and a reviewer would
|
|
8
|
+
* have to read it as code. So the grammar is narrow on purpose:
|
|
9
|
+
*
|
|
10
|
+
* value — a literal, a reference, a call of a reference, an array or an object;
|
|
11
|
+
* literal — a string in quotes, a number, `true`, `false`, `null`;
|
|
12
|
+
* reference — `section.name[.field…]` without quotes, the section one of the six;
|
|
13
|
+
* call — a reference followed by arguments in parentheses, the arguments values;
|
|
14
|
+
* array — values in brackets, a trailing comma allowed;
|
|
15
|
+
* object — `key: value` pairs in braces, the key a name or a string, a repeated key refused.
|
|
16
|
+
*
|
|
17
|
+
* Functions, operators, `new`, `require` and imports are refused with the place they stand at.
|
|
18
|
+
* Comments are skipped; a comment or a dot inside a string is the string's own text. Nothing may
|
|
19
|
+
* follow the closing `);` but whitespace and comments: a tail is where code would be hidden.
|
|
20
|
+
*
|
|
21
|
+
* The result is plain data: objects and arrays as such, a reference as a `Ref`, a call as a `Call`.
|
|
22
|
+
* Usage: node flow-syntax.mjs <file> — prints the model as JSON, or `flow syntax: <what> at L:C`
|
|
23
|
+
* and exits 1.
|
|
24
|
+
*/
|
|
25
|
+
import { readFileSync } from 'node:fs';
|
|
26
|
+
import { pathToFileURL } from 'node:url';
|
|
27
|
+
|
|
28
|
+
/** The sections a reference may start with. */
|
|
29
|
+
export const SECTIONS = ['source', 'measure', 'state', 'release', 'words', 'expect'];
|
|
30
|
+
|
|
31
|
+
const NAME = /^[A-Za-z][A-Za-z0-9]*$/;
|
|
32
|
+
const KEYWORDS = new Set(['true', 'false', 'null']);
|
|
33
|
+
const FORBIDDEN = new Set(['function', 'new', 'require', 'import', 'export', 'class', 'this', 'return', 'await', 'async', 'eval']);
|
|
34
|
+
|
|
35
|
+
/** A reference: `section.name[.field…]`. */
|
|
36
|
+
export class Ref {
|
|
37
|
+
constructor(path) {
|
|
38
|
+
this.path = path;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
toJSON() {
|
|
42
|
+
return { ref: this.path.join('.') };
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** A call of a reference with arguments. */
|
|
47
|
+
export class Call {
|
|
48
|
+
constructor(ref, args) {
|
|
49
|
+
this.ref = ref;
|
|
50
|
+
this.args = args;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
toJSON() {
|
|
54
|
+
return { call: this.ref.path.join('.'), args: this.args };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** A refusal of the parser: what is wrong and where. */
|
|
59
|
+
export class FlowSyntaxError extends Error {
|
|
60
|
+
constructor(what, line, column) {
|
|
61
|
+
super(`${what} at ${line}:${column}`);
|
|
62
|
+
this.what = what;
|
|
63
|
+
this.line = line;
|
|
64
|
+
this.column = column;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function tokenize(text) {
|
|
69
|
+
const tokens = [];
|
|
70
|
+
let at = 0;
|
|
71
|
+
let line = 1;
|
|
72
|
+
let column = 1;
|
|
73
|
+
|
|
74
|
+
const advance = (count) => {
|
|
75
|
+
for (let i = 0; i < count; i += 1) {
|
|
76
|
+
if (text[at] === '\n') {
|
|
77
|
+
line += 1;
|
|
78
|
+
column = 1;
|
|
79
|
+
} else {
|
|
80
|
+
column += 1;
|
|
81
|
+
}
|
|
82
|
+
at += 1;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
const fail = (what) => {
|
|
86
|
+
throw new FlowSyntaxError(what, line, column);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
while (at < text.length) {
|
|
90
|
+
const ch = text[at];
|
|
91
|
+
const next = text[at + 1];
|
|
92
|
+
|
|
93
|
+
if (/\s/.test(ch)) {
|
|
94
|
+
advance(1);
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (ch === '/' && next === '/') {
|
|
99
|
+
while (at < text.length && text[at] !== '\n') advance(1);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (ch === '/' && next === '*') {
|
|
104
|
+
const end = text.indexOf('*/', at + 2);
|
|
105
|
+
if (end < 0) fail('an unclosed comment');
|
|
106
|
+
advance(end + 2 - at);
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const start = { line, column };
|
|
111
|
+
|
|
112
|
+
if (ch === "'" || ch === '"') {
|
|
113
|
+
let value = '';
|
|
114
|
+
advance(1);
|
|
115
|
+
for (;;) {
|
|
116
|
+
if (at >= text.length || text[at] === '\n') fail('an unclosed string');
|
|
117
|
+
const c = text[at];
|
|
118
|
+
if (c === ch) {
|
|
119
|
+
advance(1);
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
if (c === '\\') {
|
|
123
|
+
const e = text[at + 1];
|
|
124
|
+
const map = { n: '\n', t: '\t', '\\': '\\', "'": "'", '"': '"' };
|
|
125
|
+
if (!(e in map)) fail(`an unknown escape \\${e ?? ''} in a string`);
|
|
126
|
+
value += map[e];
|
|
127
|
+
advance(2);
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
value += c;
|
|
131
|
+
advance(1);
|
|
132
|
+
}
|
|
133
|
+
tokens.push({ type: 'string', value, ...start });
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (/[0-9]/.test(ch) || (ch === '-' && /[0-9]/.test(next ?? ''))) {
|
|
138
|
+
const m = /^-?[0-9]+(\.[0-9]+)?/.exec(text.slice(at));
|
|
139
|
+
advance(m[0].length);
|
|
140
|
+
if (/[A-Za-z_$]/.test(text[at] ?? '')) fail('a name glued to a number');
|
|
141
|
+
tokens.push({ type: 'number', value: Number(m[0]), ...start });
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (/[A-Za-z_$]/.test(ch)) {
|
|
146
|
+
const m = /^[A-Za-z_$][A-Za-z0-9_$]*/.exec(text.slice(at));
|
|
147
|
+
const word = m[0];
|
|
148
|
+
if (FORBIDDEN.has(word)) fail(`«${word}» is not allowed: the description executes nothing`);
|
|
149
|
+
if (!NAME.test(word)) fail(`the name «${word}» is outside [A-Za-z][A-Za-z0-9]*`);
|
|
150
|
+
advance(word.length);
|
|
151
|
+
tokens.push({ type: 'name', value: word, ...start });
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if ('(){}[],:;.'.includes(ch)) {
|
|
156
|
+
advance(1);
|
|
157
|
+
tokens.push({ type: 'punct', value: ch, ...start });
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (ch === '=' && next === '>') fail('an arrow function is not allowed: the description executes nothing');
|
|
162
|
+
if (ch === '`') fail('a template string is not allowed: the description executes nothing');
|
|
163
|
+
fail(`«${ch}» is an operator: an expression is not allowed, only values`);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
tokens.push({ type: 'end', value: null, line, column });
|
|
167
|
+
return tokens;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Parses a description into plain data. Throws `FlowSyntaxError`. */
|
|
171
|
+
export function parse(text) {
|
|
172
|
+
const tokens = tokenize(text);
|
|
173
|
+
let at = 0;
|
|
174
|
+
|
|
175
|
+
const peek = () => tokens[at];
|
|
176
|
+
const fail = (what, token = peek()) => {
|
|
177
|
+
throw new FlowSyntaxError(what, token.line, token.column);
|
|
178
|
+
};
|
|
179
|
+
const describe = (token) => (token.type === 'end' ? 'the end' : `«${token.value}»`);
|
|
180
|
+
const expect = (value) => {
|
|
181
|
+
const token = peek();
|
|
182
|
+
if (token.type !== 'punct' || token.value !== value) fail(`«${value}» expected, ${describe(token)} found`);
|
|
183
|
+
at += 1;
|
|
184
|
+
return token;
|
|
185
|
+
};
|
|
186
|
+
const isPunct = (value) => peek().type === 'punct' && peek().value === value;
|
|
187
|
+
|
|
188
|
+
function reference() {
|
|
189
|
+
const first = peek();
|
|
190
|
+
at += 1;
|
|
191
|
+
if (!SECTIONS.includes(first.value)) {
|
|
192
|
+
fail(`«${first.value}» is not a section: a reference starts with ${SECTIONS.join(', ')}`, first);
|
|
193
|
+
}
|
|
194
|
+
const path = [first.value];
|
|
195
|
+
while (isPunct('.')) {
|
|
196
|
+
at += 1;
|
|
197
|
+
const part = peek();
|
|
198
|
+
if (part.type !== 'name') fail(`a name expected after the dot, ${describe(part)} found`);
|
|
199
|
+
path.push(part.value);
|
|
200
|
+
at += 1;
|
|
201
|
+
}
|
|
202
|
+
if (path.length < 2) fail(`a reference names a section and an entry: «${first.value}.<name>»`, first);
|
|
203
|
+
const ref = new Ref(path);
|
|
204
|
+
if (!isPunct('(')) return ref;
|
|
205
|
+
at += 1;
|
|
206
|
+
const args = [];
|
|
207
|
+
while (!isPunct(')')) {
|
|
208
|
+
args.push(value());
|
|
209
|
+
if (isPunct(',')) at += 1;
|
|
210
|
+
else if (!isPunct(')')) fail(`«,» or «)» expected, ${describe(peek())} found`);
|
|
211
|
+
}
|
|
212
|
+
at += 1;
|
|
213
|
+
return new Call(ref, args);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function array() {
|
|
217
|
+
expect('[');
|
|
218
|
+
const items = [];
|
|
219
|
+
while (!isPunct(']')) {
|
|
220
|
+
items.push(value());
|
|
221
|
+
if (isPunct(',')) at += 1;
|
|
222
|
+
else if (!isPunct(']')) fail(`«,» or «]» expected, ${describe(peek())} found`);
|
|
223
|
+
}
|
|
224
|
+
at += 1;
|
|
225
|
+
return items;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function object() {
|
|
229
|
+
expect('{');
|
|
230
|
+
const result = {};
|
|
231
|
+
const seen = new Set();
|
|
232
|
+
while (!isPunct('}')) {
|
|
233
|
+
const key = peek();
|
|
234
|
+
if (key.type !== 'name' && key.type !== 'string') fail(`a key expected, ${describe(key)} found`);
|
|
235
|
+
if (key.type === 'name' && KEYWORDS.has(key.value)) fail(`«${key.value}» cannot be a key`);
|
|
236
|
+
if (seen.has(key.value)) fail(`the key «${key.value}» repeats`, key);
|
|
237
|
+
seen.add(key.value);
|
|
238
|
+
at += 1;
|
|
239
|
+
expect(':');
|
|
240
|
+
Object.defineProperty(result, key.value, { value: value(), enumerable: true, writable: true, configurable: true });
|
|
241
|
+
if (isPunct(',')) at += 1;
|
|
242
|
+
else if (!isPunct('}')) fail(`«,» or «}» expected, ${describe(peek())} found`);
|
|
243
|
+
}
|
|
244
|
+
at += 1;
|
|
245
|
+
return result;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function value() {
|
|
249
|
+
const token = peek();
|
|
250
|
+
if (token.type === 'string' || token.type === 'number') {
|
|
251
|
+
at += 1;
|
|
252
|
+
return token.value;
|
|
253
|
+
}
|
|
254
|
+
if (token.type === 'name') {
|
|
255
|
+
if (token.value === 'true' || token.value === 'false') {
|
|
256
|
+
at += 1;
|
|
257
|
+
return token.value === 'true';
|
|
258
|
+
}
|
|
259
|
+
if (token.value === 'null') {
|
|
260
|
+
at += 1;
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
return reference();
|
|
264
|
+
}
|
|
265
|
+
if (isPunct('[')) return array();
|
|
266
|
+
if (isPunct('{')) return object();
|
|
267
|
+
return fail(`a value expected, ${describe(token)} found`);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
expect('(');
|
|
271
|
+
if (!isPunct('{')) fail(`the description is one object: «({» expected, ${describe(peek())} found`);
|
|
272
|
+
const model = object();
|
|
273
|
+
expect(')');
|
|
274
|
+
expect(';');
|
|
275
|
+
if (peek().type !== 'end') fail(`nothing may follow «);», ${describe(peek())} found`);
|
|
276
|
+
return model;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
280
|
+
const file = process.argv[2];
|
|
281
|
+
if (!file) {
|
|
282
|
+
console.error('usage: node flow-syntax.mjs <file>');
|
|
283
|
+
process.exit(2);
|
|
284
|
+
}
|
|
285
|
+
try {
|
|
286
|
+
console.log(JSON.stringify(parse(readFileSync(file, 'utf8'))));
|
|
287
|
+
} catch (error) {
|
|
288
|
+
if (!(error instanceof FlowSyntaxError)) throw error;
|
|
289
|
+
console.log(`flow syntax: ${error.message}`);
|
|
290
|
+
process.exit(1);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
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 the previous refusal,
|
|
11
|
+
* the one move is the owner's menu: the options of `words.menu`, with the number of the task put in.
|
|
12
|
+
*
|
|
13
|
+
* The case of the silent hosting counts only when the measurement itself stopped on the silence: a
|
|
14
|
+
* read that failed for a state passed over says nothing when a later local exit is unmet. Any other
|
|
15
|
+
* case the hosting could not answer is not met.
|
|
16
|
+
*/
|
|
17
|
+
import { evaluateCondition } from './flow-condition.mjs';
|
|
18
|
+
import { stepsOfProgress } from './work-steps-lib.mjs';
|
|
19
|
+
|
|
20
|
+
/** The measurer whose answer depends on where the measurement stopped. */
|
|
21
|
+
const SILENCE = 'measure.host.silent';
|
|
22
|
+
|
|
23
|
+
/** The measurers that name why the next move is the owner's menu. */
|
|
24
|
+
const MENU_CAUSES = { unread: 'measure.session.unread', forbidden: 'measure.session.forbidden', idle: 'measure.session.idle' };
|
|
25
|
+
|
|
26
|
+
/** The first release case met, or null. `read` answers a measurer by its reference. */
|
|
27
|
+
export function releaseCase(model, read, result) {
|
|
28
|
+
const stoppedOnSilence = result.state !== null && result.reason !== null;
|
|
29
|
+
const answer = (name) => {
|
|
30
|
+
try {
|
|
31
|
+
return read(name);
|
|
32
|
+
} catch (error) {
|
|
33
|
+
// A case the hosting could not answer is not met: an unknown fact releases nothing.
|
|
34
|
+
if (error?.name === 'HostSilent') return false;
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const reader = (name) => (name === SILENCE ? stoppedOnSilence && answer(name) : answer(name));
|
|
39
|
+
return model.release.find((entry) => evaluateCondition(entry.when, reader)) ?? null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Why the next move is the owner's menu: { by: '<guard>' }, { idle: true }, or null. A measurer the
|
|
44
|
+
* description does not declare, or the hosting could not answer, names no cause. An unread
|
|
45
|
+
* background task comes first, { unread: { task, output, agent } }: while it is unread the move is to
|
|
46
|
+
* read it, and no menu is offered.
|
|
47
|
+
*/
|
|
48
|
+
export function menuCause(read) {
|
|
49
|
+
const answer = (name) => {
|
|
50
|
+
try {
|
|
51
|
+
return read(name);
|
|
52
|
+
} catch {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const unread = answer(MENU_CAUSES.unread);
|
|
57
|
+
if (unread) return { unread };
|
|
58
|
+
const by = answer(MENU_CAUSES.forbidden);
|
|
59
|
+
if (by) return { by: String(by) };
|
|
60
|
+
return answer(MENU_CAUSES.idle) ? { idle: true } : null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** The options of the owner's menu: `words.menu`, the number of the task put in place of N. */
|
|
64
|
+
export function menuOptions(words, task) {
|
|
65
|
+
return (words.menu ?? []).map((option) => (task ? option.replace(/RT-N$/, `RT-${task}`) : option));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** The current step of a progress text and the count of steps not done: { number, name, left }, or null. */
|
|
69
|
+
export function currentStep(progress) {
|
|
70
|
+
const steps = stepsOfProgress(progress ?? '').steps;
|
|
71
|
+
const step = steps.find((s) => s.mark === '>');
|
|
72
|
+
return step ? { number: step.number, name: step.name, left: steps.filter((s) => s.mark !== 'x').length } : null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The reason of a held turn: the measured state, its action, and the step when the stages go on. With a
|
|
77
|
+
* cause of the menu the one move is the owner's menu instead.
|
|
78
|
+
*/
|
|
79
|
+
export function holdReason(model, result, step, menu = null) {
|
|
80
|
+
const total = model.states.length;
|
|
81
|
+
const state = model.states[result.index - 1];
|
|
82
|
+
const lines = [`The scenario is not over: the work stands in the state \`${result.state}\` (${result.index} of ${total}), whose exit is not met.`];
|
|
83
|
+
if (menu?.cause?.unread) {
|
|
84
|
+
const { task, output, agent } = menu.cause.unread;
|
|
85
|
+
if (agent) {
|
|
86
|
+
lines.push(`The background agent \`${task}\` ended after the last call, and its notice has not been read.`);
|
|
87
|
+
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.');
|
|
88
|
+
} else {
|
|
89
|
+
const where = output ? ` — its output is \`${output}\`` : '';
|
|
90
|
+
lines.push(`The background task \`${task}\` ended after the last call, and its notice has not been read${where}.`);
|
|
91
|
+
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.');
|
|
92
|
+
}
|
|
93
|
+
} else if (menu?.cause) {
|
|
94
|
+
lines.push(
|
|
95
|
+
menu.cause.idle
|
|
96
|
+
? 'The previous refusal named a move, and no call followed it.'
|
|
97
|
+
: `The check \`${menu.cause.by}\` refused the same step twice for the same reason.`,
|
|
98
|
+
);
|
|
99
|
+
const options = menuOptions(model.words, menu.task);
|
|
100
|
+
lines.push(`The one move is the owner's menu: ask through the question tool with exactly these options — ${options.map((o) => `«${o}»`).join(', ')}.`);
|
|
101
|
+
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; «стоп» ends the turn.');
|
|
102
|
+
return lines.join('\n');
|
|
103
|
+
}
|
|
104
|
+
if (step && state?.key === 'stage') {
|
|
105
|
+
lines.push(`${step.left} steps of the plan are not done, counted by \`node tools/check-work-steps.mjs\`.`);
|
|
106
|
+
lines.push(`The next move is step ${step.number} «${step.name}»: do it, then measure it — \`node tools/task-flow-script.mjs step ${step.number}\`.`);
|
|
107
|
+
} else {
|
|
108
|
+
lines.push(`The next move is the action of this state: ${state?.action ?? ''} (pattern \`${state?.pattern ?? ''}\`).`);
|
|
109
|
+
}
|
|
110
|
+
lines.push('`node tools/task-flow-script.mjs measure` names the exits read.');
|
|
111
|
+
return lines.join('\n');
|
|
112
|
+
}
|
|
@@ -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)));
|