@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,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The epic of the work, for the measurers that read it. The task the branch carries names its epic
|
|
3
|
+
* on the card. A branch without a task number takes the epic of the working copy from the assignment
|
|
4
|
+
* table; such an epic merged into the main branch or with its card closed counts as absent — the copy
|
|
5
|
+
* then leads nothing. The plan of the epic lies in the plans directory of the working copy.
|
|
6
|
+
*/
|
|
7
|
+
import { findEpicPlan, taskOfBranch } from './epic-text.mjs';
|
|
8
|
+
|
|
9
|
+
/** The plans directory of the tree. */
|
|
10
|
+
export const PLANS = 'docs/plans';
|
|
11
|
+
|
|
12
|
+
const planOf = (tree, number) =>
|
|
13
|
+
findEpicPlan(
|
|
14
|
+
tree
|
|
15
|
+
.list(PLANS)
|
|
16
|
+
.filter((name) => name.endsWith('.md'))
|
|
17
|
+
.map((name) => tree.read(`${PLANS}/${name}`) ?? ''),
|
|
18
|
+
number,
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
/** The epic of the copy is alive: its card is not closed and its PR into the main branch is not merged. */
|
|
22
|
+
const alive = (host, plan) => {
|
|
23
|
+
const card = host.issue(plan.epic);
|
|
24
|
+
if (card && !card.open) return false;
|
|
25
|
+
return !(plan.branch && host.pulls(plan.branch).some((p) => p.base === 'main' && p.state === 'MERGED'));
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The task the branch carries, or null. The epic branch has the same form as a task branch — the key
|
|
30
|
+
* and a number — and reads as a branch without a task number: a plan of the epic with that number
|
|
31
|
+
* names it as its branch.
|
|
32
|
+
*/
|
|
33
|
+
export function workTask({ git, tree }) {
|
|
34
|
+
const branch = git.branch();
|
|
35
|
+
const number = taskOfBranch(branch);
|
|
36
|
+
if (number === null) return null;
|
|
37
|
+
return planOf(tree, number)?.branch === branch ? null : number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The plan of the epic of the work: { epic, branch, rows }, or null where there is none. */
|
|
41
|
+
export function epicOfWork({ git, host, tree }) {
|
|
42
|
+
const task = workTask({ git, tree });
|
|
43
|
+
if (task === null) {
|
|
44
|
+
const number = tree.copyEpic();
|
|
45
|
+
const plan = number === null ? null : planOf(tree, number);
|
|
46
|
+
return plan && alive(host, plan) ? plan : null;
|
|
47
|
+
}
|
|
48
|
+
const epic = host.issue(task)?.epic;
|
|
49
|
+
return epic === null || epic === undefined ? null : planOf(tree, Number(epic));
|
|
50
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* The plan of an epic: its number, its branch and the rows of its task table, in their order.
|
|
4
|
+
* A row is `| <#> | <KEY>-<n> — <name> | <state> |`; the state «отложено» defers the task,
|
|
5
|
+
* «влито» marks it merged. Any other state, the old mark «шаг владельца» among them, is an ordinary
|
|
6
|
+
* row.
|
|
7
|
+
*/
|
|
8
|
+
export function epicPlan(text) {
|
|
9
|
+
const epic = text.match(/\*\*Эпик:\*\*\s+[A-Z]+-(\d+)/)?.[1] ?? null;
|
|
10
|
+
const branch = text.match(/\*\*Ветка эпика:\*\*\s+`([^`]+)`/)?.[1] ?? null;
|
|
11
|
+
const rows = [];
|
|
12
|
+
for (const line of text.split('\n')) {
|
|
13
|
+
const m = line.match(/^\|\s*(?:\d+|—|-)\s*\|\s*[A-Z]+-(\d+)\b[^|]*\|\s*([^|]*?)\s*\|\s*$/);
|
|
14
|
+
if (!m) continue;
|
|
15
|
+
const state = m[2];
|
|
16
|
+
rows.push({
|
|
17
|
+
task: Number(m[1]),
|
|
18
|
+
state,
|
|
19
|
+
deferred: state === 'отложено',
|
|
20
|
+
merged: state === 'влито',
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return { epic: epic === null ? null : Number(epic), branch, rows };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The plan of the epic numbered so among the texts of the plans directory, or null. */
|
|
27
|
+
export function findEpicPlan(texts, epic) {
|
|
28
|
+
return texts.map(epicPlan).find((p) => p.epic === epic) ?? null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The task number a branch name carries, by the key of the plan, or null. */
|
|
32
|
+
export function taskOfBranch(branch) {
|
|
33
|
+
const m = String(branch).match(/^[A-Z]+-(\d+)-[a-z0-9][a-z0-9-]*$/);
|
|
34
|
+
return m ? Number(m[1]) : null;
|
|
35
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The measurer «measure.epic» — the exits that read the epic of the work: its plan in the plans
|
|
3
|
+
* directory, its branch and its card.
|
|
4
|
+
*
|
|
5
|
+
* declared — exit 2: the epic branch stands on the server or went into the main branch by the PR of
|
|
6
|
+
* the epic, and the epic card left the first column or is closed. Kept for the life of the branch
|
|
7
|
+
* once met.
|
|
8
|
+
*
|
|
9
|
+
* nextTaken — exit 11: every unmerged, unblocked task of the epic other than the current one has a
|
|
10
|
+
* branch, locally or on the server; with no such task the exit is met. A task is blocked when it is
|
|
11
|
+
* deferred. A task with a branch standing
|
|
12
|
+
* before a task without one does not meet the exit: the plan still holds work nobody took.
|
|
13
|
+
*
|
|
14
|
+
* mergedMarked — exit 12: every task not deferred with a merged PR of its branch is marked
|
|
15
|
+
* «влито», except the task merged last, whatever its row, and the task of the last row: the mark is
|
|
16
|
+
* set by the branch of the next task, and these have none. A mark on a task whose merged PR the
|
|
17
|
+
* hosting does not list counts while no branch of it is on the server and no PR of its branches is
|
|
18
|
+
* open or closed unmerged. Until then state 13 would demand the PR of
|
|
19
|
+
* an epic whose tasks are not in its branch.
|
|
20
|
+
*
|
|
21
|
+
* finished — exit 13: the tip of the branch of every task of the epic that is not deferred lies in
|
|
22
|
+
* the epic branch or in the main branch on the server, and the PR of the epic into the main branch
|
|
23
|
+
* exists in any state. The tip is the local branch, the branch on the server, or the head of its
|
|
24
|
+
* merged PR when the server removed the branch.
|
|
25
|
+
*/
|
|
26
|
+
import { epicOfWork } from './epic-of.mjs';
|
|
27
|
+
import { taskOfBranch } from './epic-text.mjs';
|
|
28
|
+
|
|
29
|
+
export function declared({ git, host, tree }) {
|
|
30
|
+
return () => {
|
|
31
|
+
const plan = epicOfWork({ git, host, tree });
|
|
32
|
+
if (!plan?.branch) return false;
|
|
33
|
+
const key = `exit2:${plan.epic}`;
|
|
34
|
+
if (host.recalled(key)) return true;
|
|
35
|
+
const onServer = host.remoteBranch(plan.branch) || host.pulls(plan.branch).some((p) => p.base === 'main' && p.state === 'MERGED');
|
|
36
|
+
const card = host.issue(plan.epic);
|
|
37
|
+
const met = onServer && card !== null && (!card.open || (card.status !== null && card.status !== 'backlog'));
|
|
38
|
+
if (met) host.remember(key);
|
|
39
|
+
return met;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** A row the work does not wait for: deferred by the owner's word naming the task. */
|
|
44
|
+
const blocked = (row) => row.deferred;
|
|
45
|
+
|
|
46
|
+
const prefix = (task) => `RT-${task}-`;
|
|
47
|
+
|
|
48
|
+
export function nextTaken({ git, host, tree }) {
|
|
49
|
+
return () => {
|
|
50
|
+
const plan = epicOfWork({ git, host, tree });
|
|
51
|
+
if (!plan) return false;
|
|
52
|
+
const current = taskOfBranch(git.branch());
|
|
53
|
+
// A task with a merged PR is not ahead even unmarked: the hosting removes its branch on merge.
|
|
54
|
+
const merged = new Set(host.mergedPulls().map((p) => taskOfBranch(p.head)).filter((n) => n !== null));
|
|
55
|
+
const ahead = plan.rows.filter((row) => !row.merged && !merged.has(row.task) && row.task !== current && !blocked(row));
|
|
56
|
+
return ahead.every((row) => git.branches(prefix(row.task)).length > 0 || host.remoteBranches(prefix(row.task)).length > 0);
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function mergedMarked({ git, host, tree }) {
|
|
61
|
+
return () => {
|
|
62
|
+
const plan = epicOfWork({ git, host, tree });
|
|
63
|
+
if (!plan) return false;
|
|
64
|
+
// The moment of the merge per task: the latest of its merged PRs.
|
|
65
|
+
const mergedAt = new Map();
|
|
66
|
+
for (const p of host.mergedPulls()) {
|
|
67
|
+
const task = taskOfBranch(p.head);
|
|
68
|
+
if (task === null) continue;
|
|
69
|
+
const at = p.mergedAt ?? '';
|
|
70
|
+
if (!mergedAt.has(task) || at > mergedAt.get(task)) mergedAt.set(task, at);
|
|
71
|
+
}
|
|
72
|
+
const live = plan.rows.filter((row) => !row.deferred);
|
|
73
|
+
// The task merged last has no next branch to mark it by: its merged PR counts alone. Tasks
|
|
74
|
+
// merged in the same second are all last.
|
|
75
|
+
const lastAt = [...live].filter((row) => mergedAt.has(row.task)).reduce((at, row) => (mergedAt.get(row.task) > at ? mergedAt.get(row.task) : at), '');
|
|
76
|
+
const isLast = (row) => mergedAt.has(row.task) && mergedAt.get(row.task) === lastAt;
|
|
77
|
+
// The last row has no next task either: a chain merged top-down leaves it merged before the rest.
|
|
78
|
+
const lastRow = live.at(-1) ?? null;
|
|
79
|
+
return live.every((row) => {
|
|
80
|
+
if (mergedAt.has(row.task)) return row.merged || isLast(row) || row === lastRow;
|
|
81
|
+
// A mark with no merged PR in view stands for a merge past the window of the hosting: the
|
|
82
|
+
// hosting removed its branch on merge, so a branch left on the server, or any PR of its
|
|
83
|
+
// branches open or closed unmerged, says the mark is ahead of the work.
|
|
84
|
+
return row.merged && !host.remoteBranches(prefix(row.task)).length && !openPullOrClosedUnmerged({ git, host }, row.task);
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** A PR of a branch of the task is open or closed unmerged; the branches are the local and the server ones. */
|
|
90
|
+
const openPullOrClosedUnmerged = ({ git, host }, task) => {
|
|
91
|
+
const names = new Set([...git.branches(prefix(task)), ...host.remoteBranches(prefix(task))].map((b) => b.name));
|
|
92
|
+
return [...names].some((name) => host.pulls(name).some((p) => p.state === 'OPEN' || p.state === 'CLOSED'));
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/** The tip of the branch of a task: local, on the server, or the head of its merged PR. */
|
|
96
|
+
const tipOf = ({ git, host }, task) =>
|
|
97
|
+
git.branches(prefix(task))[0]?.sha ??
|
|
98
|
+
host.remoteBranches(prefix(task))[0]?.sha ??
|
|
99
|
+
host.mergedPulls().find((p) => taskOfBranch(p.head) === task)?.headRefOid ??
|
|
100
|
+
null;
|
|
101
|
+
|
|
102
|
+
export function finished({ git, host, tree }) {
|
|
103
|
+
return () => {
|
|
104
|
+
const plan = epicOfWork({ git, host, tree });
|
|
105
|
+
if (!plan?.branch) return false;
|
|
106
|
+
const landed = plan.rows
|
|
107
|
+
.filter((row) => !row.deferred)
|
|
108
|
+
.every((row) => {
|
|
109
|
+
const tip = tipOf({ git, host }, row.task);
|
|
110
|
+
return tip !== null && (host.inRemote(tip, plan.branch) || host.inRemote(tip, 'main'));
|
|
111
|
+
});
|
|
112
|
+
return landed && host.pulls(plan.branch).some((p) => p.base === 'main');
|
|
113
|
+
};
|
|
114
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The measurer «measure.folder» — exit 9: one commit of the branch removed the task folder and added
|
|
3
|
+
* a record to the description of the past.
|
|
4
|
+
*/
|
|
5
|
+
import { taskFolder, under } from './text.mjs';
|
|
6
|
+
|
|
7
|
+
export function archived({ git }) {
|
|
8
|
+
return () => {
|
|
9
|
+
const branch = git.branch();
|
|
10
|
+
if (!branch) return false;
|
|
11
|
+
const folder = taskFolder(branch);
|
|
12
|
+
return git
|
|
13
|
+
.commits()
|
|
14
|
+
.some((c) => c.deleted.some((p) => under(p, folder)) && c.added.some((p) => under(p, 'docs/archive')));
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The measurer «measure.footprint» — exit 8: after the commit of the plan the branch changed at least
|
|
3
|
+
* one file under every path of every footprint row marked «(правится)», and the directory of the
|
|
4
|
+
* product agreement the grill or the plan names under `proposed/` is gone from the head. A plan
|
|
5
|
+
* without marked rows is judged by `proposed/` alone.
|
|
6
|
+
*/
|
|
7
|
+
import { agreementLines, footprintRows, taskFolder, touches } from './text.mjs';
|
|
8
|
+
|
|
9
|
+
export function touched({ git }) {
|
|
10
|
+
return () => {
|
|
11
|
+
const branch = git.branch();
|
|
12
|
+
if (!branch) return false;
|
|
13
|
+
const folder = taskFolder(branch);
|
|
14
|
+
const sha = git.addedBy(`${folder}/plan.md`);
|
|
15
|
+
if (!sha) return false;
|
|
16
|
+
const plan = git.versionAt(`${folder}/plan.md`, sha) ?? '';
|
|
17
|
+
const commits = git.commits();
|
|
18
|
+
const changed = commits
|
|
19
|
+
.slice(commits.findIndex((c) => c.sha === sha) + 1)
|
|
20
|
+
.flatMap((c) => [...c.added, ...c.deleted, ...c.modified]);
|
|
21
|
+
const rowsMet = footprintRows(plan)
|
|
22
|
+
.filter((row) => row.edited)
|
|
23
|
+
.every((row) => row.paths.every((path) => changed.some((file) => touches(file, path))));
|
|
24
|
+
const texts = [git.lastVersion(`${folder}/grill.md`), plan].filter((t) => typeof t === 'string');
|
|
25
|
+
const proposed = texts.flatMap((t) => agreementLines(t).paths).filter((p) => p.includes('/proposed/'));
|
|
26
|
+
return rowsMet && !proposed.some((p) => git.existsAtHead(p));
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The measurer «measure.grill» — exit 1: the grill of the branch, or of a draft in the working copy,
|
|
3
|
+
* holds the owner's request as a quote and an answer. The grill of the branch is read from the
|
|
4
|
+
* working copy, and from the history once the folder is taken apart.
|
|
5
|
+
*/
|
|
6
|
+
import { grillAnswered, taskFolder } from './text.mjs';
|
|
7
|
+
|
|
8
|
+
export function written({ git, tree }) {
|
|
9
|
+
return () => {
|
|
10
|
+
const texts = [];
|
|
11
|
+
const branch = git.branch();
|
|
12
|
+
if (branch) {
|
|
13
|
+
const path = `${taskFolder(branch)}/grill.md`;
|
|
14
|
+
texts.push(tree.read(path) ?? git.lastVersion(path));
|
|
15
|
+
}
|
|
16
|
+
for (const name of tree.list('docs/tasks')) {
|
|
17
|
+
if (name.startsWith('_draft-')) texts.push(tree.read(`docs/tasks/${name}/grill.md`));
|
|
18
|
+
}
|
|
19
|
+
return texts.some((text) => typeof text === 'string' && grillAnswered(text));
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The measurer «measure.host» — the hosting did not answer: a read failed twice in this measurement.
|
|
3
|
+
* The engine reads it after the states, so it says whether the measured state stands on the silence.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export function silent({ host }) {
|
|
7
|
+
return () => host.silent();
|
|
8
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The measurer «measure.owner» — what the owner's last word says about the turn: an interrupt, or a
|
|
3
|
+
* push to go on. No typed word stops the work: the owner stops it by Esc.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** The mark the host writes into the record when the owner presses Esc. */
|
|
7
|
+
const INTERRUPT = /^\[Request interrupted by user/;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The owner's last word is the interrupt mark of Esc: a turn a background notice wakes after it is
|
|
11
|
+
* released until the owner writes again.
|
|
12
|
+
*/
|
|
13
|
+
export function interrupted({ owner }) {
|
|
14
|
+
return () => {
|
|
15
|
+
const last = owner.last();
|
|
16
|
+
return last !== null && INTERRUPT.test(last.trim());
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** The owner's last word pushes the work on by `words.nudge`, or names a task or an epic. */
|
|
21
|
+
export function nudged({ owner }) {
|
|
22
|
+
return ({ words }) => {
|
|
23
|
+
const last = owner.last();
|
|
24
|
+
if (last === null) return false;
|
|
25
|
+
return new RegExp(words.nudge ?? '(?!)', 'iu').test(last) || /(?<![\p{L}\d])[A-Z]+-\d+(?!\d)/u.test(last);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The measurer «measure.plan» — exit 5: a commit of the branch added the plan; every step of the
|
|
3
|
+
* plan as that commit wrote it has a check line whose expected result is a form of `expect`; and
|
|
4
|
+
* the approval mark lies in the common directory of git and names the commit of the plan and the
|
|
5
|
+
* place of the answer, where a session record of this repository holds the owner's «Одобряю …».
|
|
6
|
+
* A plan of a branch of `words.legacyBranches` was approved before the engine and needs no mark.
|
|
7
|
+
*/
|
|
8
|
+
import { taskFolder } from './text.mjs';
|
|
9
|
+
|
|
10
|
+
export function approved({ git, marks, steps, records }) {
|
|
11
|
+
return (data) => {
|
|
12
|
+
const words = data?.words ?? {};
|
|
13
|
+
const forms = Object.values(data?.expect ?? {}).map((form) => new RegExp(form.pattern));
|
|
14
|
+
const branch = git.branch();
|
|
15
|
+
if (!branch) return false;
|
|
16
|
+
const path = `${taskFolder(branch)}/plan.md`;
|
|
17
|
+
const sha = git.addedBy(path);
|
|
18
|
+
if (!sha) return false;
|
|
19
|
+
if ((words.legacyBranches ?? []).includes(branch)) return true;
|
|
20
|
+
const checks = steps.checks(git.versionAt(path, sha) ?? '');
|
|
21
|
+
const known = (c) => typeof c.expected === 'string' && forms.some((form) => form.test(c.expected.trim()));
|
|
22
|
+
if (checks.length === 0 || !checks.every(known)) return false;
|
|
23
|
+
// The answer is confirmed at its place in the session records, as the guard confirms it.
|
|
24
|
+
const task = branch.match(/^([A-Z]+-\d+)-/)?.[1] ?? branch;
|
|
25
|
+
return records.approvalFault(marks.approval(branch), sha, task) === null;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The measurer «measure.pr» — exit 10: a branch on the server holds the commit that took the task
|
|
3
|
+
* folder apart; the branch has a PR in any state with a reviewer; the task left the work column.
|
|
4
|
+
*/
|
|
5
|
+
import { taskOfBranch } from './epic-text.mjs';
|
|
6
|
+
import { taskFolder, under } from './text.mjs';
|
|
7
|
+
|
|
8
|
+
export function handed({ git, host }) {
|
|
9
|
+
return () => {
|
|
10
|
+
const branch = git.branch();
|
|
11
|
+
const task = taskOfBranch(branch);
|
|
12
|
+
if (task === null) return false;
|
|
13
|
+
const folder = taskFolder(branch);
|
|
14
|
+
const archived = git.commits().find((c) => c.deleted.some((p) => under(p, folder)) && c.added.some((p) => under(p, 'docs/archive')));
|
|
15
|
+
if (!archived || !host.remoteContains(archived.sha)) return false;
|
|
16
|
+
if (!host.pulls(branch).some((p) => p.reviewers.length > 0)) return false;
|
|
17
|
+
const card = host.issue(task);
|
|
18
|
+
return card !== null && (!card.open || card.status !== 'in-progress');
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The measurer «measure.progress».
|
|
3
|
+
*
|
|
4
|
+
* mirrors — exit 6: a version of the progress in the commit of the plan or later repeats the steps
|
|
5
|
+
* of the plan, numbers and names, and marks exactly one of them as going on now.
|
|
6
|
+
*
|
|
7
|
+
* done — exit 7: the progress of the working copy, and without the folder the last one in the
|
|
8
|
+
* history, marks every step of the plan done, and every done step has a green mark of its own. A
|
|
9
|
+
* plan without a single check line is judged by the marks of the progress alone.
|
|
10
|
+
*/
|
|
11
|
+
import { sameSteps, taskFolder } from './text.mjs';
|
|
12
|
+
|
|
13
|
+
export function mirrors({ git, steps }) {
|
|
14
|
+
return () => {
|
|
15
|
+
const branch = git.branch();
|
|
16
|
+
if (!branch) return false;
|
|
17
|
+
const folder = taskFolder(branch);
|
|
18
|
+
const sha = git.addedBy(`${folder}/plan.md`);
|
|
19
|
+
if (!sha) return false;
|
|
20
|
+
const planned = steps.ofPlan(git.versionAt(`${folder}/plan.md`, sha) ?? '');
|
|
21
|
+
if (planned.length === 0) return false;
|
|
22
|
+
const commits = git.commits();
|
|
23
|
+
return commits.slice(commits.findIndex((c) => c.sha === sha)).some((c) => {
|
|
24
|
+
const text = git.versionAt(`${folder}/progress.md`, c.sha);
|
|
25
|
+
if (text === null) return false;
|
|
26
|
+
const got = steps.ofProgress(text).steps;
|
|
27
|
+
return sameSteps(planned, got) && got.filter((s) => s.mark === '>').length === 1;
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function done({ git, tree, marks, steps }) {
|
|
33
|
+
return () => {
|
|
34
|
+
const branch = git.branch();
|
|
35
|
+
if (!branch) return false;
|
|
36
|
+
const folder = taskFolder(branch);
|
|
37
|
+
const plan = tree.read(`${folder}/plan.md`) ?? git.lastVersion(`${folder}/plan.md`);
|
|
38
|
+
const progress = tree.read(`${folder}/progress.md`) ?? git.lastVersion(`${folder}/progress.md`);
|
|
39
|
+
if (plan === null || progress === null) return false;
|
|
40
|
+
const planned = steps.ofPlan(plan);
|
|
41
|
+
if (planned.length === 0) return false;
|
|
42
|
+
const got = steps.ofProgress(progress).steps;
|
|
43
|
+
const unchecked = steps.checks(plan).every((c) => c.command === null);
|
|
44
|
+
return planned.every((p) => {
|
|
45
|
+
const step = got.find((s) => s.number === p.number);
|
|
46
|
+
if (step?.mark !== 'x') return false;
|
|
47
|
+
return unchecked || marks.step(branch, p.number)?.matched === true;
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The measurer «measure.session» — what this session did: a write to the tree, a role it runs as, a
|
|
3
|
+
* menu of a refusal that did not reach the owner, a step another check forbids, a stop after a
|
|
4
|
+
* refusal of a stop with no call in between, and a wait for a background task of its own.
|
|
5
|
+
*/
|
|
6
|
+
/** The tools that edit a file. */
|
|
7
|
+
const EDIT_TOOLS = new Set(['Edit', 'Write', 'MultiEdit', 'NotebookEdit']);
|
|
8
|
+
|
|
9
|
+
/** The session wrote to the tree: an edit of a file, or a command of the work of `words.write`. */
|
|
10
|
+
export function wrote({ session }) {
|
|
11
|
+
return ({ words, rules }) =>
|
|
12
|
+
session.toolUses().some((use) => EDIT_TOOLS.has(use.name) || (use.name === 'Bash' && rules.isWriteCommand(use.input.command ?? '', words)));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** The session runs as a role whose header gives it no edit tool: its report is its work. */
|
|
16
|
+
export function role({ session }) {
|
|
17
|
+
return () => {
|
|
18
|
+
const tools = session.roleTools(session.agent());
|
|
19
|
+
if (!tools || tools.includes('*')) return false;
|
|
20
|
+
return !/(?:^|[^\w])(?:Write|Edit|MultiEdit|NotebookEdit)(?:[^\w]|$)/.test(tools);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The menu of a refusal did not reach the owner a second time in a row: the last two refusals name
|
|
26
|
+
* the menu of `words.menu`, after each the agent called the menu, and no call was answered.
|
|
27
|
+
*/
|
|
28
|
+
export function menuLost({ session }) {
|
|
29
|
+
return ({ words }) => {
|
|
30
|
+
const options = (words.menu ?? []).map((option) => option.replace(/RT-N$/, ''));
|
|
31
|
+
if (options.length === 0) return false;
|
|
32
|
+
let streak = 0;
|
|
33
|
+
let awaiting = false;
|
|
34
|
+
for (const event of session.events()) {
|
|
35
|
+
if (event.kind === 'refusal') {
|
|
36
|
+
// A refusal with a menu the agent never tried to ask breaks the streak, as does any
|
|
37
|
+
// refusal that names no menu.
|
|
38
|
+
if (awaiting) streak = 0;
|
|
39
|
+
awaiting = options.every((option) => event.text.includes(option));
|
|
40
|
+
if (!awaiting) streak = 0;
|
|
41
|
+
} else if (event.kind === 'menu' && awaiting) {
|
|
42
|
+
streak = event.answered ? 0 : streak + 1;
|
|
43
|
+
awaiting = false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return streak >= 2;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** The hook of the engine itself, the one that holds a turn by the scenario. */
|
|
51
|
+
const ENGINE_HOOK = 'turn-exit-guard';
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Another check forbids the step: the last two refusals of calls come from the same guard for the
|
|
55
|
+
* same reason, and no call wrote to the tree after the first of them. Answers the name of the guard,
|
|
56
|
+
* or false — the exit check then names the owner's menu about that guard.
|
|
57
|
+
*/
|
|
58
|
+
/**
|
|
59
|
+
* The refusals of a stop stand after the last call and menu: the move they named was not taken. The
|
|
60
|
+
* stop is idle when one of them is the engine's own, or names no hook: true. When every one of them
|
|
61
|
+
* is another hook's, the stop is no idle one: { foreign: [<their hooks, each once>] }. While a
|
|
62
|
+
* background task of the session runs the stop is a wait, not an idle one: the executor has a move,
|
|
63
|
+
* and it is to wait.
|
|
64
|
+
*/
|
|
65
|
+
export function idle({ session, tree }) {
|
|
66
|
+
return () => {
|
|
67
|
+
const events = session.events();
|
|
68
|
+
let refusals = [];
|
|
69
|
+
for (const event of events) {
|
|
70
|
+
if (event.kind === 'call' || event.kind === 'menu') refusals = [];
|
|
71
|
+
else if (event.kind === 'refusal') refusals.push(event);
|
|
72
|
+
}
|
|
73
|
+
if (refusals.length === 0 || running(events, timeOf(session), scriptsOf(tree)).tasks.length > 0 || unreadOf(events) !== null) return false;
|
|
74
|
+
if (refusals.some((refusal) => !refusal.by || refusal.by === ENGINE_HOOK)) return true;
|
|
75
|
+
return { foreign: [...new Set(refusals.map((refusal) => refusal.by))] };
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The background task of the session whose notice has not reached it: { task, output, agent }, or null. A
|
|
81
|
+
* task is unread when its start stands in the record, its notice ended it with a result, and no call
|
|
82
|
+
* or menu followed that notice: the notice reaches the session only when the turn goes on, and a
|
|
83
|
+
* call is the first sign it went on. A task the session stopped itself, or one the harness killed,
|
|
84
|
+
* holds nothing.
|
|
85
|
+
*/
|
|
86
|
+
function unreadOf(events) {
|
|
87
|
+
const started = new Map();
|
|
88
|
+
const unread = new Map();
|
|
89
|
+
for (const event of events) {
|
|
90
|
+
if (event.kind === 'background' && event.task) {
|
|
91
|
+
// An agent a message resumed runs again under the same number and sends a notice again.
|
|
92
|
+
started.set(event.task, { ...event, over: false });
|
|
93
|
+
unread.delete(event.task);
|
|
94
|
+
} else if (event.kind === 'backgroundEnd') {
|
|
95
|
+
// A notice that names its call ends that run alone, as in the count of running tasks: a
|
|
96
|
+
// late copy of the notice of a former run does not end the run a message resumed.
|
|
97
|
+
const task = event.id ? [...started.values()].find((one) => one.id === event.id) : started.get(event.task);
|
|
98
|
+
if (!task || task.over) continue;
|
|
99
|
+
task.over = true;
|
|
100
|
+
if (event.stopped || event.status === 'killed' || event.status === 'stopped') continue;
|
|
101
|
+
unread.set(task.task, { task: task.task, output: event.output ?? task.output ?? null, agent: Boolean(task.agent) });
|
|
102
|
+
} else if (event.kind === 'call' || event.kind === 'menu') unread.clear();
|
|
103
|
+
}
|
|
104
|
+
return [...unread.values()].pop() ?? null;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** The measurer «measure.session.unread»: the unread background task of the session, or false. */
|
|
108
|
+
export function unread({ session }) {
|
|
109
|
+
return () => unreadOf(session.events()) ?? false;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* The command of a server started in the background: a stand, a showcase, a dev server. It never
|
|
114
|
+
* ends by itself and sends no notice, so it is no wait. A package script `serve`, `serve:*`,
|
|
115
|
+
* `storybook` or `storybook:*`; `storybook dev`; the serve target of nx or ng; a stand's `up.mjs`.
|
|
116
|
+
* A build, a lint or a search that only names the showcase is no server.
|
|
117
|
+
*/
|
|
118
|
+
const SERVER =
|
|
119
|
+
/\b(?:pnpm|npm|yarn)\s+(?:run\s+)?(?:serve|storybook)(?::[\w-]+)?(?![\w:-])|\bstorybook\s+dev\b|\b(?:nx|ng)\s+serve\b|\bnx\s+run\s+[\w@./-]+:serve\b|\bnx\s+run-many\b[^|;&]*?(?:-t|--targets?)[=\s]+serve\b|\bstand\/up\.mjs\b/;
|
|
120
|
+
|
|
121
|
+
/** A server at the start of a part of a command: a search that only names one is no server. */
|
|
122
|
+
const SERVER_AT_START = new RegExp(`^(?:(?:npx|pnpm\\s+exec|pnpm\\s+dlx)\\s+|node\\s+\\S*?)?(?:${SERVER.source})`);
|
|
123
|
+
|
|
124
|
+
/** The package script a server command runs: `serve:db` of `pnpm run serve:db`. */
|
|
125
|
+
const SCRIPT = /\b(?:pnpm|npm|yarn)\s+(?:run\s+)?((?:serve|storybook)(?::[\w-]+)?)(?![\w:-])/;
|
|
126
|
+
|
|
127
|
+
/** A script body that starts containers detached and ends by itself: `docker compose up -d`. */
|
|
128
|
+
const DETACHED = /\bup\b[^|;&]*?\s(?:-d|--detach)\b/;
|
|
129
|
+
|
|
130
|
+
/** A command of nothing but pauses and prints: `sleep 120; echo done`. It waits for nothing. */
|
|
131
|
+
const PAUSE = /^(?:sleep\s+[\d.]+[smhd]?|echo\b[^;&|]*|true|:)$/;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* A background command that is no wait: a server, which never ends by itself, or a bare pause. A
|
|
135
|
+
* package script whose body in `scripts` starts its containers detached ends by itself and is a
|
|
136
|
+
* wait like any other command.
|
|
137
|
+
*/
|
|
138
|
+
function noWait(command, scripts) {
|
|
139
|
+
const parts = command.split(/;|&&|\|\||(?<!&)&(?!&)/).map((part) => part.trim()).filter(Boolean);
|
|
140
|
+
if (parts.length > 0 && parts.every((part) => PAUSE.test(part))) return true;
|
|
141
|
+
// The command runs as long as its last part: a stand raised before a test run ends with the run.
|
|
142
|
+
const last = (parts.at(-1) ?? '').split('|')[0].trim().replace(/^(?:[A-Z_][A-Z0-9_]*=\S*\s+)+/, '');
|
|
143
|
+
if (!SERVER_AT_START.test(last)) return false;
|
|
144
|
+
const body = scripts?.[SCRIPT.exec(last)?.[1]];
|
|
145
|
+
return !(typeof body === 'string' && DETACHED.test(body));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** The `scripts` of the package file at the tree root, or null. */
|
|
149
|
+
function scriptsOf(tree) {
|
|
150
|
+
try {
|
|
151
|
+
return JSON.parse(tree?.read?.('package.json') ?? 'null')?.scripts ?? null;
|
|
152
|
+
} catch {
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* A background task older than this releases nothing: it is hung, in minutes. The longest command of
|
|
159
|
+
* the records of 14–22.11 ran 58 minutes; 3 of 810 tasks, all agents, ran longer than 90.
|
|
160
|
+
*/
|
|
161
|
+
export const BACKGROUND_BOUND = 90;
|
|
162
|
+
|
|
163
|
+
const timeOf = (session) => (typeof session.now === 'function' ? session.now() : Date.now());
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* The background tasks of the session that have a start, no end, and are younger than the bound at
|
|
167
|
+
* `now`, the ones older than it, and how many of the open tasks have released their stop:
|
|
168
|
+
* { tasks, hung, spent }. A watch of a CI run counts like any other task.
|
|
169
|
+
*/
|
|
170
|
+
function running(events, now, scripts = null) {
|
|
171
|
+
const open = new Map();
|
|
172
|
+
// The calls whose end stands in the record before their start: a command that finished at once.
|
|
173
|
+
const over = new Set();
|
|
174
|
+
// How many of the open tasks have released their stop: an ended turn takes one, the end of a
|
|
175
|
+
// task gives one back, and a call of a tool gives all back.
|
|
176
|
+
let spent = 0;
|
|
177
|
+
const close = (id) => {
|
|
178
|
+
if (!open.delete(id)) return false;
|
|
179
|
+
spent = Math.max(0, spent - 1);
|
|
180
|
+
return true;
|
|
181
|
+
};
|
|
182
|
+
for (const event of events) {
|
|
183
|
+
// A server never ends by itself, and a pause waits for nothing: no wait, and no hung task.
|
|
184
|
+
if (event.kind === 'background' && noWait(event.command ?? '', scripts)) continue;
|
|
185
|
+
if (event.kind === 'background') {
|
|
186
|
+
if (!over.has(event.id)) open.set(event.id, event);
|
|
187
|
+
} else if (event.kind === 'backgroundEnd') {
|
|
188
|
+
// A notice that names its call ends that run alone: an agent a message resumed runs
|
|
189
|
+
// under a new call, and a late copy of the notice of its former run does not end it.
|
|
190
|
+
if (event.id) {
|
|
191
|
+
if (!close(event.id)) over.add(event.id);
|
|
192
|
+
} else for (const [id, task] of open) if (event.task && task.task === event.task) close(id);
|
|
193
|
+
} else if (event.kind === 'ended') spent = Math.min(open.size, spent + 1);
|
|
194
|
+
else if (event.kind === 'call') spent = 0;
|
|
195
|
+
}
|
|
196
|
+
// A start stamped ahead of the clock by more than a minute is no start to wait for.
|
|
197
|
+
const age = (task) => now - task.at;
|
|
198
|
+
const timed = [...open.values()].filter((task) => Number.isFinite(task.at) && age(task) > -60_000);
|
|
199
|
+
const tasks = timed.filter((task) => age(task) < BACKGROUND_BOUND * 60_000);
|
|
200
|
+
// An agent that handed its report back while its own background work ran ends with no notice
|
|
201
|
+
// the record reads: past the bound it counts as no task, never as a hung one.
|
|
202
|
+
const hung = timed.filter((task) => !task.agent && age(task) >= BACKGROUND_BOUND * 60_000).map((task) => ({ task: task.task ?? task.id, minutes: Math.floor(age(task) / 60_000), output: task.output ?? null }));
|
|
203
|
+
return { tasks, hung, spent };
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* The measurer «measure.session.hung»: the oldest background task of the session that runs past the
|
|
208
|
+
* bound with no notice, { task, minutes, output }, or false. The hold names it, and the move is to
|
|
209
|
+
* read its output and stop or restart it, not to wait.
|
|
210
|
+
*/
|
|
211
|
+
export function hung({ session, tree }) {
|
|
212
|
+
return () => {
|
|
213
|
+
const { hung: over } = running(session.events(), timeOf(session), scriptsOf(tree));
|
|
214
|
+
return over.sort((a, b) => b.minutes - a.minutes)[0] ?? false;
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* The session waits for a background task of its own: more tasks run than turns ended on them with
|
|
220
|
+
* no call since. One task releases one stop — a chain of waits does not keep a turn released, and
|
|
221
|
+
* two tasks release two stops: the notice of the first wakes the session while the second runs.
|
|
222
|
+
*/
|
|
223
|
+
export function waiting({ session, tree }) {
|
|
224
|
+
return () => {
|
|
225
|
+
const { tasks, spent } = running(session.events(), timeOf(session), scriptsOf(tree));
|
|
226
|
+
return tasks.length > spent;
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export function forbidden({ session }) {
|
|
231
|
+
return ({ words, rules }) => {
|
|
232
|
+
const writes = (event) =>
|
|
233
|
+
event.kind === 'call' &&
|
|
234
|
+
!event.blocked &&
|
|
235
|
+
(EDIT_TOOLS.has(event.name) || (event.name === 'Bash' && rules.isWriteCommand(event.input.command ?? '', words)));
|
|
236
|
+
let last = null;
|
|
237
|
+
let before = null;
|
|
238
|
+
for (const event of session.events()) {
|
|
239
|
+
if (event.kind === 'blocked') {
|
|
240
|
+
before = last;
|
|
241
|
+
last = event;
|
|
242
|
+
} else if (writes(event)) {
|
|
243
|
+
before = null;
|
|
244
|
+
last = null;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
if (!last || !before) return false;
|
|
248
|
+
// While a background task ended unread, the move is to read it, not the owner's menu.
|
|
249
|
+
if (unreadOf(session.events()) !== null) return false;
|
|
250
|
+
return last.by === before.by && last.reason === before.reason ? last.by : false;
|
|
251
|
+
};
|
|
252
|
+
}
|