@otea/cli 0.0.1 → 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 +251 -3
  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 +72 -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,299 @@
1
+ import { backWaysOf, isClosed, positionOf, stateOf } from './engine.js';
2
+ import { DONE, DROPPED, defaultWay, guardedBranch, isEvidence, MOTIVE, partOf, SAME, STEP, stepById, stepIndex, usedRefs, } from './model.js';
3
+ const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
4
+ export function changePlan(live, draft, context = {}) {
5
+ if (!live)
6
+ return [{ kind: 'created', board: draft.name, steps: draft.steps.map((s) => s.name) }];
7
+ const out = [];
8
+ if (live.name !== draft.name)
9
+ out.push({ kind: 'board_renamed', from: live.name, to: draft.name });
10
+ if (live.item !== draft.item)
11
+ out.push({ kind: 'item_renamed', to: draft.item });
12
+ for (const step of draft.steps) {
13
+ const old = live.steps.find(({ id }) => id === step.id);
14
+ const { id, name } = step;
15
+ if (!old) {
16
+ out.push({ kind: 'step_added', step: id, name, doer: step.doer, reviewer: step.reviewer });
17
+ continue;
18
+ }
19
+ if (old.name !== name)
20
+ out.push({ kind: 'step_renamed', step: id, from: old.name, to: name });
21
+ if (old.doer !== step.doer)
22
+ out.push({ kind: 'step_doer', step: id, name, doer: step.doer });
23
+ if (old.reviewer !== step.reviewer)
24
+ out.push({ kind: 'step_reviewer', step: id, name, reviewer: step.reviewer });
25
+ for (const hand of step.hand) {
26
+ const part = partOf(draft, hand.ref);
27
+ if (!part)
28
+ continue;
29
+ const before = old.hand.find(({ ref }) => ref === hand.ref);
30
+ const base = { step: id, name, part: part.id, partName: part.name };
31
+ if (!before)
32
+ out.push({ kind: 'hand_added', ...base, req: hand.req, fresh: hand.fresh });
33
+ else if (before.req !== hand.req ||
34
+ before.fresh !== hand.fresh ||
35
+ !same(before.when, hand.when))
36
+ out.push({ kind: 'hand_changed', ...base, req: hand.req, fresh: hand.fresh });
37
+ }
38
+ for (const before of old.hand) {
39
+ if (step.hand.some(({ ref }) => ref === before.ref))
40
+ continue;
41
+ const partName = partOf(live, before.ref)?.name ?? '';
42
+ out.push({ kind: 'hand_removed', step: id, name, part: before.ref, partName });
43
+ }
44
+ if (!same(old.instructions, step.instructions))
45
+ out.push({ kind: 'step_instructions', step: id, name });
46
+ if (!same(forward(live, old.id), forward(draft, step.id)))
47
+ out.push({ kind: 'step_ways', step: id, name });
48
+ if (old.back !== step.back) {
49
+ const to = step.back === SAME ? name : (stepById(draft, step.back)?.name ?? name);
50
+ out.push({ kind: 'step_back', step: id, name, to });
51
+ }
52
+ }
53
+ for (const step of draft.steps) {
54
+ if (stepById(live, step.id))
55
+ out.push(...laterStepChanges(live, draft, step.id, context));
56
+ }
57
+ for (const old of live.steps) {
58
+ if (!draft.steps.some(({ id }) => id === old.id))
59
+ out.push({ kind: 'step_removed', step: old.id, name: old.name });
60
+ }
61
+ const kept = (from, other) => from.steps.filter(({ id }) => other.steps.some((s) => s.id === id)).map(({ id }) => id);
62
+ if (!same(kept(live, draft), kept(draft, live)))
63
+ out.push({ kind: 'steps_reordered' });
64
+ const used = usedRefs(draft);
65
+ const handed = new Set(draft.steps.flatMap(({ hand }) => hand.map(({ ref }) => ref)));
66
+ for (const part of Object.values(draft.parts)) {
67
+ if (!used.has(part.id))
68
+ continue;
69
+ const old = live.parts[part.id];
70
+ if (old && old.name !== part.name)
71
+ out.push({ kind: 'part_renamed', part: part.id, from: old.name, to: part.name });
72
+ if (!old && !handed.has(part.id))
73
+ out.push({ kind: 'part_added', part: part.id, name: part.name, evidence: isEvidence(part) });
74
+ }
75
+ if (!same(live.form, draft.form) || live.title !== draft.title) {
76
+ const names = [draft.title, ...draft.form.map(({ ref }) => partOf(draft, ref)?.name ?? '')];
77
+ out.push({ kind: 'form', names: names.filter(Boolean) });
78
+ }
79
+ if (!same(live.layout, draft.layout) || !same(live.row, draft.row))
80
+ out.push({ kind: 'layout' });
81
+ if (live.about !== draft.about || live.idle !== draft.idle)
82
+ out.push({ kind: 'board_instructions' });
83
+ if (!same(live.cap, draft.cap))
84
+ out.push({ kind: 'cap', cap: draft.cap });
85
+ out.push(...laterBoardChanges(live, draft, context));
86
+ return out;
87
+ }
88
+ function laterBoardChanges(live, draft, context) {
89
+ const out = [];
90
+ const used = usedRefs(draft);
91
+ for (const part of Object.values(draft.parts)) {
92
+ if (!used.has(part.id))
93
+ continue;
94
+ const old = live.parts[part.id];
95
+ const pushNames = (def, guard) => guard ? guard.push.flatMap((s) => stepById(def, s)?.name ?? []) : null;
96
+ const [was, now] = [pushNames(live, old?.guard), pushNames(draft, part.guard)];
97
+ const moved = (key) => !same(old?.guard?.[key], part.guard?.[key]);
98
+ if (!same(was, now) || moved('repo') || moved('base'))
99
+ out.push({
100
+ kind: 'guard',
101
+ part: part.id,
102
+ partName: part.name,
103
+ push: now,
104
+ ...(part.guard?.base === undefined ? {} : { base: part.guard.base }),
105
+ });
106
+ if ((old?.initial ?? null) !== (part.initial ?? null)) {
107
+ const choice = part.options.find(({ id }) => id === part.initial);
108
+ out.push({
109
+ kind: 'initial',
110
+ part: part.id,
111
+ partName: part.name,
112
+ partKind: part.kind,
113
+ value: part.initial ?? null,
114
+ ...(choice ? { valueName: choice.name } : {}),
115
+ });
116
+ }
117
+ }
118
+ if (!same(live.split, draft.split))
119
+ out.push({
120
+ kind: 'split',
121
+ board: splitName(draft, context),
122
+ always: draft.split?.always ?? false,
123
+ });
124
+ const motiveNames = (def) => def.drop.motives.map(({ name }) => name);
125
+ if (!same(motiveNames(live), motiveNames(draft)))
126
+ out.push({ kind: 'motives', names: motiveNames(draft) });
127
+ if (live.drop.by !== draft.drop.by)
128
+ out.push({ kind: 'drop_by', by: draft.drop.by });
129
+ if (!same(live.list, draft.list)) {
130
+ const group = draft.list.group;
131
+ const named = group === undefined || group === STEP || group === MOTIVE
132
+ ? group
133
+ : (partOf(draft, group)?.name ?? group);
134
+ out.push({ kind: 'list', as: draft.list.as, ...(named === undefined ? {} : { group: named }) });
135
+ }
136
+ return out;
137
+ }
138
+ // The forward alternatives of a step, which step_ways reports (ways back are their own change).
139
+ function forward(def, stepId) {
140
+ const index = stepIndex(def, stepId);
141
+ return (stepById(def, stepId)?.ways ?? []).filter((way) => way === DONE || stepIndex(def, way) > index);
142
+ }
143
+ // The name of the board a definition's items divide into, or null.
144
+ function splitName(def, context) {
145
+ const split = def.split;
146
+ if (split === undefined)
147
+ return null;
148
+ if (split.board === SAME)
149
+ return def.name;
150
+ return context.boardName?.(split.board) ?? split.board;
151
+ }
152
+ function laterStepChanges(live, draft, id, context) {
153
+ const out = [];
154
+ const old = stepById(live, id);
155
+ const step = stepById(draft, id);
156
+ if (!old || !step)
157
+ return out;
158
+ const { name } = step;
159
+ const skips = (def, s) => def.steps[0]?.id === s.id && s.skipWhenReady && s.reviewer === 'none';
160
+ if (skips(live, old) !== skips(draft, step)) {
161
+ const to = defaultWay(draft, id);
162
+ out.push({
163
+ kind: 'skip',
164
+ step: id,
165
+ name,
166
+ to: stepById(draft, to)?.name ?? to,
167
+ on: skips(draft, step),
168
+ });
169
+ }
170
+ const before = backWaysOf(live, id);
171
+ const after = backWaysOf(draft, id);
172
+ const you = step.doer === 'you';
173
+ for (const to of after.filter((target) => !before.includes(target)))
174
+ out.push({
175
+ kind: 'way_back',
176
+ step: id,
177
+ name,
178
+ to: stepById(draft, to)?.name ?? to,
179
+ you,
180
+ on: true,
181
+ });
182
+ for (const to of before.filter((target) => !after.includes(target)))
183
+ out.push({
184
+ kind: 'way_back',
185
+ step: id,
186
+ name,
187
+ to: stepById(live, to)?.name ?? to,
188
+ you,
189
+ on: false,
190
+ });
191
+ if (old.note.req !== step.note.req)
192
+ out.push({ kind: 'note', step: id, name, on: step.note.req === 'always' });
193
+ if (!same(old.waits, step.waits)) {
194
+ const board = step.waits.includes('parts') ? splitName(draft, context) : null;
195
+ out.push({ kind: 'waits', step: id, name, waits: step.waits, ...(board ? { board } : {}) });
196
+ }
197
+ if (old.doerMayDrop !== step.doerMayDrop)
198
+ out.push({ kind: 'doer_drop', step: id, name, on: step.doerMayDrop });
199
+ return out;
200
+ }
201
+ function suggestion(live, draft, stepId) {
202
+ const index = live.steps.findIndex(({ id }) => id === stepId);
203
+ const next = live.steps.slice(index + 1).find(({ id }) => draft.steps.some((s) => s.id === id));
204
+ return next?.id ?? DONE;
205
+ }
206
+ // Whether the draft still has the phase an open item stands in.
207
+ function phaseSurvives(draft, stepId, phase) {
208
+ const step = draft.steps.find(({ id }) => id === stepId);
209
+ if (!step)
210
+ return false;
211
+ if (phase === 'review')
212
+ return step.reviewer !== 'none';
213
+ return true;
214
+ }
215
+ export function itemEffects(live, draft, items) {
216
+ const out = { moves: [], needs: [], reopened: [], waiting: [], frozen: [] };
217
+ const open = items.flatMap((item) => {
218
+ const at = positionOf(item.state);
219
+ return isClosed(at) ? [] : [{ ...item, step: at.step, phase: at.phase }];
220
+ });
221
+ const wasPushed = new Set(guardedBranch(live)?.guard.push ?? []);
222
+ for (const stepId of guardedBranch(draft)?.guard.push ?? []) {
223
+ const step = stepById(draft, stepId);
224
+ if (!step || wasPushed.has(stepId))
225
+ continue;
226
+ const here = open.filter((item) => item.step === stepId && item.phase !== 'doing');
227
+ if (here.length > 0)
228
+ out.frozen.push({ step: stepId, name: step.name, items: here.map(({ id }) => id) });
229
+ }
230
+ for (const step of draft.steps) {
231
+ const old = stepById(live, step.id);
232
+ for (const wait of step.waits) {
233
+ if (old?.waits.includes(wait))
234
+ continue;
235
+ const count = (item) => (wait === 'parts' ? item.openParts : item.openBlockers);
236
+ const held = open.filter((item) => item.step === step.id && item.phase === 'doing' && (count(item) ?? 0) > 0);
237
+ if (held.length > 0)
238
+ out.waiting.push({ step: step.id, name: step.name, wait, items: held.map(({ id }) => id) });
239
+ }
240
+ }
241
+ for (const old of live.steps) {
242
+ const here = open.filter(({ step }) => step === old.id);
243
+ const step = draft.steps.find(({ id }) => id === old.id);
244
+ if (!step) {
245
+ if (here.length > 0)
246
+ out.moves.push({
247
+ step: old.id,
248
+ name: old.name,
249
+ items: here.map(({ id }) => id),
250
+ suggested: suggestion(live, draft, old.id),
251
+ });
252
+ continue;
253
+ }
254
+ const doing = here.filter(({ phase }) => phase === 'doing').map(({ id }) => id);
255
+ const required = (list) => new Set(list.filter(({ req }) => req === 'always').map(({ ref }) => ref));
256
+ const before = required(old.hand);
257
+ const added = [...required(step.hand)].filter((ref) => !before.has(ref));
258
+ if (doing.length > 0 && added.length > 0)
259
+ out.needs.push({
260
+ step: step.id,
261
+ name: step.name,
262
+ items: doing,
263
+ parts: added.map((ref) => partOf(draft, ref)?.name ?? ''),
264
+ });
265
+ const lost = here.filter(({ phase }) => !phaseSurvives(draft, step.id, phase));
266
+ if (lost.length > 0)
267
+ out.reopened.push({ step: step.id, name: step.name, items: lost.map(({ id }) => id) });
268
+ }
269
+ return out;
270
+ }
271
+ // The state changes publishing makes to open items: those of removed steps go where `moves` says
272
+ // (or to the suggestion), and reviews the draft no longer has go back to work in their step.
273
+ export function itemMoves(live, draft, items, moves) {
274
+ const out = [];
275
+ const motives = new Set(draft.drop.motives.map(({ id }) => id));
276
+ for (const item of items) {
277
+ const at = positionOf(item.state);
278
+ // A discard whose motive the draft no longer has reads as plain Descartado.
279
+ if (isClosed(at)) {
280
+ if (at.motive !== undefined && !motives.has(at.motive))
281
+ out.push({ id: item.id, from: item.state, to: DROPPED });
282
+ continue;
283
+ }
284
+ const kept = draft.steps.some(({ id }) => id === at.step);
285
+ if (!kept) {
286
+ if (!live.steps.some(({ id }) => id === at.step))
287
+ continue;
288
+ const target = moves[at.step] ?? suggestion(live, draft, at.step);
289
+ if (target !== DONE && !draft.steps.some(({ id }) => id === target))
290
+ return { ok: false, step: at.step };
291
+ const to = target === DONE ? DONE : stateOf({ step: target, phase: 'doing' });
292
+ out.push({ id: item.id, from: item.state, to });
293
+ continue;
294
+ }
295
+ if (!phaseSurvives(draft, at.step, at.phase))
296
+ out.push({ id: item.id, from: item.state, to: stateOf({ step: at.step, phase: 'doing' }) });
297
+ }
298
+ return { ok: true, moves: out };
299
+ }
@@ -0,0 +1,232 @@
1
+ import { closeIconNames, isIconName } from '../icons.js';
2
+ import { fitsRole, isRole } from './analysis.js';
3
+ import { isLandStep, startsWith, waysOf } from './engine.js';
4
+ import { mentionedRefs, mentionNames } from './mentions.js';
5
+ import { DONE, isEvidence, LEVELS, partOf, SAME, stepIndex, TITLE, usedRefs, WHEN_KINDS, } from './model.js';
6
+ // Words Otea already uses for its own things, in both languages, compared without case.
7
+ export const RESERVED_NAMES = [
8
+ 'done',
9
+ 'dropped',
10
+ 'hecho',
11
+ 'descartado',
12
+ 'publish',
13
+ 'publicar',
14
+ 'stuck',
15
+ 'atasco',
16
+ 'turn',
17
+ 'turno',
18
+ 'your turn',
19
+ 'te toca',
20
+ 'round',
21
+ 'ronda',
22
+ 'draft',
23
+ 'borrador',
24
+ ];
25
+ const key = (name) => name.trim().toLocaleLowerCase();
26
+ export function problemsOf(def, context) {
27
+ const out = [];
28
+ const add = (level, code, at, params = {}) => out.push({ level, code, params, at });
29
+ const used = usedRefs(def);
30
+ const partAt = (ref) => {
31
+ if (def.form.some((entry) => entry.ref === ref))
32
+ return { kind: 'form' };
33
+ const step = def.steps.find(({ hand }) => hand.some((entry) => entry.ref === ref));
34
+ if (step)
35
+ return { kind: 'part', id: ref, step: step.id };
36
+ return { kind: 'anytime' };
37
+ };
38
+ if (key(def.name) === '')
39
+ add('error', 'board_unnamed', { kind: 'about' });
40
+ else if ((context.takenNames ?? []).some((name) => key(name) === key(def.name)))
41
+ add('error', 'board_name_taken', { kind: 'about' }, { name: def.name.trim() });
42
+ // An icon Otea has no drawing for would publish a type it cannot draw: refused here, by name.
43
+ const icon = def.icon.trim();
44
+ if (icon !== '' && !isIconName(icon))
45
+ add('error', 'icon_unknown', { kind: 'about' }, { icon, close: closeIconNames(icon) });
46
+ if (def.steps.length === 0)
47
+ add('error', 'no_steps', { kind: 'form' });
48
+ for (const step of def.steps) {
49
+ if (key(step.name) === '')
50
+ add('error', 'step_unnamed', { kind: 'step', id: step.id });
51
+ }
52
+ const parts = Object.values(def.parts).filter(({ id }) => used.has(id));
53
+ for (const part of parts) {
54
+ if (key(part.name) === '')
55
+ add('error', 'part_unnamed', partAt(part.id));
56
+ }
57
+ // One name space: the title, the parts in use and the steps.
58
+ const names = new Map();
59
+ const claim = (name, use, at) => {
60
+ const k = key(name);
61
+ if (k === '')
62
+ return;
63
+ const seen = names.get(k);
64
+ if (!seen) {
65
+ names.set(k, { name: name.trim(), uses: [use] });
66
+ return;
67
+ }
68
+ seen.uses.push(use);
69
+ if (seen.uses.length === 2)
70
+ add('error', 'duplicate_name', at, { name: seen.name, uses: seen.uses });
71
+ };
72
+ claim(def.title, 'title', { kind: 'form' });
73
+ for (const part of parts)
74
+ claim(part.name, isEvidence(part) ? 'evidence' : 'field', partAt(part.id));
75
+ for (const step of def.steps)
76
+ claim(step.name, 'step', { kind: 'step', id: step.id });
77
+ for (const step of def.steps) {
78
+ for (const hand of step.hand) {
79
+ if (!partOf(def, hand.ref))
80
+ add('error', 'part_missing', { kind: 'step', id: step.id });
81
+ }
82
+ }
83
+ for (const ref of [...def.form.map((entry) => entry.ref), ...def.anytime]) {
84
+ if (!partOf(def, ref))
85
+ add('error', 'part_missing', { kind: ref === TITLE ? 'form' : 'anytime' });
86
+ }
87
+ for (const step of def.steps) {
88
+ if (RESERVED_NAMES.includes(key(step.name)))
89
+ add('warning', 'reserved_name', { kind: 'step', id: step.id }, { name: step.name.trim() });
90
+ }
91
+ for (const step of def.steps) {
92
+ const readable = new Set([...startsWith(def, step.id).map(({ ref }) => ref), ...def.anytime]);
93
+ for (const hand of step.hand) {
94
+ if (hand.req !== 'when')
95
+ continue;
96
+ const read = hand.when ? partOf(def, hand.when.part) : undefined;
97
+ const ok = hand.when !== undefined &&
98
+ read !== undefined &&
99
+ WHEN_KINDS.includes(read.kind) &&
100
+ readable.has(hand.when.part) &&
101
+ hand.when.value !== '';
102
+ if (!ok)
103
+ add('error', 'when_unreadable', { kind: 'part', id: hand.ref, step: step.id }, { part: partOf(def, hand.ref)?.name ?? '', step: step.name });
104
+ }
105
+ }
106
+ // A way leads to another step, later or earlier (taken back), or to Hecho; never to itself.
107
+ def.steps.forEach((step, index) => {
108
+ for (const way of step.ways) {
109
+ const at = stepIndex(def, way);
110
+ if (way !== DONE && (at < 0 || at === index))
111
+ add('error', 'way_invalid', { kind: 'step', id: step.id }, { step: step.name });
112
+ }
113
+ });
114
+ def.steps.forEach((step, index) => {
115
+ if (step.back === SAME)
116
+ return;
117
+ const back = stepIndex(def, step.back);
118
+ if (back < 0 || back > index)
119
+ add('error', 'back_invalid', { kind: 'step', id: step.id }, { step: step.name });
120
+ });
121
+ if (def.cap.on && (!Number.isInteger(def.cap.n) || def.cap.n < 1))
122
+ add('error', 'cap_invalid', { kind: 'about' });
123
+ // Only you say something is Hecho: an agent may not close an item as done, by handing it off with
124
+ // nobody reviewing or by approving it; except to land work in a last step it reaches only once
125
+ // you approved it.
126
+ for (const step of def.steps) {
127
+ const closer = step.reviewer === 'none' ? step.doer : step.reviewer;
128
+ if (closer === 'you' || !waysOf(def, step.id).includes(DONE))
129
+ continue;
130
+ if (isLandStep(def, step.id))
131
+ continue;
132
+ add('error', 'agent_closes', { kind: 'step', id: step.id }, { step: step.name });
133
+ }
134
+ for (const step of def.steps) {
135
+ if (step.doer === 'you' && step.reviewer === 'you')
136
+ add('warning', 'self_review', { kind: 'step', id: step.id }, { step: step.name });
137
+ }
138
+ // A step's instructions mention parts and steps as @[id]; a template's @{key}, or an id the board
139
+ // does not have, would reach agents as it is written.
140
+ for (const step of def.steps) {
141
+ const text = Object.values(step.instructions).join('\n');
142
+ const at = { kind: 'step', id: step.id };
143
+ if (/@\{[^}]*\}/.test(text))
144
+ add('warning', 'mention_raw', at, { step: step.name });
145
+ if (mentionedRefs(text).some((ref) => !mentionNames(def, ref)))
146
+ add('warning', 'mention_unknown', at, { step: step.name });
147
+ }
148
+ out.push(...laterProblems(def, context, partAt));
149
+ return out;
150
+ }
151
+ // The settings boards gained to say what presets did: waits, skipping on creation, the split, the
152
+ // protected branch, start values and motives.
153
+ function laterProblems(def, context, partAt) {
154
+ const out = [];
155
+ const add = (level, code, at, params = {}) => out.push({ level, code, params, at });
156
+ const used = usedRefs(def);
157
+ def.steps.forEach((step, index) => {
158
+ const at = { kind: 'step', id: step.id };
159
+ if (step.waits.includes('parts') && !def.split)
160
+ add('error', 'wait_no_split', at, { step: step.name, board: def.name });
161
+ if (step.skipWhenReady && (index > 0 || step.reviewer !== 'none'))
162
+ add('error', 'skip_invalid', at, { step: step.name });
163
+ else if (index === 0 && alwaysSkipped(def, step))
164
+ add('warning', 'step_always_skipped', at, { step: step.name });
165
+ });
166
+ const split = def.split;
167
+ if (split && split.board !== SAME && context.boards && context.id !== undefined) {
168
+ const other = context.boards.find(({ id }) => id === split.board);
169
+ if (!other)
170
+ add('error', 'split_unknown', { kind: 'about' }, { board: def.name });
171
+ else if (other.split?.board === context.id)
172
+ add('error', 'split_cycle', { kind: 'about' }, { board: def.name, other: other.name });
173
+ }
174
+ for (const part of Object.values(def.parts)) {
175
+ if (!used.has(part.id))
176
+ continue;
177
+ if (part.guard && !part.guard.push.some((id) => stepIndex(def, id) >= 0))
178
+ add('error', 'guard_no_push', partAt(part.id), { part: part.name });
179
+ if (part.guard?.base !== undefined && !isBranchName(part.guard.base))
180
+ add('error', 'guard_base', partAt(part.id), { part: part.name });
181
+ if (part.initial !== undefined && !initialFits(part.kind, part.options, part.initial))
182
+ add('error', 'initial_invalid', partAt(part.id), { part: part.name });
183
+ }
184
+ // A role of the analysis views must name a field the board uses, of a kind the role reads.
185
+ for (const [role, ref] of Object.entries(def.analysis ?? {})) {
186
+ if (!isRole(role) || ref === undefined)
187
+ continue;
188
+ const part = def.parts[ref];
189
+ if (!part || !used.has(ref))
190
+ add('error', 'analysis_missing', { kind: 'about' }, { role });
191
+ else if (!fitsRole(role, part))
192
+ add('error', 'analysis_kind', { kind: 'about' }, { role, part: part.name });
193
+ }
194
+ // A board with motives whose agent may drop is not a problem: the drop asks for the motive.
195
+ return out;
196
+ }
197
+ // Whether every new item skips the first step (P8-R3-2): it starts items past it when they come with
198
+ // all it hands, and the form requires every one of those, so it never runs. Only what the form
199
+ // surely fills counts: a field always asked for, never evidence, a checklist (each point must be
200
+ // ticked) or a field required only when another holds; a lead may keep an item at the step.
201
+ function alwaysSkipped(def, step) {
202
+ if (!step.skipWhenReady || step.reviewer !== 'none' || step.lead)
203
+ return false;
204
+ const required = new Set(def.form.filter((entry) => entry.required).map(({ ref }) => ref));
205
+ return step.hand.every((hand) => {
206
+ const part = partOf(def, hand.ref);
207
+ if (!part || isEvidence(part) || part.kind === 'check')
208
+ return false;
209
+ if (hand.req === 'no')
210
+ return true;
211
+ return hand.req === 'always' && (hand.ref === TITLE || required.has(hand.ref));
212
+ });
213
+ }
214
+ // A git branch name as a person types one: no spaces or the characters git refuses, no "..", not
215
+ // starting with a slash or a dot, nor ending with one.
216
+ function isBranchName(name) {
217
+ return /^(?![./])(?!.*\.\.)(?!.*[./]$)[^\s~^:?*[\\]+$/.test(name);
218
+ }
219
+ function initialFits(kind, options, value) {
220
+ if (kind === 'level')
221
+ return LEVELS.includes(value);
222
+ if (kind === 'yesno')
223
+ return value === 'yes' || value === 'no';
224
+ if (kind === 'choice')
225
+ return options.some(({ id }) => id === value);
226
+ if (kind === 'branch')
227
+ return isBranchName(value);
228
+ return false;
229
+ }
230
+ export function blocking(problems) {
231
+ return problems.some(({ level }) => level === 'error');
232
+ }
@@ -0,0 +1,84 @@
1
+ import { parseTestReport } from '../test-report.js';
2
+ // A checklist point ticked with what shows it holds: a file attached to the item (a screenshot, a
3
+ // recording), a line of an attached log, or a test that passes in an attached test report. Otea
4
+ // checks the line and the test when the agent names them, so a kept proof is one it verified.
5
+ export const POINT_PROVED = 'point_proved';
6
+ // The longest a log line is kept with its proof: enough to recognise it, never a whole stack.
7
+ export const PROOF_TEXT = 200;
8
+ // The proofs given since `since` (the round's start), the last one per point winning: a point
9
+ // proved again in the round is proved by the newer one.
10
+ export function proofsFrom(events, since) {
11
+ const out = new Map();
12
+ for (const event of events) {
13
+ if (event.type !== POINT_PROVED)
14
+ continue;
15
+ if (since !== undefined && event.at < since)
16
+ continue;
17
+ const { data } = event;
18
+ const part = String(data.part ?? '');
19
+ const point = String(data.point ?? '');
20
+ const kind = data.kind;
21
+ if (!part || !point || (kind !== 'file' && kind !== 'log' && kind !== 'test'))
22
+ continue;
23
+ out.set(`${part}\u0000${point}`, {
24
+ part,
25
+ point,
26
+ kind,
27
+ evidence: Number(data.evidence),
28
+ file: String(data.file ?? ''),
29
+ ...(typeof data.line === 'number' ? { line: data.line } : {}),
30
+ ...(typeof data.text === 'string' ? { text: data.text } : {}),
31
+ ...(typeof data.test === 'string' ? { test: data.test } : {}),
32
+ at: event.at,
33
+ by: event.actor.name,
34
+ });
35
+ }
36
+ return [...out.values()];
37
+ }
38
+ // The points of each checklist part proved in the round, by part id: what the engine reads.
39
+ export function provedPoints(proofs) {
40
+ const out = {};
41
+ for (const { part, point } of proofs) {
42
+ const points = out[part] ?? [];
43
+ points.push(point);
44
+ out[part] = points;
45
+ }
46
+ return out;
47
+ }
48
+ // The log's line `line` (from 1), or why it cannot prove anything: past the end, or blank.
49
+ export function logLine(text, line) {
50
+ const lines = text.split(/\r?\n/);
51
+ if (lines.at(-1) === '')
52
+ lines.pop();
53
+ if (!Number.isInteger(line) || line < 1)
54
+ return { ok: false, why: `the line must be a number from 1` };
55
+ if (line > lines.length)
56
+ return {
57
+ ok: false,
58
+ why: `it has ${lines.length} line${lines.length === 1 ? '' : 's'}`,
59
+ };
60
+ const said = (lines[line - 1] ?? '').trim();
61
+ if (said === '')
62
+ return { ok: false, why: `line ${line} is blank` };
63
+ return {
64
+ ok: true,
65
+ text: said.length > PROOF_TEXT ? `${said.slice(0, PROOF_TEXT - 1)}…` : said,
66
+ };
67
+ }
68
+ function fold(text) {
69
+ return text.normalize('NFD').replace(/[̀-ͯ]/g, '').trim().toLowerCase();
70
+ }
71
+ // How a test reads in full: its file or suite, then its name.
72
+ export function testTitle(test) {
73
+ return test.file ? `${test.file} › ${test.name}` : test.name;
74
+ }
75
+ // The test a report has under `wanted`: its name, or its file and name ("suite › name"), in any
76
+ // case. A report that is not one (no JUnit XML, no vitest or jest JSON) has none.
77
+ export function findTest(report, wanted) {
78
+ const parsed = parseTestReport(report);
79
+ if (!parsed)
80
+ return undefined;
81
+ const target = fold(wanted);
82
+ return (parsed.cases.find((test) => fold(testTitle(test)) === target) ??
83
+ parsed.cases.find((test) => fold(test.name) === target));
84
+ }