@rt-tools/agent-kit 0.24.0 → 0.27.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.
Files changed (312) hide show
  1. package/assets/agents/business-analyst.md +51 -50
  2. package/assets/agents/cargo-writer.md +54 -0
  3. package/assets/agents/conscience.md +37 -35
  4. package/assets/agents/project-manager.md +49 -48
  5. package/assets/agents/prose-editor.md +31 -29
  6. package/assets/agents/qa-engineer.md +50 -48
  7. package/assets/agents/rules-reviewer.md +63 -58
  8. package/assets/agents/skill-curator.md +83 -78
  9. package/assets/agents/spec-critic.md +34 -29
  10. package/assets/agents/spec-writer.md +35 -32
  11. package/assets/agents/strict-teacher.md +39 -37
  12. package/assets/checks/archive-age.mjs +48 -28
  13. package/assets/checks/archive-prune.mjs +16 -14
  14. package/assets/checks/board-epic-link.github.mjs +29 -0
  15. package/assets/checks/board-epics.github.mjs +286 -49
  16. package/assets/checks/board-folders.mjs +61 -0
  17. package/assets/checks/board-gh.github.mjs +35 -26
  18. package/assets/checks/board-long-work.github.mjs +29 -25
  19. package/assets/checks/board-paths.github.mjs +21 -16
  20. package/assets/checks/board-pull-state.github.mjs +168 -0
  21. package/assets/checks/board-runs.github.mjs +45 -43
  22. package/assets/checks/board-task-dirs.github.mjs +98 -0
  23. package/assets/checks/board-titles.github.mjs +19 -17
  24. package/assets/checks/board.github.mjs +133 -194
  25. package/assets/checks/check-archive-age.mjs +23 -19
  26. package/assets/checks/check-board.github.mjs +131 -263
  27. package/assets/checks/check-descriptions.mjs +30 -29
  28. package/assets/checks/check-doc-paths.mjs +91 -88
  29. package/assets/checks/check-dupes.mjs +84 -80
  30. package/assets/checks/check-file-size.mjs +74 -71
  31. package/assets/checks/check-glossary.mjs +47 -37
  32. package/assets/checks/check-hook-scope.mjs +30 -27
  33. package/assets/checks/check-lib-layers.mjs +22 -21
  34. package/assets/checks/check-profile-drift.mjs +48 -43
  35. package/assets/checks/check-prose-style.mjs +138 -39
  36. package/assets/checks/check-push-gate.mjs +53 -50
  37. package/assets/checks/check-reuse.mjs +50 -40
  38. package/assets/checks/check-schema-drift.mjs +104 -84
  39. package/assets/checks/check-specs.mjs +155 -134
  40. package/assets/checks/check-state-next.mjs +66 -52
  41. package/assets/checks/check-states.mjs +32 -30
  42. package/assets/checks/check-styles.mjs +52 -51
  43. package/assets/checks/check-turn-map.mjs +54 -46
  44. package/assets/checks/epic-table.github.mjs +268 -0
  45. package/assets/checks/lib-boundaries.mjs +32 -30
  46. package/assets/checks/lib-common.mjs +30 -29
  47. package/assets/checks/lib-domains.mjs +34 -34
  48. package/assets/checks/lib-manifests.mjs +17 -15
  49. package/assets/checks/lib-reexports.mjs +18 -18
  50. package/assets/checks/rt-kit-checks.config.mjs +187 -142
  51. package/assets/checks/signals.mjs +43 -39
  52. package/assets/checks/spec-anchors.mjs +114 -87
  53. package/assets/checks/spec-common.mjs +128 -84
  54. package/assets/checks/spec-contract.mjs +30 -30
  55. package/assets/checks/spec-proposed.mjs +27 -24
  56. package/assets/checks/spec-scenarios.mjs +51 -28
  57. package/assets/checks/specs-for.mjs +214 -0
  58. package/assets/checks/task-new.github.mjs +315 -61
  59. package/assets/commands/feedback.md +65 -59
  60. package/assets/commands/next-session.md +64 -57
  61. package/assets/commands/night.md +115 -0
  62. package/assets/commands/skill-curator.md +83 -79
  63. package/assets/defaults/gate-map.sh +108 -97
  64. package/assets/defaults/project.sh +232 -185
  65. package/assets/defaults/shell.sh +73 -68
  66. package/assets/defaults/turn-map.md +47 -44
  67. package/assets/docs/GLOSSARY.md +142 -65
  68. package/assets/hooks/browser-device-id.sh +16 -12
  69. package/assets/hooks/browser-guard-device-id.sh +34 -28
  70. package/assets/hooks/browser-guard-no-asking.sh +5 -4
  71. package/assets/hooks/browser-guard-no-listing.sh +12 -11
  72. package/assets/hooks/browser-guard-no-other-drivers.sh +48 -42
  73. package/assets/hooks/browser-guard-require-select.sh +34 -23
  74. package/assets/hooks/claim-guard.sh +62 -56
  75. package/assets/hooks/commit-msg.sh +14 -10
  76. package/assets/hooks/conscience-guard.sh +91 -45
  77. package/assets/hooks/constitution-index.sh +16 -16
  78. package/assets/hooks/deny-tail.sh +28 -26
  79. package/assets/hooks/dev-server-guard.sh +50 -43
  80. package/assets/hooks/dispatch.sh +60 -46
  81. package/assets/hooks/docs-guard.sh +100 -91
  82. package/assets/hooks/epic-over.sh +49 -0
  83. package/assets/hooks/epic-stop-guard.sh +108 -0
  84. package/assets/hooks/exam-guard.sh +105 -93
  85. package/assets/hooks/git-guard-delivery-conflict.sh +41 -36
  86. package/assets/hooks/git-guard-delivery-draft.sh +48 -38
  87. package/assets/hooks/git-guard-delivery-epic.sh +167 -0
  88. package/assets/hooks/git-guard-delivery-folder.sh +50 -43
  89. package/assets/hooks/git-guard-delivery-signature.sh +119 -53
  90. package/assets/hooks/git-guard-delivery.sh +223 -183
  91. package/assets/hooks/git-guard-main.sh +38 -34
  92. package/assets/hooks/git-guard-push-tests.sh +99 -87
  93. package/assets/hooks/glossary-load.sh +23 -22
  94. package/assets/hooks/grill-gate-ask.sh +12 -11
  95. package/assets/hooks/grill-gate.sh +94 -87
  96. package/assets/hooks/guard-note.sh +20 -19
  97. package/assets/hooks/handoff-entry-guard.sh +45 -25
  98. package/assets/hooks/handoff-write.sh +74 -67
  99. package/assets/hooks/hook-input.sh +67 -58
  100. package/assets/hooks/lint-after-edit.sh +95 -61
  101. package/assets/hooks/observe.sh +28 -26
  102. package/assets/hooks/override-write-guard.sh +23 -21
  103. package/assets/hooks/postmortem-guard.sh +42 -39
  104. package/assets/hooks/profile-check.sh +22 -20
  105. package/assets/hooks/proposal-guard.sh +57 -49
  106. package/assets/hooks/prose-style-guard.sh +49 -24
  107. package/assets/hooks/qa-dataid-guard.sh +83 -58
  108. package/assets/hooks/rerun-guard.sh +31 -30
  109. package/assets/hooks/reuse-first-guard.sh +108 -87
  110. package/assets/hooks/roles.sh +14 -14
  111. package/assets/hooks/rule-article.sh +39 -34
  112. package/assets/hooks/rule-source-guard.sh +47 -42
  113. package/assets/hooks/skill-gate-layers.sh +63 -57
  114. package/assets/hooks/skill-gate-rearm.sh +15 -8
  115. package/assets/hooks/skill-gate.sh +89 -81
  116. package/assets/hooks/skill-loaded.sh +10 -6
  117. package/assets/hooks/sql-guard-parse.sh +71 -66
  118. package/assets/hooks/sql-guard-request.sh +51 -46
  119. package/assets/hooks/sql-guard-target.sh +60 -51
  120. package/assets/hooks/sql-guard-write.sh +87 -79
  121. package/assets/hooks/sql-guard.sh +52 -47
  122. package/assets/hooks/stand-login-guard.sh +43 -37
  123. package/assets/hooks/task-context-load.sh +60 -55
  124. package/assets/hooks/task-flow-context.sh +87 -69
  125. package/assets/hooks/task-flow-draft-guard.sh +55 -48
  126. package/assets/hooks/task-flow-guard.sh +67 -64
  127. package/assets/hooks/turn-entry-load.sh +39 -32
  128. package/assets/hooks/turn-exit-guard.sh +260 -204
  129. package/assets/hooks/turn-exit-patterns.sh +63 -0
  130. package/assets/hooks/utf8.sh +14 -11
  131. package/assets/hooks/waiting-turn-guard.sh +104 -94
  132. package/assets/hooks/window-fill-guard.sh +70 -62
  133. package/assets/hooks/work-start-guard.sh +52 -49
  134. package/assets/hooks/write-targets.sh +99 -44
  135. package/assets/laws/autonomous-work.md +29 -27
  136. package/assets/laws/code-structure.md +31 -30
  137. package/assets/laws/delivery.md +170 -137
  138. package/assets/laws/entity-editing.md +52 -50
  139. package/assets/laws/entity-models.md +14 -13
  140. package/assets/laws/frontend-application.md +39 -38
  141. package/assets/laws/lib-imports.md +27 -27
  142. package/assets/laws/lists.md +31 -29
  143. package/assets/laws/navigation.md +37 -37
  144. package/assets/laws/observability.md +41 -40
  145. package/assets/laws/project-documentation.md +106 -99
  146. package/assets/laws/reuse-first.md +31 -29
  147. package/assets/laws/shared-code.md +27 -27
  148. package/assets/laws/verifiability.md +131 -124
  149. package/assets/laws/work-conduct.md +250 -244
  150. package/assets/patterns/admin-lists-screen.md +72 -69
  151. package/assets/patterns/admin-nav-item.md +51 -46
  152. package/assets/patterns/angular-patterns-state.md +32 -31
  153. package/assets/patterns/api-layer-pair.md +33 -31
  154. package/assets/patterns/autonomous-work-run.md +50 -49
  155. package/assets/patterns/browser-verification-measure.md +124 -88
  156. package/assets/patterns/browser-verification-stand.md +169 -157
  157. package/assets/patterns/component-structure-new.md +51 -42
  158. package/assets/patterns/dependencies-upgrade.md +55 -39
  159. package/assets/patterns/doc-style-human.md +55 -37
  160. package/assets/patterns/doc-style-sweep.md +82 -79
  161. package/assets/patterns/doc-style-trace.md +87 -81
  162. package/assets/patterns/doc-style-write.md +130 -122
  163. package/assets/patterns/entity-aside.md +77 -63
  164. package/assets/patterns/entity-models-new.md +37 -37
  165. package/assets/patterns/entity-store.md +33 -33
  166. package/assets/patterns/git-workflow-commit.azure.md +94 -87
  167. package/assets/patterns/git-workflow-commit.github.md +160 -142
  168. package/assets/patterns/git-workflow-commit.gitlab.md +96 -90
  169. package/assets/patterns/git-workflow-docker.md +165 -147
  170. package/assets/patterns/git-workflow-freshness.md +45 -45
  171. package/assets/patterns/git-workflow-merge.md +102 -94
  172. package/assets/patterns/git-workflow-migration.md +54 -52
  173. package/assets/patterns/git-workflow-pr-ready.md +57 -56
  174. package/assets/patterns/git-workflow-pr.azure.md +127 -122
  175. package/assets/patterns/git-workflow-pr.github.md +186 -177
  176. package/assets/patterns/git-workflow-pr.gitlab.md +139 -132
  177. package/assets/patterns/git-workflow-restart.md +35 -31
  178. package/assets/patterns/git-workflow-secrets.md +80 -73
  179. package/assets/patterns/git-workflow-stack.md +136 -107
  180. package/assets/patterns/lib-layers-move.md +62 -53
  181. package/assets/patterns/lib-layers-new.md +59 -45
  182. package/assets/patterns/observability-record.md +72 -67
  183. package/assets/patterns/platform-access-di.md +31 -29
  184. package/assets/patterns/reuse-first-extend.md +66 -61
  185. package/assets/patterns/shared-code-new.md +39 -38
  186. package/assets/patterns/spec-driven-domain.md +161 -151
  187. package/assets/patterns/spec-driven-rule.md +179 -168
  188. package/assets/patterns/spec-driven-sweep.md +41 -39
  189. package/assets/patterns/status-report-table.github.md +48 -36
  190. package/assets/patterns/styling-bem-component.md +42 -42
  191. package/assets/patterns/styling-bem-layout.md +39 -34
  192. package/assets/patterns/styling-bem-sheet.md +59 -58
  193. package/assets/patterns/task-flow-archive.md +222 -215
  194. package/assets/patterns/task-flow-close.md +234 -203
  195. package/assets/patterns/task-flow-handoff.md +154 -145
  196. package/assets/patterns/task-flow-resume.md +138 -133
  197. package/assets/patterns/task-flow-start.md +228 -202
  198. package/assets/patterns/testing-e2e.md +102 -101
  199. package/assets/patterns/testing-unit.md +77 -70
  200. package/assets/patterns/ts-procedure.md +32 -29
  201. package/assets/patterns/turn-entry-map.md +50 -48
  202. package/assets/pitfalls/agent-kit.md +172 -142
  203. package/assets/pitfalls/doc-style.md +96 -91
  204. package/assets/pitfalls/git-workflow.azure.md +49 -46
  205. package/assets/pitfalls/git-workflow.github.md +270 -234
  206. package/assets/pitfalls/git-workflow.gitlab.md +49 -45
  207. package/assets/pitfalls/spec-driven.md +73 -71
  208. package/assets/pitfalls/styling-bem.md +46 -40
  209. package/assets/pitfalls/task-flow.md +262 -246
  210. package/assets/pitfalls/testing.md +99 -92
  211. package/assets/pitfalls/turn-conduct.md +96 -81
  212. package/assets/rules/angular-patterns.md +81 -80
  213. package/assets/rules/api-layer.md +77 -74
  214. package/assets/rules/autonomous-work.md +87 -74
  215. package/assets/rules/browser-verification.md +223 -214
  216. package/assets/rules/component-structure.md +72 -69
  217. package/assets/rules/dependencies.md +74 -67
  218. package/assets/rules/deploy-flow.azure.md +118 -108
  219. package/assets/rules/deploy-flow.github.md +145 -135
  220. package/assets/rules/deploy-flow.gitlab.md +120 -110
  221. package/assets/rules/doc-style.md +201 -173
  222. package/assets/rules/entity-conventions.needs-admin.md +81 -79
  223. package/assets/rules/entity-models.md +73 -70
  224. package/assets/rules/git-workflow.azure.md +224 -228
  225. package/assets/rules/git-workflow.github.md +268 -239
  226. package/assets/rules/git-workflow.gitlab.md +218 -217
  227. package/assets/rules/lib-layers.md +85 -86
  228. package/assets/rules/lists.md +101 -97
  229. package/assets/rules/navigation.md +78 -78
  230. package/assets/rules/observability.needs-app.md +165 -153
  231. package/assets/rules/platform-access.md +76 -75
  232. package/assets/rules/reuse-first.md +153 -143
  233. package/assets/rules/shared-code.md +82 -79
  234. package/assets/rules/spec-driven.md +279 -260
  235. package/assets/rules/status-report.md +62 -58
  236. package/assets/rules/styling-bem.md +81 -77
  237. package/assets/rules/task-flow.md +303 -270
  238. package/assets/rules/testing.md +224 -209
  239. package/assets/rules/turn-conduct.md +262 -258
  240. package/assets/rules/turn-entry.md +92 -87
  241. package/assets/rules/typescript-conventions.md +94 -88
  242. package/assets/samples/specs/_template/spec.md +47 -47
  243. package/assets/samples/tasks/_template/grill.md +20 -20
  244. package/assets/samples/tasks/_template/plan.md +32 -30
  245. package/assets/samples/tasks/_template/progress.md +16 -16
  246. package/assets/skills/agent-kit-extend.md +129 -113
  247. package/assets/skills/agent-kit.md +259 -233
  248. package/assets/skills/write-a-skill.md +76 -71
  249. package/assets/templates/findings.md +19 -19
  250. package/assets/templates/gate-map.sh +16 -14
  251. package/assets/templates/implementation.md +28 -27
  252. package/assets/templates/pattern.md +17 -17
  253. package/assets/templates/pitfalls.md +6 -6
  254. package/assets/templates/postmortem.md +24 -23
  255. package/assets/templates/project.sh +24 -24
  256. package/assets/templates/proposal.md +62 -60
  257. package/assets/templates/rule.md +38 -38
  258. package/assets/workflows/feature.js +46 -46
  259. package/assets/workflows/plan.js +54 -54
  260. package/bin/agent-kit.d.ts.map +1 -1
  261. package/bin/agent-kit.js +8 -1
  262. package/bin/agent-kit.js.map +1 -1
  263. package/lib/cargo-prose.d.ts +41 -0
  264. package/lib/cargo-prose.d.ts.map +1 -0
  265. package/lib/cargo-prose.js +88 -0
  266. package/lib/cargo-prose.js.map +1 -0
  267. package/lib/cargo.d.ts +12 -1
  268. package/lib/cargo.d.ts.map +1 -1
  269. package/lib/cargo.js +8 -2
  270. package/lib/cargo.js.map +1 -1
  271. package/lib/catalog.d.ts +2 -0
  272. package/lib/catalog.d.ts.map +1 -1
  273. package/lib/catalog.js +4 -3
  274. package/lib/catalog.js.map +1 -1
  275. package/lib/commands.d.ts.map +1 -1
  276. package/lib/commands.js +5 -2
  277. package/lib/commands.js.map +1 -1
  278. package/lib/companion.js +3 -2
  279. package/lib/companion.js.map +1 -1
  280. package/lib/enroll.d.ts +7 -1
  281. package/lib/enroll.d.ts.map +1 -1
  282. package/lib/enroll.js +12 -3
  283. package/lib/enroll.js.map +1 -1
  284. package/lib/fate.d.ts +29 -0
  285. package/lib/fate.d.ts.map +1 -0
  286. package/lib/fate.js +147 -0
  287. package/lib/fate.js.map +1 -0
  288. package/lib/override-marks.d.ts +7 -0
  289. package/lib/override-marks.d.ts.map +1 -1
  290. package/lib/override-marks.js +14 -0
  291. package/lib/override-marks.js.map +1 -1
  292. package/lib/plan.d.ts +11 -0
  293. package/lib/plan.d.ts.map +1 -1
  294. package/lib/plan.js +10 -1
  295. package/lib/plan.js.map +1 -1
  296. package/lib/ship.d.ts +29 -9
  297. package/lib/ship.d.ts.map +1 -1
  298. package/lib/ship.js +44 -2
  299. package/lib/ship.js.map +1 -1
  300. package/lib/shipment.d.ts.map +1 -1
  301. package/lib/shipment.fixture.d.ts +8 -1
  302. package/lib/shipment.fixture.d.ts.map +1 -1
  303. package/lib/shipment.fixture.js +9 -0
  304. package/lib/shipment.fixture.js.map +1 -1
  305. package/lib/shipment.js +38 -5
  306. package/lib/shipment.js.map +1 -1
  307. package/lib/sync.d.ts.map +1 -1
  308. package/lib/sync.js +45 -11
  309. package/lib/sync.js.map +1 -1
  310. package/package.json +1 -1
  311. package/rt-tools-agent-kit-0.27.0.tgz +0 -0
  312. package/rt-tools-agent-kit-0.24.0.tgz +0 -0
@@ -1,23 +1,40 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
- * Заведение задачи, с которой начинается правка.
3
+ * Creating the task an edit starts with.
4
4
  *
5
- * Заведение состоит из четырёх шагов, и правка начинается только после всех
6
- * четырёх: тикет, номер в его заголовке, добавление на борду, состояние
7
- * «Backlog». Пока шаги переписывались руками из паттерна, промах на любом из
8
- * них давал задачу, которой нет в очереди работ: две такие простояли месяц.
5
+ * Creation is made of four steps, and the edit starts only after all four: the task, the number in
6
+ * its title, adding it to the board, the «Backlog» state. While the steps were rewritten by hand
7
+ * from a pattern, a miss on any of them gave a task that is not in the work queue: two such stood
8
+ * idle for a month.
9
9
  *
10
- * Ветку команда не заводит — печатает готовую строку. Заведение ветки отдельным
11
- * вызовом требует гард главной ветки: составную «создать ветку и сразу
12
- * коммитить» он отклоняет целиком.
10
+ * The command does not create the branch — it prints the ready line. Creating a branch by a call
11
+ * of its own is demanded by the main branch guard: the compound «create a branch and commit right
12
+ * away» it turns down whole.
13
13
  *
14
- * npm run task:new -- --title 'Письма владельцу не уходят' --label bug --label area:api
15
- * npm run task:new -- --title '…' --slug mail-owner-silence < описание.md
14
+ * npm run task:new -- --title 'Letters to the owner are not sent' --label bug --label area:api
15
+ * npm run task:new -- --title '…' --slug mail-owner-silence < description.md
16
+ * npm run task:new -- --epic --title 'Delivery goes by epics' --slug work-by-epics
17
+ * npm run task:new -- --epic-of 1921 --title '…' --slug command-creates-epic
18
+ * npm run task:new -- --outside-epic 'the owner asked for it apart' --title '…'
16
19
  *
17
- * Тело читается со стандартного ввода. Автор и исполнитель — учётная запись бота,
18
- * та же, от которой идут коммиты; `--assignee` перекрывает исполнителя.
20
+ * The body is read from standard input. The author and the assignee are the bot account, the same
21
+ * one the commits go from; `--assignee` overrides the assignee.
22
+ *
23
+ * With `--epic` the same four steps create an epic — the card the tasks of a piece of work wider
24
+ * than one branch hang on. Three things are added to them: the epic label, without which the audit
25
+ * has nothing to tell an epic card from an ordinary task by; a draft of the plan in the tree's
26
+ * plans directory, because the card carries neither the makeup of the epic nor the order of its
27
+ * tasks; and the path to that draft in the card body — the audit reads the plan by it, and a card
28
+ * without the path points into emptiness. The branch line printed at the end is taken from the main
29
+ * branch: the branch of an epic is the base for the branches of its tasks.
30
+ *
31
+ * With `--epic-of <number>` the created task is a task of that epic: the body says so in the very
32
+ * shape the audit reads the link by, and the printed branch line takes the branch of the epic as
33
+ * its base. Both are written here and not left to the executor's hand: the shape of the line is
34
+ * read by a machine from two sides at once, and the base of the branch is otherwise taken from the
35
+ * working copy, where at that minute any branch may be checked out.
19
36
  */
20
- import { cpSync, existsSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
37
+ import { cpSync, existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
21
38
  import { dirname, join, resolve } from 'node:path';
22
39
  import { fileURLToPath } from 'node:url';
23
40
 
@@ -40,9 +57,18 @@ import {
40
57
  taskState,
41
58
  unstampFolder,
42
59
  } from './board.mjs';
60
+ import { CONFIG, ROOT } from './rt-kit-checks.config.mjs';
61
+
62
+ /**
63
+ * What an epic is created by: the label of its card and the directory its plan is put in. Both are
64
+ * each tree's own words, and neither has a default — a plan laid at a guessed address is found by
65
+ * nobody, and a card without the label is an ordinary task to the audit.
66
+ */
67
+ const EPIC_LABEL = CONFIG.board?.epicLabel ?? '';
68
+ const PLANS_DIR = CONFIG.plansDir ?? '';
43
69
 
44
70
  function parseArgs(argv) {
45
- const args = { labels: [], assignee: BOT, title: null, slug: null };
71
+ const args = { labels: [], assignee: BOT, title: null, slug: null, epic: false, epicOf: null, outsideEpic: null };
46
72
  for (let index = 0; index < argv.length; index += 1) {
47
73
  const value = argv[index + 1];
48
74
  switch (argv[index]) {
@@ -62,8 +88,19 @@ function parseArgs(argv) {
62
88
  args.slug = value;
63
89
  index += 1;
64
90
  break;
91
+ case '--epic':
92
+ args.epic = true;
93
+ break;
94
+ case '--epic-of':
95
+ args.epicOf = Number(value);
96
+ index += 1;
97
+ break;
98
+ case '--outside-epic':
99
+ args.outsideEpic = value ?? '';
100
+ index += 1;
101
+ break;
65
102
  default:
66
- fail(`неизвестный ключ ${argv[index]}`);
103
+ fail(`unknown flag ${argv[index]}`);
67
104
  }
68
105
  }
69
106
  return args;
@@ -87,23 +124,139 @@ function readBody() {
87
124
 
88
125
  const args = parseArgs(process.argv.slice(2));
89
126
  if (!args.title) {
90
- fail("нужен --title '<Что не так>'");
127
+ fail("--title '<Что не так>' is required");
91
128
  }
92
129
  if (numberFromTitle(args.title) !== null || args.title.startsWith(`[${TASK_KEY}-`)) {
93
- fail('номер в заголовок не пишется руками: он известен только после заведения и дописывается сам');
130
+ fail('the number is not typed into the title by hand: it is known only after the creation and is appended by itself');
94
131
  }
95
132
  if (args.slug !== null && !/^[a-z0-9][a-z0-9-]*$/.test(args.slug)) {
96
- fail('slug — строчные латинские буквы, цифры и дефисы: имя ветки читают в списке из полусотни строк');
133
+ fail('slug is lowercase latin letters, digits and dashes: the branch name is read in a list of fifty lines');
134
+ }
135
+
136
+ /**
137
+ * A task outside an epic is not created — that is the whole of the requirement, and the refusal
138
+ * carries both lawful ways out of it, because in the shape «name the epic» alone it is read as
139
+ * "there is no way out" and gets bypassed by a call to the hosting past this command.
140
+ *
141
+ * The owner's word is the second way, and it goes into the call as text: work outside an epic
142
+ * happens — a one-line fix, a report from the outside — and only the owner names it as such. An
143
+ * empty reason is not a reason: it is indistinguishable from a flag typed to get past a refusal.
144
+ *
145
+ * A tree that has not named the epic label lives as before: there epics do not exist at all, and
146
+ * demanding one of every task would stop the work of every such tree on the day of installation.
147
+ */
148
+ if (EPIC_LABEL && !args.epic && args.epicOf === null && args.outsideEpic === null) {
149
+ fail(
150
+ 'a task outside an epic is not taken. Two ways: name the epic — `--epic-of <number>` — or name the word of the owner about work outside an epic — `--outside-epic "<the reason of the owner>"`'
151
+ );
152
+ }
153
+ if (args.outsideEpic !== null && args.outsideEpic.trim() === '') {
154
+ fail('--outside-epic "<the reason of the owner>": an empty reason is indistinguishable from a flag typed to get past the refusal');
155
+ }
156
+ if (args.outsideEpic !== null && (args.epic || args.epicOf !== null)) {
157
+ fail('--outside-epic goes with neither --epic nor --epic-of: work is either under an epic or outside one, and the word of the owner is needed only for the second');
158
+ }
159
+
160
+ if (args.epic && args.epicOf !== null) {
161
+ fail('--epic and --epic-of together: an epic is not a task of an epic. An epic inside an epic is not a shape this order knows');
162
+ }
163
+ if (args.epicOf !== null && !Number.isInteger(args.epicOf)) {
164
+ fail('--epic-of <number>: the number of the epic card, as it stands in the work queue');
97
165
  }
98
166
 
99
167
  /**
100
- * Токен машинной записи необязателен: не назвавшее его дерево заводит задачу учётной записью,
101
- * под которой залогинен клиент хостинга. Требование токена держало бы заведение задач у дерева,
102
- * машинной записи не заводившего, и у дерева, чью запись ограничил хостинг, — а без заведения
103
- * не начинается никакая работа вовсе. Кто именно завёл задачу, читается у неё самой.
168
+ * Everything an epic cannot be created without is asked before the creation, not after it: a card
169
+ * already made cannot be taken off the board by anyone but an administrator, and a refusal after
170
+ * the call leaves an epic without a plan and without a label — that is, invisible to the audit as
171
+ * an epic at all.
172
+ */
173
+ if (args.epic) {
174
+ if (!EPIC_LABEL) {
175
+ fail('the label of an epic card is not named — `board.epicLabel` in the check settings. Without it the audit has nothing to tell an epic from an ordinary task by');
176
+ }
177
+ if (!PLANS_DIR) {
178
+ fail('the directory of plans is not named — `plansDir` in the check settings. The plan of an epic lies outside the task folder: the folder dies with the merge, the epic outlives it');
179
+ }
180
+ if (!args.slug) {
181
+ fail('--slug <short-slug> is required for an epic: the plan file and the branch of the epic are named by it');
182
+ }
183
+ }
184
+
185
+ /** The label goes with the card, and the audit finds the epic by it — no second way. */
186
+ const labels = args.epic && !args.labels.includes(EPIC_LABEL) ? [...args.labels, EPIC_LABEL] : args.labels;
187
+
188
+ /**
189
+ * The token of the machine account is optional: a tree that has not named it creates the task
190
+ * under the account the hosting client is logged in as. Demanding the token would hold task
191
+ * creation in a tree that has not created a machine account, and in a tree whose account the
192
+ * hosting has limited — and without creation no work starts at all. Who exactly created the task
193
+ * is read off the task itself.
104
194
  */
105
195
  const token = botToken() ?? undefined;
106
196
 
197
+ /**
198
+ * The plan of the epic and the line about it in the card body.
199
+ *
200
+ * The audit takes the path to the plan from the body: the card has to name it anyway, and a
201
+ * setting read instead would become a second truth about where the plan of this very epic lies. So
202
+ * the path is written into the body by the same call that creates the file.
203
+ */
204
+ const planPath = args.epic ? `${PLANS_DIR.replace(/\/+$/, '')}/${args.slug}.md` : null;
205
+
206
+ /**
207
+ * The epic the task is created under, read from its card.
208
+ *
209
+ * The link is declared by the task body, and the audit reads exactly one shape of it: the word
210
+ * about the task standing right before the word about the epic. Written by hand, the line comes
211
+ * out in a shape of its own once out of three, and the audit then says the task belongs to no epic
212
+ * while the executor sees the epic named in the body.
213
+ *
214
+ * The path to the plan is taken from the epic card, as the audit takes it — a second address here
215
+ * would diverge from the first one silently. The branch of the epic is read from the plan: the
216
+ * plan names it, and the queue does not know branch names at all.
217
+ */
218
+ function epicOfCard(epicNumber) {
219
+ const card = ghJson(['issue', 'view', String(epicNumber), '--json', 'number,title,labels,body'], { token });
220
+ const labelled = (card.labels ?? []).some((label) => label.name === EPIC_LABEL);
221
+ if (!labelled) {
222
+ fail(`#${epicNumber} is not an epic: the card carries no label «${EPIC_LABEL}». A task hangs on an epic, and an epic is what the audit reads by that label`);
223
+ }
224
+ const named = String(card.body ?? '').match(/(?:^|[\s(`])([\w.-]+(?:\/[\w.-]+)+\.md)/);
225
+ const plan = named ? named[1] : null;
226
+ if (plan === null) {
227
+ fail(`the card of the epic #${epicNumber} names no path to its plan — there is nowhere to read what the epic holds, and the branch of the epic is named there too`);
228
+ }
229
+ return { plan, branch: epicBranchOf(plan, epicNumber) };
230
+ }
231
+
232
+ /**
233
+ * The branch of the epic, read from the header of its plan.
234
+ *
235
+ * Three spellings are accepted: the one this command writes, the bare word about a branch and the
236
+ * English one — the plans of a tree are translated one at a time, and a single spelling would take
237
+ * every plan but the freshest out of the reading in silence.
238
+ */
239
+ function epicBranchOf(plan, epicNumber) {
240
+ const path = join(ROOT, plan);
241
+ if (!existsSync(path)) {
242
+ return null;
243
+ }
244
+ const named = readFileSync(path, 'utf8').match(
245
+ new RegExp(`\\*\\*(?:Ветка эпика|Ветка|Branch):\\*\\*\\s*\`?(${TASK_KEY}-${epicNumber}-[a-z0-9][a-z0-9-]*)\`?`)
246
+ );
247
+ return named ? named[1] : null;
248
+ }
249
+
250
+ const epic = args.epicOf === null ? null : epicOfCard(args.epicOf);
251
+ const body = [
252
+ readBody(),
253
+ args.epic ? `Замысел эпика — ${planPath}` : '',
254
+ epic ? `Задача эпика #${args.epicOf}, замысел — ${epic.plan}` : '',
255
+ args.outsideEpic ? `Работа вне эпика — ${args.outsideEpic}` : '',
256
+ ]
257
+ .filter((part) => part !== '')
258
+ .join('\n\n');
259
+
107
260
  let number = null;
108
261
  try {
109
262
  const created = gh(
@@ -115,19 +268,19 @@ try {
115
268
  '--title',
116
269
  args.title,
117
270
  '--body',
118
- readBody(),
271
+ body,
119
272
  '--assignee',
120
273
  args.assignee,
121
- ...args.labels.flatMap((label) => ['--label', label]),
274
+ ...labels.flatMap((label) => ['--label', label]),
122
275
  ],
123
276
  { token }
124
277
  ).trim();
125
278
  number = Number(created.split('/').pop());
126
279
  if (!Number.isInteger(number)) {
127
- fail(`не разобрать номер заведённой задачи в ответе: ${created}`);
280
+ fail(`the number of the created task cannot be parsed in the answer: ${created}`);
128
281
  }
129
282
 
130
- // Номер известен только теперь, поэтому заголовок дописывается вторым вызовом.
283
+ // The number is known only now, so the title is appended by a second call.
131
284
  gh(['api', '-X', 'PATCH', `repos/${OWNER}/${REPO}/issues/${number}`, '-f', `title=[${TASK_KEY}-${number}] ${args.title}`], {
132
285
  token,
133
286
  });
@@ -141,31 +294,43 @@ try {
141
294
  `mutation { updateProjectV2ItemFieldValue(input: {projectId: "${PROJECT_ID}", itemId: "${itemId}", fieldId: "${STATUS_FIELD_ID}", value: {singleSelectOptionId: "${BACKLOG_OPTION_ID}"}}) { projectV2Item { id } } }`,
142
295
  { token }
143
296
  );
297
+
298
+ // The task of an epic becomes a sub-issue of the epic card. The line in the body says the same
299
+ // thing, but only to whoever opens the task: the board shows neither the makeup of an epic nor
300
+ // how much of it is done, and the count has to be assembled by hand from the list of open
301
+ // tasks. A sub-issue is the hosting's own link — the epic card gets the list and the progress,
302
+ // the task gets the line about its parent, and the board card gets the "done of total" bar.
303
+ //
304
+ // The link is asked by the numeric id of the task, not by its number: the endpoint takes the id.
305
+ if (args.epicOf !== null) {
306
+ const subId = ghJson(['api', `repos/${OWNER}/${REPO}/issues/${number}`, '--jq', '{id:.id}'], { token }).id;
307
+ gh(['api', '-X', 'POST', `repos/${OWNER}/${REPO}/issues/${args.epicOf}/sub_issues`, '-F', `sub_issue_id=${subId}`], { token });
308
+ }
144
309
  } catch (error) {
145
- const reason = error instanceof OfflineError ? `нет связи с GitHub: ${error.message}` : String(error.message ?? error);
310
+ const reason = error instanceof OfflineError ? `no connection to GitHub: ${error.message}` : String(error.message ?? error);
146
311
  if (number === null) {
147
312
  fail(reason);
148
313
  }
149
- // Тикет уже есть, а на борде его может не быть — ровно то состояние, из-за которого
150
- // задачи и терялись. Молчать здесь нельзя: номер печатается, чтобы доделать руками.
151
- console.error(`task-new: задача #${number} заведена, но доведена не до конца — ${reason}`);
152
- console.error(`task-new: проверь и доправь — npm run check:board`);
314
+ // The task already exists, and it may not be on the board — exactly the state tasks were being
315
+ // lost by. Staying silent here is not allowed: the number is printed to finish it by hand.
316
+ console.error(`task-new: the task #${number} is created but not finished — ${reason}`);
317
+ console.error(`task-new: check it and finish it — npm run check:board`);
153
318
  process.exit(1);
154
319
  }
155
320
 
156
- const branch = args.slug ? `${TASK_KEY}-${number}-${args.slug}` : `${TASK_KEY}-${number}-<короткий-slug>`;
321
+ const branch = args.slug ? `${TASK_KEY}-${number}-${args.slug}` : `${TASK_KEY}-${number}-<short-slug>`;
157
322
 
158
323
  /**
159
- * Папка задачи переименовывается здесь, потому что номер и имя ветки в этот момент известны
160
- * единственный раз за всю работу. Разбор просьбы владельца идёт до заведения задачи — до
161
- * конца разбора неизвестно даже, сколько задач из него выйдет, — и лежит в
162
- * `docs/tasks/_draft-<slug>`. Оставленный черновиком, он остаётся вне истории, а следующий
163
- * заход его не находит: хук запуска ищет папку по имени ветки.
324
+ * The task folder is renamed here, because the number and the branch name are known at this moment
325
+ * for the only time in the whole work. The grill of the owner's request goes before the task is
326
+ * created — until the grill is over it is not even known how many tasks will come out of it — and
327
+ * lies in `docs/tasks/_draft-<slug>`. Left as a draft, it stays outside the history, and the next
328
+ * session does not find it: the startup hook looks for the folder by the branch name.
164
329
  */
165
330
 
166
331
  function adoptDraft() {
167
332
  if (!args.slug) {
168
- console.log(`\nПапка задачи: --slug не задан, переименовать черновик нечем.`);
333
+ console.log(`\nThe task folder: --slug is not set, there is nothing to rename the draft by.`);
169
334
  return;
170
335
  }
171
336
  const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
@@ -173,66 +338,155 @@ function adoptDraft() {
173
338
  const target = join(root, 'docs/tasks', branch);
174
339
 
175
340
  if (existsSync(target)) {
176
- console.log(`\nПапка задачи уже на месте: docs/tasks/${branch}/`);
341
+ console.log(`\nThe task folder is already in place: docs/tasks/${branch}/`);
177
342
  } else if (existsSync(draft)) {
178
343
  renameSync(draft, target);
179
- // Черновик тоже собирают с образца, и шапка в нём та же: снимается она и здесь.
344
+ // The draft too is assembled from the sample, and the header in it is the same: it is
345
+ // taken off here as well.
180
346
  unstampFolder(target);
181
- console.log(`\nПапка задачи: docs/tasks/_draft-${args.slug}/ → docs/tasks/${branch}/`);
347
+ console.log(`\nThe task folder: docs/tasks/_draft-${args.slug}/ → docs/tasks/${branch}/`);
182
348
  } else {
183
349
  const template = join(root, 'docs/tasks/_template');
184
350
 
185
351
  if (!existsSync(template)) {
186
- console.log(`\nПапки задачи нет, и собрать её не с чего: образца ${'docs/tasks/_template'} в дереве не лежит`);
352
+ console.log(`\nThere is no task folder and nothing to assemble it from: the sample ${'docs/tasks/_template'} does not lie in the tree`);
187
353
  return;
188
354
  }
189
355
 
190
356
  cpSync(template, target, { recursive: true });
191
357
  unstampFolder(target);
192
- console.log(`\nПапка задачи собрана с образца: docs/tasks/${branch}/`);
358
+ console.log(`\nThe task folder is assembled from the sample: docs/tasks/${branch}/`);
193
359
  }
194
360
 
195
- // Шапку замысла читает гард: по ней он находит договорённость о продукте. Номер в ней
196
- // проставляется здесь же — руками его переписывают из подсказки и ошибаются.
361
+ // The header of the plan is read by a guard: by it the guard finds the product agreement. The
362
+ // number in it is set right here — by hand it is copied over from a hint and mistyped.
197
363
  const plan = join(target, 'plan.md');
198
364
  if (!existsSync(plan)) {
199
365
  return;
200
366
  }
201
367
  const before = readFileSync(plan, 'utf8');
202
- const after = before.replace(/^\*\*Задача:\*\*.*$/m, `**Задача:** ${TASK_KEY}-${number} · **Ветка:** ${branch}`);
368
+ // The key is read under two names: the package sample is English, and a tree folder created
369
+ // before the layer was translated is Russian. It is written in English.
370
+ const after = before.replace(/^\*\*(?:Task|Задача):\*\*.*$/m, `**Task:** ${TASK_KEY}-${number} · **Branch:** ${branch}`);
203
371
  if (after !== before) {
204
372
  writeFileSync(plan, after);
205
- console.log(`Шапка замысла проставлена: docs/tasks/${branch}/plan.md`);
373
+ console.log(`The header of the plan is filled in: docs/tasks/${branch}/plan.md`);
374
+ }
375
+ }
376
+
377
+ /**
378
+ * The draft of the epic plan. It is assembled here and not copied from a sample: the sample would
379
+ * have to be laid out at a fixed address, while the directory of plans is each tree's own — and a
380
+ * draft assembled here comes with the number, the title and the branch already filled in, which a
381
+ * copied one would leave to be typed by hand.
382
+ *
383
+ * An existing file is not overwritten: a plan written before the card is a lawful order — the
384
+ * makeup is thought out first, and the card is created under a ready one.
385
+ */
386
+ function writeEpicPlan() {
387
+ const path = join(ROOT, planPath);
388
+ if (existsSync(path)) {
389
+ console.log(`\nThe plan of the epic is already in place: ${planPath}`);
390
+ return;
206
391
  }
392
+ mkdirSync(dirname(path), { recursive: true });
393
+ writeFileSync(
394
+ path,
395
+ [
396
+ `# ${args.title}`,
397
+ '',
398
+ `**Эпик:** ${TASK_KEY}-${number} · **Ветка эпика:** \`${branch}\``,
399
+ '',
400
+ '## Что даёт',
401
+ '',
402
+ '<Возможность, ради которой эпик заведён: что владелец получит и чего не может сегодня.>',
403
+ '',
404
+ '## Как стоят ветки',
405
+ '',
406
+ `Ветка эпика отведена от главной, ветки задач — от неё, заявки задач идут в неё. <Стопкой`,
407
+ 'ветки задач стоят или каждая от ветки эпика — решает этот план, а не тот, кто заводит',
408
+ 'ветку.>',
409
+ '',
410
+ '## Состав',
411
+ '',
412
+ '| # | Задача | Состояние |',
413
+ '| --- | ---------------------------------------- | --------- |',
414
+ `| 1 | ${TASK_KEY}-<номер> — <что делает> | впереди |`,
415
+ '',
416
+ '## Чего эпик не делает',
417
+ '',
418
+ '- <Что лежит рядом и в эпик не входит.>',
419
+ '',
420
+ ].join('\n')
421
+ );
422
+ console.log(`\nThe draft of the epic plan: ${planPath}`);
207
423
  }
208
424
 
209
- adoptDraft();
425
+ if (args.epic) {
426
+ writeEpicPlan();
427
+ } else {
428
+ adoptDraft();
429
+ }
210
430
 
211
431
  console.log(`[${TASK_KEY}-${number}] ${args.title}`);
212
432
  console.log(`https://github.com/${OWNER}/${REPO}/issues/${number}`);
213
433
 
214
434
  /**
215
- * Пятый шаг: заведение подтверждается ответом очереди работ, а не выводом этой команды.
435
+ * The fifth step: creation is confirmed by the answer of the work queue, not by the output of this
436
+ * command.
216
437
  *
217
- * Все четыре шага выше отвечают за свои вызовы и молчат о том, видна ли задача тому, кто по
218
- * ней придёт. Шестнадцать заведений подряд так и напечатали номер со ссылкой, не попав в
219
- * очередь ни одно: учётная запись была ограничена хостингом, вызовы при этом отказа не дали.
438
+ * All four steps above answer for their own calls and stay silent about whether the task is visible
439
+ * to whoever comes for it. Sixteen creations in a row printed the number with a link that way, and
440
+ * not one of them landed in the queue: the account was limited by the hosting, and the calls gave
441
+ * no refusal at that.
220
442
  */
221
- let answer;
222
- try {
223
- answer = describeTaskState(number, taskState(number, { token }));
224
- } catch (error) {
225
- const reason = error instanceof OfflineError ? error.message : String(error.message ?? error);
226
- answer = describeTaskState(number, { offline: reason });
443
+ /**
444
+ * This is read more than once. The queue does not hand back a new card the same second it was
445
+ * created, and the reading goes as the next call after the adding: two creations in a row printed
446
+ * that the task is not in the queue while the card was in place. A false refusal here costs more
447
+ * than a delay — it pushes to create the card a second time, and only an administrator can take it
448
+ * off the board.
449
+ */
450
+ let unreachable = false;
451
+
452
+ function askQueue() {
453
+ try {
454
+ return describeTaskState(number, taskState(number, { token }));
455
+ } catch (error) {
456
+ // There was nothing to ask with — there is nothing to repeat: the answer is not late,
457
+ // there will be none at all.
458
+ unreachable = true;
459
+ const reason = error instanceof OfflineError ? error.message : String(error.message ?? error);
460
+ return describeTaskState(number, { offline: reason });
461
+ }
462
+ }
463
+
464
+ /** How long to wait between readings and how many times to re-read: the queue delay is seconds. */
465
+ const QUEUE_RETRIES = 3;
466
+ const QUEUE_PAUSE_MS = 1500;
467
+
468
+ let answer = askQueue();
469
+ for (let attempt = 1; !answer.ok && !unreachable && attempt < QUEUE_RETRIES; attempt += 1) {
470
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, QUEUE_PAUSE_MS);
471
+ answer = askQueue();
227
472
  }
228
473
  for (const line of answer.lines) {
229
474
  (answer.ok ? console.log : console.error)(`task-new: ${line}`);
230
475
  }
231
476
 
232
- console.log(`\nВетка заводится отдельным вызовом:\n git checkout -b ${branch}`);
233
- console.log(`Взятая в работу задача переставляется на борде:\n npm run task:move -- ${number} ${IN_PROGRESS_STATUS}`);
477
+ /**
478
+ * The branch of an epic is taken from the main branch, and the branches of its tasks from it: a
479
+ * base named here saves the executor from taking it from the working copy, where any branch may be
480
+ * checked out at that minute.
481
+ */
482
+ const base = args.epic ? ` origin/${CONFIG.deploy?.mainBranch || 'main'}` : epic?.branch ? ` ${epic.branch}` : '';
483
+ if (epic && !epic.branch) {
484
+ console.error(`task-new: the plan «${epic.plan}» does not name the branch of the epic — the base of the branch is taken by hand, and it is the branch of the epic, not the main one`);
485
+ }
486
+ console.log(`\nThe branch is created by a separate call:\n git checkout -b ${branch}${base}`);
487
+ console.log(`A task taken into work is moved on the board:\n npm run task:move -- ${number} ${IN_PROGRESS_STATUS}`);
234
488
 
235
489
  if (!answer.ok) {
236
- console.error(`task-new: проверь очередь работ целиком — npm run check:board`);
490
+ console.error(`task-new: check the whole work queue — npm run check:board`);
237
491
  process.exit(1);
238
492
  }