@otea/cli 0.0.0-stage → 0.1.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 (243) hide show
  1. package/LICENSE +661 -0
  2. package/README.es.md +151 -0
  3. package/README.md +252 -2
  4. package/THIRD_PARTY_NOTICES.md +114 -0
  5. package/bin/otea.mjs +28 -0
  6. package/dist/app/agent-detail.js +26 -0
  7. package/dist/app/agent-draft.js +429 -0
  8. package/dist/app/agent-prompts.js +52 -0
  9. package/dist/app/agents.js +77 -0
  10. package/dist/app/asking.js +43 -0
  11. package/dist/app/board-archive.js +243 -0
  12. package/dist/app/board-migration.js +272 -0
  13. package/dist/app/boards.js +870 -0
  14. package/dist/app/branch-owner.js +48 -0
  15. package/dist/app/brief.js +53 -0
  16. package/dist/app/choices.js +61 -0
  17. package/dist/app/collections.js +101 -0
  18. package/dist/app/context.js +1 -0
  19. package/dist/app/crop.js +56 -0
  20. package/dist/app/devices.js +62 -0
  21. package/dist/app/draft-request.js +82 -0
  22. package/dist/app/events.js +12 -0
  23. package/dist/app/evidence.js +287 -0
  24. package/dist/app/gates.js +610 -0
  25. package/dist/app/guide.js +37 -0
  26. package/dist/app/home.js +145 -0
  27. package/dist/app/init-boards.js +36 -0
  28. package/dist/app/intake.js +25 -0
  29. package/dist/app/item-search.js +141 -0
  30. package/dist/app/items.js +318 -0
  31. package/dist/app/keep-waiting.js +44 -0
  32. package/dist/app/land-order.js +107 -0
  33. package/dist/app/language.js +52 -0
  34. package/dist/app/launcher.js +56 -0
  35. package/dist/app/lease-take.js +54 -0
  36. package/dist/app/leases.js +86 -0
  37. package/dist/app/machine.js +39 -0
  38. package/dist/app/merged.js +89 -0
  39. package/dist/app/migrate.js +171 -0
  40. package/dist/app/next.js +1637 -0
  41. package/dist/app/notes.js +319 -0
  42. package/dist/app/notify-targets.js +113 -0
  43. package/dist/app/opened.js +25 -0
  44. package/dist/app/owner-only.js +34 -0
  45. package/dist/app/performance.js +28 -0
  46. package/dist/app/phone.js +97 -0
  47. package/dist/app/presence.js +596 -0
  48. package/dist/app/preset-views.js +25 -0
  49. package/dist/app/presets.js +129 -0
  50. package/dist/app/priority.js +156 -0
  51. package/dist/app/profile.js +86 -0
  52. package/dist/app/project.js +247 -0
  53. package/dist/app/proofs.js +179 -0
  54. package/dist/app/questions.js +215 -0
  55. package/dist/app/reader-filter.js +58 -0
  56. package/dist/app/relations.js +164 -0
  57. package/dist/app/relay.js +98 -0
  58. package/dist/app/repos.js +176 -0
  59. package/dist/app/restart.js +92 -0
  60. package/dist/app/set-aside.js +64 -0
  61. package/dist/app/system-locale.js +6 -0
  62. package/dist/app/tailscale-cli.js +77 -0
  63. package/dist/app/tailscale-testing.js +41 -0
  64. package/dist/app/tailscale.js +177 -0
  65. package/dist/app/tips.js +30 -0
  66. package/dist/app/topics-everywhere.js +53 -0
  67. package/dist/app/topics.js +453 -0
  68. package/dist/app/undo.js +52 -0
  69. package/dist/app/validate.js +131 -0
  70. package/dist/app/watch.js +48 -0
  71. package/dist/cli/command.js +44 -0
  72. package/dist/cli/commands.js +3303 -0
  73. package/dist/cli/exit-codes.js +70 -0
  74. package/dist/cli/forge.js +176 -0
  75. package/dist/cli/format.js +340 -0
  76. package/dist/cli/gh.js +17 -0
  77. package/dist/cli/gitrepo.js +489 -0
  78. package/dist/cli/help.js +101 -0
  79. package/dist/cli/hooks.js +232 -0
  80. package/dist/cli/main.js +37 -0
  81. package/dist/cli/merged-outside.js +58 -0
  82. package/dist/cli/names.js +154 -0
  83. package/dist/cli/opener.js +21 -0
  84. package/dist/cli/owner.js +154 -0
  85. package/dist/cli/phone.js +221 -0
  86. package/dist/cli/ports.js +24 -0
  87. package/dist/cli/probe.js +18 -0
  88. package/dist/cli/run.js +246 -0
  89. package/dist/cli/serve-file.js +21 -0
  90. package/dist/cli/stats.js +55 -0
  91. package/dist/cli/version.js +3 -0
  92. package/dist/core/agent-guide.js +31 -0
  93. package/dist/core/agent-prompts.js +139 -0
  94. package/dist/core/authority.js +94 -0
  95. package/dist/core/board/analysis.js +86 -0
  96. package/dist/core/board/choices.js +100 -0
  97. package/dist/core/board/compile.js +362 -0
  98. package/dist/core/board/engine.js +523 -0
  99. package/dist/core/board/hints.js +46 -0
  100. package/dist/core/board/history.js +146 -0
  101. package/dist/core/board/ids.js +87 -0
  102. package/dist/core/board/joins.js +30 -0
  103. package/dist/core/board/mentions.js +68 -0
  104. package/dist/core/board/merged.js +18 -0
  105. package/dist/core/board/model.js +135 -0
  106. package/dist/core/board/next.js +1116 -0
  107. package/dist/core/board/notes.js +298 -0
  108. package/dist/core/board/performance.js +218 -0
  109. package/dist/core/board/plan.js +299 -0
  110. package/dist/core/board/problems.js +232 -0
  111. package/dist/core/board/proofs.js +84 -0
  112. package/dist/core/board/questions.js +114 -0
  113. package/dist/core/board/reading.js +220 -0
  114. package/dist/core/board/readings.js +534 -0
  115. package/dist/core/board/schema.js +335 -0
  116. package/dist/core/board/shape-words.js +179 -0
  117. package/dist/core/board/template-words.js +23 -0
  118. package/dist/core/board/templates-catalogue.js +965 -0
  119. package/dist/core/board/templates-coverage.js +261 -0
  120. package/dist/core/board/templates-flows.js +779 -0
  121. package/dist/core/board/templates.js +586 -0
  122. package/dist/core/brief.js +93 -0
  123. package/dist/core/diagram.js +80 -0
  124. package/dist/core/errors.js +12 -0
  125. package/dist/core/evidence.js +33 -0
  126. package/dist/core/fields.js +129 -0
  127. package/dist/core/hierarchy.js +30 -0
  128. package/dist/core/icons.js +181 -0
  129. package/dist/core/image-crop.js +166 -0
  130. package/dist/core/item.js +49 -0
  131. package/dist/core/lease.js +31 -0
  132. package/dist/core/modules.js +318 -0
  133. package/dist/core/notify/planner.js +117 -0
  134. package/dist/core/notify/signals.js +66 -0
  135. package/dist/core/notify/text.js +60 -0
  136. package/dist/core/path-key.js +22 -0
  137. package/dist/core/placement.js +161 -0
  138. package/dist/core/preset-labels.js +66 -0
  139. package/dist/core/preset-notes.js +109 -0
  140. package/dist/core/preset.js +541 -0
  141. package/dist/core/profile.js +55 -0
  142. package/dist/core/project-id.js +20 -0
  143. package/dist/core/refusal.js +1 -0
  144. package/dist/core/relations.js +208 -0
  145. package/dist/core/repo.js +54 -0
  146. package/dist/core/samples.js +161 -0
  147. package/dist/core/search-words.js +68 -0
  148. package/dist/core/test-report.js +120 -0
  149. package/dist/core/time.js +8 -0
  150. package/dist/core/validation.js +60 -0
  151. package/dist/core/views.js +171 -0
  152. package/dist/core/workflow.js +51 -0
  153. package/dist/mcp/commands.js +101 -0
  154. package/dist/mcp/server.js +239 -0
  155. package/dist/mcp/words.js +95 -0
  156. package/dist/server/boards.js +232 -0
  157. package/dist/server/changes.js +42 -0
  158. package/dist/server/diff-tip.js +83 -0
  159. package/dist/server/drift.js +87 -0
  160. package/dist/server/errors.js +87 -0
  161. package/dist/server/evidence.js +82 -0
  162. package/dist/server/hosts.js +6 -0
  163. package/dist/server/hub.js +98 -0
  164. package/dist/server/lan-access.js +62 -0
  165. package/dist/server/lan.js +164 -0
  166. package/dist/server/listen.js +70 -0
  167. package/dist/server/notifier.js +156 -0
  168. package/dist/server/notify-api.js +151 -0
  169. package/dist/server/pairing.js +124 -0
  170. package/dist/server/projects.js +191 -0
  171. package/dist/server/push.js +199 -0
  172. package/dist/server/server.js +960 -0
  173. package/dist/server/session.js +43 -0
  174. package/dist/server/stream.js +36 -0
  175. package/dist/server/test-push.js +38 -0
  176. package/dist/server/token.js +37 -0
  177. package/dist/server/transports.js +54 -0
  178. package/dist/server/ui.js +44 -0
  179. package/dist/server/writes.js +361 -0
  180. package/dist/server/wrong-address.js +36 -0
  181. package/dist/store/boards.js +111 -0
  182. package/dist/store/database.js +45 -0
  183. package/dist/store/machine.js +77 -0
  184. package/dist/store/migrations.js +493 -0
  185. package/dist/store/queries.js +585 -0
  186. package/dist/store/registry.js +72 -0
  187. package/package.json +73 -4
  188. package/presets/architecture/playbook.md +69 -0
  189. package/presets/architecture/preset.yaml +80 -0
  190. package/presets/architecture/samples.yaml +23 -0
  191. package/presets/bug-triage/playbook.md +129 -0
  192. package/presets/bug-triage/preset.yaml +127 -0
  193. package/presets/bug-triage/samples/wall-slide-after.png +0 -0
  194. package/presets/bug-triage/samples/wall-slide-before.png +0 -0
  195. package/presets/bug-triage/samples.yaml +72 -0
  196. package/presets/change/playbook.md +115 -0
  197. package/presets/change/preset.yaml +141 -0
  198. package/presets/change/samples.yaml +62 -0
  199. package/presets/review/playbook.md +51 -0
  200. package/presets/review/preset.yaml +62 -0
  201. package/presets/review/samples.yaml +27 -0
  202. package/presets/tasks/playbook.md +78 -0
  203. package/presets/tasks/preset.yaml +61 -0
  204. package/presets/tasks/samples.yaml +46 -0
  205. package/schemas/board.schema.json +764 -0
  206. package/ui/dist/THIRD_PARTY_NOTICES.md +114 -0
  207. package/ui/dist/assets/dm-mono-latin-400-normal--0xN8mdc.woff +0 -0
  208. package/ui/dist/assets/dm-mono-latin-400-normal-4GdczIuU.woff2 +0 -0
  209. package/ui/dist/assets/dm-mono-latin-500-normal-CN8Miw6E.woff +0 -0
  210. package/ui/dist/assets/dm-mono-latin-500-normal-DRMDZjhP.woff2 +0 -0
  211. package/ui/dist/assets/dm-mono-latin-ext-400-normal-1aZr6b2b.woff +0 -0
  212. package/ui/dist/assets/dm-mono-latin-ext-400-normal-C2zvOubV.woff2 +0 -0
  213. package/ui/dist/assets/dm-mono-latin-ext-500-normal-BtRyHRi6.woff2 +0 -0
  214. package/ui/dist/assets/dm-mono-latin-ext-500-normal-Dw3M13d8.woff +0 -0
  215. package/ui/dist/assets/index-C3OzJope.js +103 -0
  216. package/ui/dist/assets/index-COdEjckQ.css +1 -0
  217. package/ui/dist/assets/newsreader-latin-ext-opsz-italic-CSPGnFdO.woff2 +0 -0
  218. package/ui/dist/assets/newsreader-latin-ext-opsz-normal-BQn1nviT.woff2 +0 -0
  219. package/ui/dist/assets/newsreader-latin-opsz-italic-kJKFiXvB.woff2 +0 -0
  220. package/ui/dist/assets/newsreader-latin-opsz-normal-s-izfB6B.woff2 +0 -0
  221. package/ui/dist/assets/newsreader-vietnamese-opsz-italic-DTr-ymY4.woff2 +0 -0
  222. package/ui/dist/assets/newsreader-vietnamese-opsz-normal-BjhtXyW2.woff2 +0 -0
  223. package/ui/dist/assets/pdf-YwugTw7Y.js +54 -0
  224. package/ui/dist/assets/pdf-engine-CkBopwck.js +1 -0
  225. package/ui/dist/assets/pdf-rELvHkft.js +56 -0
  226. package/ui/dist/assets/pdf.worker.min-B5Yc7dP4.mjs +27 -0
  227. package/ui/dist/assets/pdf.worker.min-B7U8ptvh.js +1 -0
  228. package/ui/dist/assets/pdf.worker.min-CIqJB0yW.mjs +28 -0
  229. package/ui/dist/assets/pdf.worker.min-UqOn5EDC.js +1 -0
  230. package/ui/dist/assets/schibsted-grotesk-latin-ext-wght-normal-hsMS0n0O.woff2 +0 -0
  231. package/ui/dist/assets/schibsted-grotesk-latin-wght-normal-Bb8VGrTG.woff2 +0 -0
  232. package/ui/dist/icons/apple-touch-icon.png +0 -0
  233. package/ui/dist/icons/otea-192.png +0 -0
  234. package/ui/dist/icons/otea-512.png +0 -0
  235. package/ui/dist/icons/otea-badge.png +0 -0
  236. package/ui/dist/icons/otea-maskable-512.png +0 -0
  237. package/ui/dist/index.html +25 -0
  238. package/ui/dist/manifest.webmanifest +24 -0
  239. package/ui/dist/otea-idle.svg +5 -0
  240. package/ui/dist/otea-working.svg +5 -0
  241. package/ui/dist/otea-yours-working.svg +5 -0
  242. package/ui/dist/otea-yours.svg +5 -0
  243. package/ui/dist/sw.js +1 -0
@@ -0,0 +1,610 @@
1
+ import { backWaysOf, gateAt, isClosed, landStepOf, positionOf, reopenStep, waysOf, } from '../core/board/engine.js';
2
+ import { DROPPED, guardedBranch, stepById, TITLE, } from '../core/board/model.js';
3
+ import { baseGateText, baseRefusal, branchForPersonText, commitsForPersonText, DONE_NAME, forPersonText, gateText, placeText, reviewForPersonText, rewindRefusal, rewriteForPersonText, unnamedBranchRefusal, } from '../core/board/next.js';
4
+ import { partByName, stateName } from '../core/board/reading.js';
5
+ import { OteaError } from '../core/errors.js';
6
+ import { listCollections, selectEvents, selectItems } from '../store/queries.js';
7
+ import { presetOf } from './collections.js';
8
+ import { listItems, workflowOf } from './items.js';
9
+ import { mergedOf } from './merged.js';
10
+ import { itemOnBoard, liveBoards } from './next.js';
11
+ import { approvedTipOf, handedOff } from './tips.js';
12
+ function brought(brings) {
13
+ const asked = brings();
14
+ return Array.isArray(asked) ? { branches: asked } : asked;
15
+ }
16
+ // Git is asked once per check, however many boards read what the action brings in.
17
+ function once(brings) {
18
+ let asked;
19
+ return () => {
20
+ asked ??= brings();
21
+ return asked;
22
+ };
23
+ }
24
+ // How an approved item gets its changes reviewed again: sent back from its land step to the step
25
+ // whose approval led there, or, once Done, reopened. The person does both; the agent asks.
26
+ function reviewAgainText(def, id, position) {
27
+ if (isClosed(position)) {
28
+ const step = stepById(def, reopenStep(def) ?? '')?.name;
29
+ return `ask the person (otea ask ${id}) to reopen ${id}${step ? ` to ${step}` : ''} so the change is reviewed again`;
30
+ }
31
+ const land = landStepOf(def);
32
+ // A land step with a way back lets the agent take the item back itself (P1-R2-3).
33
+ const back = land && stepById(def, backWaysOf(def, land.id).at(-1) ?? '');
34
+ if (back) {
35
+ return `take ${id} back to ${back.name} (otea handoff ${id} --way "${back.name}" --reason "<why>") so the change is reviewed again`;
36
+ }
37
+ const from = def.steps.find((step) => land !== undefined && step.id !== land.id && waysOf(def, step.id).includes(land.id));
38
+ return `ask the person (otea ask ${id}) to send ${id} back${from ? ` to ${from.name}` : ''} so the change is reviewed again`;
39
+ }
40
+ const short = (commit) => commit.slice(0, 7);
41
+ const GATED = ['push', 'merge'];
42
+ // The keys a check names, as one board stores them: `branch` is its protected branch, `repo` the
43
+ // field its guard reads the repository from (a board without one leaves the repo out: the branch
44
+ // alone names the item), any other key a part by its name. Undefined when the board cannot hold
45
+ // such an item.
46
+ function boardKeys(def, fields) {
47
+ const branch = guardedBranch(def);
48
+ if (!branch)
49
+ return undefined;
50
+ const out = {};
51
+ for (const [key, value] of Object.entries(fields)) {
52
+ if (key === 'branch')
53
+ out[branch.id] = value;
54
+ else if (key === 'repo') {
55
+ if (branch.guard.repo !== undefined)
56
+ out[branch.guard.repo] = value;
57
+ }
58
+ else if (key === TITLE)
59
+ out[TITLE] = value;
60
+ else {
61
+ const part = partByName(def, key);
62
+ if (!part)
63
+ return undefined;
64
+ out[part.id] = value;
65
+ }
66
+ }
67
+ return out;
68
+ }
69
+ // Repo names match whatever their case: git hosts and the default file systems of Windows and macOS
70
+ // take `API` and `api` as one repo, so a check must not let one of them pass where the other stops.
71
+ export function sameRepo(stored, named) {
72
+ return typeof stored === 'string' && stored.toLowerCase() === named.toLowerCase();
73
+ }
74
+ // Whether the item holds every key; `repo`, the key its repo name is in, matches by sameRepo.
75
+ function holds(item, keys, repo) {
76
+ return Object.entries(keys).every(([key, value]) => {
77
+ const stored = key === TITLE ? item.title : item.fields[key];
78
+ return key === repo ? sameRepo(stored, value) : stored === value;
79
+ });
80
+ }
81
+ function boardVerdicts(ctx, board, gate, fields, brings) {
82
+ const keys = boardKeys(board.def, fields);
83
+ if (!keys)
84
+ return [];
85
+ const guard = guardedBranch(board.def);
86
+ const repo = guard?.guard.repo;
87
+ return selectItems(ctx.db, { collection: board.collection })
88
+ .filter((item) => holds(item, keys, repo))
89
+ .map((item) => {
90
+ const position = positionOf(item.state);
91
+ const round = itemOnBoard(ctx, item, board.def).round;
92
+ const allowedIn = workflowOf(ctx, item).gates?.[gate] ?? [];
93
+ const merged = mergedOf(ctx, item.id) !== undefined;
94
+ const verdict = {
95
+ id: item.id,
96
+ state: item.state,
97
+ stateName: stateName(board.def, item.state),
98
+ allowed: gateAt(board.def, position, gate).allowed,
99
+ allowedIn,
100
+ allowedInNames: allowedIn.map((state) => stateName(board.def, state)),
101
+ text: gateText(board.def, item.id, position, gate, round, merged),
102
+ };
103
+ const unreviewed = !verdict.allowed || !guard
104
+ ? undefined
105
+ : gate === 'push'
106
+ ? landingPushRefusal(ctx, board.def, item, position, guard, brings)
107
+ : mergeRefusal(ctx, board.def, item, position, guard, brings, merged);
108
+ const rewritten = verdict.allowed && !unreviewed && guard && gate === 'push'
109
+ ? rewriteRefusal(ctx, board.def, item, position, guard, brings)
110
+ : undefined;
111
+ const refused = unreviewed ?? rewritten;
112
+ if (refused)
113
+ Object.assign(verdict, { allowed: false, text: refused });
114
+ // A push refused because its step is reviewed: the person's line says why (P5-R3-13).
115
+ const inReview = gate === 'push' && !verdict.allowed && !isClosed(position) && position.phase === 'review';
116
+ const step = inReview ? stepById(board.def, position.step)?.name : undefined;
117
+ return {
118
+ verdict,
119
+ open: !isClosed(position),
120
+ dropped: isDropped(position),
121
+ ...(rewritten ? { rewrite: board.def } : {}),
122
+ ...(step ? { person: reviewForPersonText(board.def, item.id, step) } : {}),
123
+ };
124
+ });
125
+ }
126
+ // A push of an item's own branch while it is landed, after the person approved it: only what was
127
+ // approved, as it is or rebased onto the base with the same result (P3C-R2-1). Undefined when the
128
+ // push may go: the item is not being landed, its handoff recorded no tip, or the push holds it.
129
+ function landingPushRefusal(ctx, def, item, position, guard, brings) {
130
+ if (gateAt(def, position, 'merge').why !== 'landing')
131
+ return undefined;
132
+ const branch = item.fields[guard.id];
133
+ if (typeof branch !== 'string')
134
+ return undefined;
135
+ const tip = approvedTipOf(ctx, item.id, branch);
136
+ const lands = tip && brought(brings).landsAs;
137
+ if (!tip || !lands || lands([{ branch, tip }], guard.guard.base))
138
+ return undefined;
139
+ const base = guard.guard.base;
140
+ const rebased = base
141
+ ? `, as they are or rebased onto ${base} with the same result`
142
+ : ' as they are';
143
+ return `push refused: ${item.id} is being landed in ${placeText(def, position)}: the person approved ${branch} at ${short(tip.commit)}, and this push writes changes nobody reviewed. Push only the approved commits${rebased}; for anything else, ${reviewAgainText(def, item.id, position)}.`;
144
+ }
145
+ // A push that rewrites an item's branch on the remote (a force push) once the item was handed off
146
+ // (P1-R3-3): the remote branch holds what the review read, and another agent may have added to it
147
+ // meanwhile; a rewrite would drop both. Before the first handoff a rewrite is the agent's own
148
+ // business, and while the item is landed the push is held to what was approved instead
149
+ // (landingPushRefusal), where a rebase with the same result passes. Undefined when the push may go.
150
+ function rewriteRefusal(ctx, def, item, position, guard, brings) {
151
+ if (gateAt(def, position, 'merge').why === 'landing')
152
+ return undefined;
153
+ const branch = item.fields[guard.id];
154
+ if (typeof branch !== 'string' || branch === guard.guard.base)
155
+ return undefined;
156
+ if (!handedOff(ctx, item.id) || brought(brings).rewrites?.() !== true)
157
+ return undefined;
158
+ const tip = approvedTipOf(ctx, item.id, branch);
159
+ const at = tip ? ` at ${short(tip.commit)}` : '';
160
+ const base = guard.guard.base;
161
+ const merge = base
162
+ ? `to bring in ${base}, merge it (git merge origin/${base})`
163
+ : 'to bring in the base, merge it';
164
+ return `push refused: ${item.id} was handed off for review${at}, and this push rewrites ${branch} on the remote instead of adding to it: what the review read, and any commit another agent added, would be gone from it. Add commits on top; ${merge} rather than rebase.`;
165
+ }
166
+ // A merge of an item's own branch once the person approved it, while it is landed (or, on a board
167
+ // with no land step, once it is Done and not merged yet): only what was approved, as the remote has
168
+ // it now (P3C-R3-1). A forge merges the branch as the remote has it, whatever pushed there since,
169
+ // so the gate asks the remote, and refuses when it cannot. Undefined when the merge may go: the
170
+ // item is not being merged, its handoff recorded no tip, or the branch holds the approved one.
171
+ function mergeRefusal(ctx, def, item, position, guard, brings, merged) {
172
+ const why = gateAt(def, position, 'merge').why;
173
+ if (why !== 'landing' && (why !== 'done' || merged || landStepOf(def)))
174
+ return undefined;
175
+ const branch = item.fields[guard.id];
176
+ if (typeof branch !== 'string' || branch === guard.guard.base)
177
+ return undefined;
178
+ const tip = approvedTipOf(ctx, item.id, branch);
179
+ const takes = tip && !tip.unchanged ? brought(brings).takes : undefined;
180
+ if (!tip || !takes)
181
+ return undefined;
182
+ const take = takes(tip, guard.guard.base);
183
+ if ('unknown' in take)
184
+ return `merge refused: could not check ${branch} against the commit the person approved of ${item.id}, ${short(tip.commit)}: ${take.unknown}. Merge nothing of it until this check answers; if it keeps failing, ask the person: otea ask ${item.id} "<question>".`;
185
+ if (take.held)
186
+ return undefined;
187
+ const { added } = take;
188
+ const count = added.length === 1 ? '1 commit' : `${added.length} commits`;
189
+ const shown = added
190
+ .slice(0, 5)
191
+ .map(({ commit, author }) => `${commit} by ${author}`)
192
+ .join(', ') + (added.length > 5 ? ', …' : '');
193
+ const what = added.length > 0
194
+ ? `, with ${count} nobody reviewed: ${shown}`
195
+ : ', which is not what they approved';
196
+ return `merge refused: the person approved ${branch} at ${short(tip.commit)} for ${item.id}, but ${take.ref} is at ${take.commit}${what}. Merge nothing of it by any means, a forge's included (a script, a CLI or the PR's button): stop and ask the person, otea ask ${item.id} "<question>".`;
197
+ }
198
+ // Whether an item stands at or past the first step that works on the protected branch: one that
199
+ // hands it or pushes it.
200
+ function reachedBranch(def, part, state) {
201
+ const position = positionOf(state);
202
+ if (isClosed(position))
203
+ return true;
204
+ const first = def.steps.findIndex((step) => part.guard.push.includes(step.id) || step.hand.some(({ ref }) => ref === part.id));
205
+ const at = def.steps.findIndex((step) => step.id === position.step);
206
+ return first < 0 || at >= first;
207
+ }
208
+ // Whether an item ever stood at or past that step, now or in its history: only then may it hold
209
+ // work on the branch.
210
+ function workedOnBranch(ctx, def, part, item) {
211
+ if (reachedBranch(def, part, item.state))
212
+ return true;
213
+ return selectEvents(ctx.db, item.id).some(({ type, data }) => type === 'transitioned' && reachedBranch(def, part, String(data.to)));
214
+ }
215
+ function isDropped(position) {
216
+ return isClosed(position) && position.closed === DROPPED;
217
+ }
218
+ // A push or merge into the base branch a board protects: allowed only when it brings in the
219
+ // branch of at least one of the board's items (in the repo checked) and every such item is Hecho.
220
+ function baseCheck(ctx, board, gate, fields, brings) {
221
+ const branch = guardedBranch(board.def);
222
+ const base = fields.branch ?? '';
223
+ const { branches, unpushed = [] } = brought(brings);
224
+ const names = new Set(branches.filter((name) => name !== base));
225
+ const repo = branch?.guard.repo;
226
+ const matched = selectItems(ctx.db, { collection: board.collection })
227
+ .filter((item) => branch && names.has(item.fields[branch.id]))
228
+ .filter((item) => repo === undefined || fields.repo === undefined || sameRepo(item.fields[repo], fields.repo))
229
+ // A dropped item brings nothing in: a duplicate left on the same branch never blocks the item
230
+ // that was done there, and alone it allows nothing.
231
+ .filter((item) => !isDropped(positionOf(item.state)));
232
+ const held = matched.map((item) => (branch ? item.fields[branch.id] : ''));
233
+ const items = matched.map((item) => {
234
+ const position = positionOf(item.state);
235
+ const round = itemOnBoard(ctx, item, board.def).round;
236
+ const allowedIn = workflowOf(ctx, item).gates?.merge ?? [];
237
+ const ahead = unpushed.find(({ branch: name }) => branch && name === item.fields[branch.id]);
238
+ if (ahead) {
239
+ // On its land step the item's branch may take a rebase onto the base with the same result
240
+ // (landingPushRefusal): the refusal names that push first (P6-R3-1).
241
+ const rebase = gateAt(board.def, position, 'merge').why === 'landing' &&
242
+ gateAt(board.def, position, 'push').allowed
243
+ ? ` To land a branch you rebased onto ${base}, push it first, git push --force-with-lease ${ahead.push ?? 'origin'} ${ahead.branch}, then push ${base} again, git push ${ahead.push ?? 'origin'} ${base}.`
244
+ : '';
245
+ return {
246
+ id: item.id,
247
+ state: item.state,
248
+ stateName: stateName(board.def, item.state),
249
+ allowed: false,
250
+ allowedIn,
251
+ allowedInNames: allowedIn.map((state) => stateName(board.def, state)),
252
+ text: `${gate} refused: ${ahead.branch} holds commits ${ahead.remote} never got, so nobody reviewed them; ${base} takes ${item.id}'s branch only as it was pushed.${rebase}`,
253
+ };
254
+ }
255
+ return {
256
+ id: item.id,
257
+ state: item.state,
258
+ stateName: stateName(board.def, item.state),
259
+ allowed: gateAt(board.def, position, 'merge').allowed,
260
+ allowedIn,
261
+ allowedInNames: allowedIn.map((state) => stateName(board.def, state)),
262
+ text: baseGateText(board.def, item.id, position, gate, round, base),
263
+ };
264
+ });
265
+ // An open item whose branch is the base itself works straight on it (a main-only board): a push
266
+ // or merge of the base is its own, allowed by its own step as for any branch. One handed off as
267
+ // no code change brings nothing in, so a push never waits on it (P2S-R3-3).
268
+ const onBase = selectItems(ctx.db, { collection: board.collection })
269
+ .filter((item) => branch && base !== '' && item.fields[branch.id] === base)
270
+ .filter((item) => repo === undefined || fields.repo === undefined || sameRepo(item.fields[repo], fields.repo))
271
+ .filter((item) => !isClosed(positionOf(item.state)))
272
+ .filter((item) => !approvedTipOf(ctx, item.id, base)?.unchanged)
273
+ // On a board whose Rama starts at the base (P2S-R3-10), every new item names it before any work:
274
+ // one that never reached the step that hands or pushes the branch made no commit there, so a
275
+ // push of the base does not wait on it.
276
+ .filter((item) => !branch || branch.initial !== base || workedOnBranch(ctx, board.def, branch, item));
277
+ const own = onBase.map((item) => {
278
+ const position = positionOf(item.state);
279
+ const round = itemOnBoard(ctx, item, board.def).round;
280
+ const allowedIn = workflowOf(ctx, item).gates?.[gate] ?? [];
281
+ // Its land step lands it on the base, which on its own branch is a push of the base.
282
+ const landing = gateAt(board.def, position, 'merge').why === 'landing';
283
+ return {
284
+ id: item.id,
285
+ state: item.state,
286
+ stateName: stateName(board.def, item.state),
287
+ allowed: landing || gateAt(board.def, position, gate).allowed,
288
+ allowedIn,
289
+ allowedInNames: allowedIn.map((state) => stateName(board.def, state)),
290
+ text: landing
291
+ ? baseGateText(board.def, item.id, position, gate, round, base)
292
+ : gateText(board.def, item.id, position, gate, round),
293
+ };
294
+ });
295
+ const all = [...items, ...own];
296
+ // What each item brought in lands: its branch at the tip the person approved, when its handoff
297
+ // recorded one; on its own branch, the base itself.
298
+ const landing = [];
299
+ const approved = [];
300
+ for (const item of [...matched, ...onBase]) {
301
+ const name = branch ? item.fields[branch.id] : '';
302
+ const tip = approvedTipOf(ctx, item.id, name);
303
+ landing.push(tip ? { branch: name, tip } : { branch: name });
304
+ if (tip)
305
+ approved.push({
306
+ id: item.id,
307
+ tip,
308
+ again: reviewAgainText(board.def, item.id, positionOf(item.state)),
309
+ });
310
+ }
311
+ return {
312
+ gate,
313
+ allowed: all.length > 0 && all.every(({ allowed }) => allowed),
314
+ items: all,
315
+ held: own.length > 0 ? [...held, base] : held,
316
+ landing,
317
+ approved,
318
+ };
319
+ }
320
+ // Why a push or merge into a base branch is refused when what it writes is not what the person
321
+ // approved of the items it brings in (P3C-R2-1): commits added after the approval, a rebase with
322
+ // another result, or a merge whose conflicts the review never saw.
323
+ function unapprovedRefusal(gate, base, approved) {
324
+ const which = approved
325
+ .map(({ id, tip }) => `${id} (${short(tip.commit)} on ${tip.branch})`)
326
+ .join(', ');
327
+ const again = approved.map(({ again }) => again).join('; ');
328
+ return `${gate} refused: ${base} would not hold exactly what the person approved of ${which}: it brings in changes nobody reviewed, or a merge whose conflicts the review never saw. Bring in the approved commits as they are, or rebased onto ${base} with the same result; for anything else, ${again}.`;
329
+ }
330
+ // The commits of a refusal as a reader knows them: each short id with its subject, five at most.
331
+ function commitsShown(commits) {
332
+ const shown = commits
333
+ .slice(0, 5)
334
+ .map(({ commit, subject }) => (subject ? `${short(commit)} (${subject})` : short(commit)));
335
+ return shown.join(', ') + (commits.length > 5 ? ', …' : '');
336
+ }
337
+ // Why a push or merge into a base branch is refused when it brings in commits that no branch of an
338
+ // approved item holds and no approved or Done item records as its own (P5-R3-3): nobody approved
339
+ // them, whatever the steps of the items it brings in say. What the agent does about it: record a
340
+ // commit on the approved item that made it, or push nothing of it.
341
+ function strayRefusal(gate, base, defs, commits) {
342
+ const count = commits.length === 1 ? '1 commit' : `${commits.length} commits`;
343
+ const names = defs.map((def) => def.name).join(' and ');
344
+ const verb = defs.length > 1 ? 'protect' : 'protects';
345
+ const example = short(commits[0]?.commit ?? '<commit>');
346
+ return `${gate} refused: ${base} would take ${count} that no approved item holds on its branch or records as its own: ${commitsShown(commits)}. ${names} ${verb} ${base}: it takes only the branches of approved items, as they were pushed, and the commits an approved or Done item records by its id. If an approved item made it, record it on that item: while it is landed, in the field its step asks for (otea update <id> --field "<field>=${example}"); once it is Done, with otea merged <id> --commit ${example}. If no approved item made it, push nothing of it: ask the person, otea ask <id> "<question>".`;
347
+ }
348
+ // An id of a commit as an item records it in a field: 7 to 40 hex digits, a word of its own.
349
+ const COMMIT_ID = /\b[0-9a-f]{7,40}\b/gi;
350
+ function commitIds(value) {
351
+ return typeof value === 'string'
352
+ ? (value.match(COMMIT_ID) ?? []).map((id) => id.toLowerCase())
353
+ : [];
354
+ }
355
+ function recordsOf(ctx, boards, fields, base) {
356
+ return boards.flatMap((board) => {
357
+ const branch = guardedBranch(board.def);
358
+ if (!branch)
359
+ return [];
360
+ const repo = branch.guard.repo;
361
+ return selectItems(ctx.db, { collection: board.collection }).flatMap((item) => {
362
+ const position = positionOf(item.state);
363
+ if (isDropped(position) || !gateAt(board.def, position, 'merge').allowed)
364
+ return [];
365
+ if (repo !== undefined &&
366
+ fields.repo !== undefined &&
367
+ !sameRepo(item.fields[repo], fields.repo))
368
+ return [];
369
+ const ids = [
370
+ ...Object.values(item.fields).flatMap(commitIds),
371
+ ...commitIds(mergedOf(ctx, item.id)?.commit),
372
+ ];
373
+ const tip = approvedTipOf(ctx, item.id, base);
374
+ const held = tip && !tip.unchanged ? { tip: tip.commit } : {};
375
+ return ids.length > 0 || held.tip ? [{ item, def: board.def, ids, ...held }] : [];
376
+ });
377
+ });
378
+ }
379
+ // What the approved and Done items record of the commits a push of the base brings in, when it
380
+ // brings in no item's branch: each item with the commits of the push that are its own, and the
381
+ // commits none of them records. Undefined when git cannot list what the push brings in (the remote
382
+ // has no base yet), or the push brings in no commit at all.
383
+ function recordedTake(records, outside) {
384
+ const every = outside([]);
385
+ if (every.length === 0)
386
+ return undefined;
387
+ const taken = records.flatMap((record) => {
388
+ const underTip = record.tip
389
+ ? new Set(outside([], [record.tip]).map(({ commit }) => commit))
390
+ : undefined;
391
+ const commits = every.filter(({ commit }) => record.ids.some((id) => commit.toLowerCase().startsWith(id)) ||
392
+ (underTip !== undefined && !underTip.has(commit)));
393
+ return commits.length > 0 ? [{ record, commits }] : [];
394
+ });
395
+ const owned = new Set(taken.flatMap(({ commits }) => commits.map(({ commit }) => commit)));
396
+ return { taken, left: every.filter(({ commit }) => !owned.has(commit)) };
397
+ }
398
+ // What otea check answers for an item whose recorded commits a push of the base takes.
399
+ function recordedVerdict(ctx, gate, base, { record, commits }) {
400
+ const { item, def } = record;
401
+ const position = positionOf(item.state);
402
+ const allowedIn = workflowOf(ctx, item).gates?.merge ?? [];
403
+ const where = isClosed(position)
404
+ ? `is ${DONE_NAME}`
405
+ : `is being landed in ${placeText(def, position)}, after the person's approval,`;
406
+ const ids = commits.map(({ commit }) => short(commit));
407
+ const listed = ids.length > 5 ? `${ids.slice(0, 5).join(', ')} and ${ids.length - 5} more` : ids.join(', ');
408
+ return {
409
+ id: item.id,
410
+ state: item.state,
411
+ stateName: stateName(def, item.state),
412
+ allowed: true,
413
+ allowedIn,
414
+ allowedInNames: allowedIn.map((state) => stateName(def, state)),
415
+ text: `${gate} allowed: ${item.id} ${where} and records ${listed} as its own; ${base} takes ${ids.length === 1 ? 'it' : 'them'}.`,
416
+ };
417
+ }
418
+ // Checks the items whose fields hold every value given and whose workflow gates the action: on a
419
+ // board, its protected branch (and the repo its guard reads), matched by their hidden ids and
420
+ // answered by the step engine; on a collection still on a preset, its workflow's gates. The open
421
+ // ones are checked when there are any; otherwise the closed ones, since a closed state can allow an
422
+ // action too (merging what was approved). A push or merge into a branch a board protects as its
423
+ // base is checked against the items whose branches it brings in (`brings`; none when not given).
424
+ export function checkGate(ctx, gate, fields, asked = () => []) {
425
+ const brings = once(asked);
426
+ const boards = liveBoards(ctx);
427
+ const onBoards = new Set(boards.map(({ collection }) => collection));
428
+ assertKnownGate(ctx, gate, onBoards);
429
+ assertKnownKeys(ctx, boards, onBoards, fields);
430
+ const bases = GATED.includes(gate)
431
+ ? boards.filter(({ def }) => fields.branch !== undefined && guardedBranch(def)?.guard.base === fields.branch)
432
+ : [];
433
+ if (bases.length > 0) {
434
+ const check = baseVerdict(ctx, boards, bases, gate, fields, brings);
435
+ if (check.allowed || gate !== 'push')
436
+ return check;
437
+ const defs = bases.map(({ def }) => def);
438
+ const person = check.stray
439
+ ? commitsForPersonText(defs, fields.branch ?? '', check.stray)
440
+ : forPersonText(defs);
441
+ return { ...check, person };
442
+ }
443
+ const fromBoards = GATED.includes(gate)
444
+ ? boards.flatMap((board) => boardVerdicts(ctx, board, gate, fields, brings))
445
+ : [];
446
+ const fromPresets = presetVerdicts(ctx, gate, fields, onBoards);
447
+ const gated = [...fromBoards, ...fromPresets];
448
+ const open = gated.filter((entry) => entry.open);
449
+ // Of the closed ones, a dropped duplicate left on the branch never blocks the item that was done
450
+ // there; dropped ones alone still answer (and allow nothing).
451
+ const kept = gated.filter((entry) => !entry.dropped);
452
+ const closed = kept.length > 0 ? kept : gated;
453
+ const answered = open.length > 0 ? open : closed;
454
+ const items = answered.map(({ verdict }) => verdict);
455
+ // Where a board protects a base, a push takes only a branch an item names (P5-R3-2): one no item
456
+ // names is no item's work, and Otea never lets through what no board lets through.
457
+ const guarding = boards.filter(({ def }) => guardedBranch(def)?.guard.base !== undefined);
458
+ if (items.length === 0 && gate === 'push' && fields.branch !== undefined && guarding.length > 0) {
459
+ const defs = guarding.map(({ def }) => def);
460
+ return {
461
+ gate,
462
+ allowed: false,
463
+ items,
464
+ refusal: unnamedBranchRefusal(defs, fields.branch),
465
+ person: branchForPersonText(defs),
466
+ };
467
+ }
468
+ const check = { gate, allowed: items.every(({ allowed }) => allowed), items };
469
+ if (items.length === 0)
470
+ check.note = `no item with a ${gate} gate matches`;
471
+ // A person who means to rewrite the branch pushes it themselves, past the hook (P1-R3-3).
472
+ const rewritten = answered.find(({ rewrite }) => rewrite !== undefined)?.rewrite;
473
+ if (rewritten)
474
+ check.person = rewriteForPersonText(rewritten);
475
+ // A push refused while its item is reviewed says why to the person too (P5-R3-13).
476
+ const reviewed = answered.find(({ person }) => person !== undefined)?.person;
477
+ if (!check.allowed && !check.person && reviewed)
478
+ check.person = reviewed;
479
+ return check;
480
+ }
481
+ // The base branches the project's live boards protect (guard.base), each once, for the forge to
482
+ // enforce (otea hook install --forge).
483
+ export function protectedBases(ctx) {
484
+ const bases = liveBoards(ctx).flatMap(({ def }) => guardedBranch(def)?.guard.base ?? []);
485
+ return [...new Set(bases)].sort();
486
+ }
487
+ // A gate no board and no preset declares is a typo (`psuh`) or an action Otea does not gate
488
+ // (`deploy`): the check refuses it rather than matching nothing and allowing the action.
489
+ function assertKnownGate(ctx, gate, onBoards) {
490
+ const declared = listCollections(ctx.db)
491
+ .filter(({ name }) => !onBoards.has(name))
492
+ .flatMap((collection) => presetOf(ctx, collection).types.flatMap(({ workflow }) => Object.keys(workflow.gates ?? {})));
493
+ const gates = [...new Set([...GATED, ...declared])].sort();
494
+ if (gates.includes(gate))
495
+ return;
496
+ throw new OteaError('invalid_gate', `Unknown gate "${gate}"; the gates are ${gates.join(', ')}`);
497
+ }
498
+ // A key no board part and no preset field names is a typo: the check refuses it rather than
499
+ // matching nothing and allowing the action.
500
+ function assertKnownKeys(ctx, boards, onBoards, fields) {
501
+ const presets = listCollections(ctx.db)
502
+ .filter(({ name }) => !onBoards.has(name))
503
+ .map((collection) => presetOf(ctx, collection));
504
+ for (const key of Object.keys(fields)) {
505
+ if (key === 'branch' || key === 'repo' || key === TITLE)
506
+ continue;
507
+ const named = boards.some(({ def }) => partByName(def, key) !== undefined) ||
508
+ presets.some((preset) => key in preset.fields);
509
+ if (!named) {
510
+ throw new OteaError('invalid_fields', `No board has a field named "${key}" to check`);
511
+ }
512
+ }
513
+ }
514
+ function presetVerdicts(ctx, gate, fields, onBoards) {
515
+ // An error here fails the check closed: an item Otea cannot read is never allowed by silence.
516
+ const { repo, ...exact } = fields;
517
+ const items = listItems(ctx, { fields: exact }).filter((item) => !onBoards.has(item.collection) && (repo === undefined || sameRepo(item.fields.repo, repo)));
518
+ return items.flatMap((item) => {
519
+ const allowedIn = workflowOf(ctx, item).gates?.[gate];
520
+ if (!allowedIn)
521
+ return [];
522
+ // A preset's states are its words already.
523
+ const verdict = {
524
+ id: item.id,
525
+ state: item.state,
526
+ stateName: item.state,
527
+ allowed: allowedIn.includes(item.state),
528
+ allowedIn,
529
+ allowedInNames: allowedIn,
530
+ };
531
+ return [{ verdict, open: item.turn !== 'none' }];
532
+ });
533
+ }
534
+ // The repository a board item's protected branch is in (its guard's repo field), or the `repo`
535
+ // field of an item still on a preset.
536
+ export function repoOfItem(ctx, item, boards = liveBoards(ctx)) {
537
+ const board = boards.find(({ collection }) => collection === item.collection);
538
+ if (!board)
539
+ return item.fields.repo;
540
+ const repo = guardedBranch(board.def)?.guard.repo;
541
+ return repo === undefined ? undefined : item.fields[repo];
542
+ }
543
+ // A push or merge into a base branch boards protect (checkGate): every board that protects it is
544
+ // asked at once.
545
+ function baseVerdict(ctx, boards, bases, gate, fields, brings) {
546
+ // Every board that protects the base is asked at once: the action must bring in an item of
547
+ // one of them, and every item it brings in, whatever its board, must allow it. A board that
548
+ // leaves the base alone still lands its own items into it: an item of it that the action
549
+ // brings in counts like theirs, by its own board's steps, so their protection never blocks the
550
+ // land step of another board (Errores pushing its approved fix to main).
551
+ const guarding = boards.filter(({ def }) => guardedBranch(def) !== undefined);
552
+ const checks = guarding.map((board) => baseCheck(ctx, board, gate, fields, brings));
553
+ const items = checks.flatMap((check) => check.items);
554
+ const base = fields.branch ?? '';
555
+ const defs = bases.map(({ def }) => def);
556
+ const outside = brought(brings).outside;
557
+ if (items.length === 0) {
558
+ // It brings in no item's branch: it may still bring in only commits that approved or Done
559
+ // items record as their own (P5-R3-3), a board that commits approved work straight on the base.
560
+ const take = outside
561
+ ? recordedTake(recordsOf(ctx, guarding, fields, base), outside)
562
+ : undefined;
563
+ if (take && take.left.length === 0) {
564
+ const taken = take.taken.map((one) => recordedVerdict(ctx, gate, base, one));
565
+ return { gate, allowed: true, items: taken };
566
+ }
567
+ if (take)
568
+ return {
569
+ gate,
570
+ allowed: false,
571
+ items,
572
+ refusal: strayRefusal(gate, base, defs, take.left),
573
+ stray: take.left,
574
+ };
575
+ // A force push of an older commit brings in nothing and takes commits away (P8-R3-4).
576
+ const rewinds = gate === 'push' && brought(brings).rewrites?.() === true;
577
+ return {
578
+ gate,
579
+ allowed: false,
580
+ items,
581
+ refusal: rewinds ? rewindRefusal(defs, base) : baseRefusal(defs, gate, base),
582
+ };
583
+ }
584
+ const allowed = items.every((item) => item.allowed);
585
+ // Every item brought in may land, but the action must not bring in more than their branches:
586
+ // a commit made on the base, or on a branch no item has, rides along unreviewed.
587
+ const stray = allowed ? (outside?.(checks.flatMap(({ held }) => held)) ?? []) : [];
588
+ if (stray.length > 0) {
589
+ return {
590
+ gate,
591
+ allowed: false,
592
+ items,
593
+ refusal: strayRefusal(gate, base, defs, stray),
594
+ stray,
595
+ };
596
+ }
597
+ // Every branch it brings in is one the person approved: what it writes must be exactly that,
598
+ // merged onto the base as the remote has it. Checked once a handoff recorded an approved tip.
599
+ const approved = checks.flatMap((check) => check.approved);
600
+ const lands = allowed && approved.length > 0 ? brought(brings).landsAs : undefined;
601
+ if (lands && !lands(checks.flatMap((check) => check.landing))) {
602
+ return {
603
+ gate,
604
+ allowed: false,
605
+ items,
606
+ refusal: unapprovedRefusal(gate, fields.branch ?? '', approved),
607
+ };
608
+ }
609
+ return { gate, allowed, items };
610
+ }
@@ -0,0 +1,37 @@
1
+ import { boardText } from '../core/board/next.js';
2
+ import { OteaError } from '../core/errors.js';
3
+ import { listCollections } from '../store/queries.js';
4
+ import { getCollection, idleRequests } from './collections.js';
5
+ import { itemNextText, liveBoardOf } from './next.js';
6
+ // What `otea show` says to do now with the item: next's text on its board.
7
+ export function hintFor(project, item, me) {
8
+ if (item.archived)
9
+ return `${item.id} is on ${item.archived.board}, an archived board: it is read-only. Pick another item with otea next.`;
10
+ return itemNextText(project, item, me) ?? '';
11
+ }
12
+ export function guideCommand(collection) {
13
+ return /^[\w.-]+$/.test(collection) ? `otea board ${collection}` : `otea board "${collection}"`;
14
+ }
15
+ export function boardGuide(project, name) {
16
+ const collection = getCollection(project.db, name).name;
17
+ const board = liveBoardOf(project, collection);
18
+ if (!board)
19
+ throw new OteaError('not_found', `Board "${name}" is not published yet`);
20
+ return {
21
+ kind: 'board',
22
+ collection: name,
23
+ board: board.id,
24
+ version: board.version,
25
+ text: boardText(board.def),
26
+ };
27
+ }
28
+ // The project's boards, each with how to read what its agents do: Pedidos once it holds an item.
29
+ export function guideIndex(project) {
30
+ const idle = idleRequests(project);
31
+ const shown = listCollections(project.db).filter(({ name }) => name !== idle);
32
+ return shown.map(({ name }) => ({
33
+ name,
34
+ board: liveBoardOf(project, name)?.id ?? null,
35
+ command: guideCommand(name),
36
+ }));
37
+ }