@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,114 @@
1
+ import { timeText } from '../time.js';
2
+ // An agent's question to the person (otea ask): asking hands the turn to the person without moving
3
+ // the item (the step, its round and the lease stay as they are); the person's answer hands it back
4
+ // to the agent, which reads it in next and show, as a send-back note, in the same round. A question
5
+ // is open while unanswered in the round of the step it was asked in. The thread is the item's
6
+ // question_asked and question_answered events; this module reads it and writes what agents read of
7
+ // it, in English, as the rest of what agents read (core/board/next.ts). Doubts never go in the
8
+ // person's notes thread (core/board/notes.ts): that one is the person's, and changes no turn.
9
+ export const QUESTION_ASKED = 'question_asked';
10
+ export const QUESTION_ANSWERED = 'question_answered';
11
+ // The item's questions, oldest first, each with its answer once there is one.
12
+ export function questionsOf(events) {
13
+ const out = new Map();
14
+ for (const { type, actor, at, data } of events) {
15
+ if (typeof data.question !== 'number')
16
+ continue;
17
+ if (type === QUESTION_ASKED) {
18
+ out.set(data.question, {
19
+ question: data.question,
20
+ text: String(data.text ?? ''),
21
+ at,
22
+ by: actor.name,
23
+ step: String(data.step ?? ''),
24
+ stepName: String(data.stepName ?? data.step ?? ''),
25
+ round: typeof data.round === 'number' ? data.round : 1,
26
+ });
27
+ }
28
+ else if (type === QUESTION_ANSWERED) {
29
+ const asked = out.get(data.question);
30
+ if (!asked || asked.answer)
31
+ continue;
32
+ asked.answer = {
33
+ text: String(data.text ?? ''),
34
+ at,
35
+ by: actor.name,
36
+ ...(typeof data.via === 'string' ? { via: data.via } : {}),
37
+ };
38
+ }
39
+ }
40
+ return [...out.values()];
41
+ }
42
+ // The question an item's events leave open (oldest first): asked, not answered, and the item not
43
+ // moved since. A move ends the round it was asked in, and with it the question.
44
+ export function openQuestion(events) {
45
+ let open;
46
+ for (const { type, data } of events) {
47
+ if (type === 'transitioned')
48
+ open = undefined;
49
+ else if (type === QUESTION_ASKED && typeof data.question === 'number')
50
+ open = data.question;
51
+ else if (type === QUESTION_ANSWERED && data.question === open)
52
+ open = undefined;
53
+ }
54
+ if (open === undefined)
55
+ return undefined;
56
+ return questionsOf(events).find(({ question }) => question === open);
57
+ }
58
+ // The text quoted: its first line opens the quote, later lines indented under it.
59
+ function quoted(head, text, indent) {
60
+ const [first = '', ...rest] = text.trim().split(/\r?\n/);
61
+ const lines = [`${head}"${first}`, ...rest.map((line) => `${indent}${line}`)];
62
+ lines[lines.length - 1] += '"';
63
+ return lines;
64
+ }
65
+ const WAKE = 'otea wait --turn agent wakes you when they answer';
66
+ // What otea ask says once the question is asked.
67
+ export function askedText(id) {
68
+ return `Asked the person on ${id}: the turn is theirs until they answer; the step, round and lease stay as they are. They answer it in Otea (on the item page or the phone); if they answer in the chat instead, put their words on it: otea answer ${id} "<their words>". ${WAKE}; read it then: otea show ${id}`;
69
+ }
70
+ // What otea answer says once the person's answer from the chat is on the question. `asker`: the
71
+ // agent that asked, when another agent noted the answer, and whether its session ended: the item
72
+ // then waits for whoever claims it (P3C-R3-11).
73
+ export function chatAnswerText(id, asker) {
74
+ const noted = `Noted the person's answer on ${id}, as given in the chat.`;
75
+ if (asker?.gone)
76
+ return `${noted} ${asker.name}, which asked, is gone (its session ended): claim it to carry on: otea claim ${id}; then address it and hand off as the step says.`;
77
+ if (asker)
78
+ return `${noted} It goes back to ${asker.name}, which asked, in the same round; its wait wakes it.`;
79
+ return `${noted} The turn is yours again in the same round: address it, then hand off as the step says.`;
80
+ }
81
+ // What next and show say of an item whose question waits for the person.
82
+ export function waitingAnswerText(question, me) {
83
+ const who = question.by === me ? 'your' : `${question.by}'s`;
84
+ return [
85
+ ...quoted(`Waiting for the person to answer ${who} question: `, question.text, ' '),
86
+ ` The turn is theirs: do not hand it off yet; ${WAKE}.`,
87
+ ];
88
+ }
89
+ // next's and show's block for the round's answered questions, in the order they were asked (a
90
+ // conversation reads forward): each question and the person's answer, which the agent addresses as
91
+ // a send-back note.
92
+ export function answersBlock(questions, me) {
93
+ const answered = questions.filter((each) => each.answer !== undefined);
94
+ return answered.flatMap(({ text, by, answer }) => {
95
+ if (!answer)
96
+ return [];
97
+ const who = by === me ? 'You' : by;
98
+ return [
99
+ '',
100
+ ...quoted(`${who} asked the person: `, text, ' '),
101
+ ...quoted('The person answered: ', answer.text, ' '),
102
+ ` ${timeText(answer.at)}; address it in this round.`,
103
+ ];
104
+ });
105
+ }
106
+ // What otea wait says when an answer wakes it.
107
+ export function waitAnswerText(id) {
108
+ return `${id}: the person answered your question. Read it: otea show ${id}`;
109
+ }
110
+ // Whether a handoff's words ask the person something: how an agent asked before otea ask, kept only
111
+ // to read old events that way.
112
+ export function legacyAsks(reason) {
113
+ return (reason ?? '').trim().endsWith('?');
114
+ }
@@ -0,0 +1,220 @@
1
+ import { OteaError } from '../errors.js';
2
+ import { isClosed, positionOf, stateOf } from './engine.js';
3
+ import { CHOICE_KINDS, DONE, DROPPED, isEvidence, LEVELS, stepById, TITLE, usedRefs, } from './model.js';
4
+ import { DONE_NAME, DROPPED_NAME } from './next.js';
5
+ import { LEVEL_SAID, TITLE_NAME } from './template-words.js';
6
+ // What a reader of a board item meets and types: names, never the hidden ids under them. An agent
7
+ // fills `--field Tamaño=Una`, attaches `--module Bocetos`, and reads `state: Concepto (in review)`;
8
+ // the ids stay the storage keys. Pure and browser-safe.
9
+ function fold(text) {
10
+ return text.normalize('NFD').replace(/[̀-ͯ]/g, '').trim().toLocaleLowerCase();
11
+ }
12
+ // The parts a reader can name: every part the board uses, the title first.
13
+ function namedParts(def) {
14
+ const used = usedRefs(def);
15
+ return Object.values(def.parts).filter((part) => used.has(part.id));
16
+ }
17
+ // A part by its name or its id; undefined when the board has none.
18
+ export function partByName(def, key) {
19
+ if (key === TITLE || fold(key) === fold(def.title))
20
+ return undefined;
21
+ if (def.parts[key])
22
+ return def.parts[key];
23
+ const wanted = fold(key);
24
+ return Object.values(def.parts).find((part) => fold(part.name) === wanted);
25
+ }
26
+ function namesOf(parts) {
27
+ return parts.map(({ name }) => name).join(', ');
28
+ }
29
+ // The level scale's words in English and Spanish, each reading as its key.
30
+ const LEVEL_WORDS = {
31
+ low: 'low',
32
+ medium: 'medium',
33
+ high: 'high',
34
+ critical: 'critical',
35
+ baja: 'low',
36
+ media: 'medium',
37
+ alta: 'high',
38
+ critica: 'critical',
39
+ };
40
+ function oneChoice(part, given) {
41
+ const wanted = fold(given);
42
+ const found = part.options.find(({ id, name }) => id === given || fold(name) === wanted);
43
+ if (!found)
44
+ throw new OteaError('invalid_fields', `${part.name} must be one of ${part.options.map(({ name }) => name).join(', ')}`);
45
+ return found.id;
46
+ }
47
+ function listOf(value) {
48
+ if (Array.isArray(value))
49
+ return value.map(String);
50
+ const text = String(value).trim();
51
+ if (text.startsWith('[')) {
52
+ try {
53
+ const parsed = JSON.parse(text);
54
+ if (Array.isArray(parsed))
55
+ return parsed.map(String);
56
+ }
57
+ catch {
58
+ // Not JSON: names joined by commas.
59
+ }
60
+ }
61
+ return text
62
+ .split(',')
63
+ .map((piece) => piece.trim())
64
+ .filter(Boolean);
65
+ }
66
+ function valueFor(part, value) {
67
+ if (value === null || value === undefined || value === '')
68
+ return value;
69
+ if (part.kind === 'choice')
70
+ return oneChoice(part, String(value));
71
+ if (part.kind === 'multi' || part.kind === 'check')
72
+ return JSON.stringify(listOf(value).map((piece) => oneChoice(part, piece)));
73
+ if (part.kind === 'level') {
74
+ const key = LEVEL_WORDS[fold(String(value))];
75
+ if (!key)
76
+ throw new OteaError('invalid_fields', `${part.name} must be one of ${LEVELS.join(', ')}`);
77
+ return key;
78
+ }
79
+ if (part.kind === 'yesno') {
80
+ const word = fold(String(value));
81
+ if (['yes', 'si', 'true'].includes(word))
82
+ return 'yes';
83
+ if (['no', 'false'].includes(word))
84
+ return 'no';
85
+ throw new OteaError('invalid_fields', `${part.name} must be yes or no`);
86
+ }
87
+ return value;
88
+ }
89
+ // `--description` (and MCP's `description`) on a board with no field of that name: the long text
90
+ // named Description in English or Spanish, else the board's only long text. Refuses, naming the
91
+ // long texts, a board with several and none of them the description, or with none.
92
+ const DESCRIPTION = 'description';
93
+ const DESCRIPTION_NAMES = new Set([DESCRIPTION, 'descripcion']);
94
+ function descriptionOf(def) {
95
+ const long = namedParts(def).filter((part) => part.kind === 'long');
96
+ const named = long.filter((part) => DESCRIPTION_NAMES.has(fold(part.name)));
97
+ const pool = named.length > 0 ? named : long;
98
+ if (pool.length === 1 && pool[0])
99
+ return pool[0];
100
+ throw new OteaError('invalid_fields', long.length === 0
101
+ ? `${def.name} has no description field; its fields are ${fieldNames(def).join(', ')}`
102
+ : `${def.name} has no description field; fill one of its long texts by name: ${namesOf(long)}`);
103
+ }
104
+ // The fields a reader typed, by name or id, as the item stores them: by part id, with choices as
105
+ // their ids. Refuses, in words, a name the board has not and a value no choice has.
106
+ export function readFieldInput(def, fields) {
107
+ const out = {};
108
+ for (const [key, value] of Object.entries(fields)) {
109
+ if (key === TITLE || fold(key) === fold(def.title)) {
110
+ out[TITLE] = value;
111
+ continue;
112
+ }
113
+ const part = partByName(def, key) ?? (fold(key) === DESCRIPTION ? descriptionOf(def) : undefined);
114
+ // A part the agent attaches as a file is no field to fill (P3C-R3-5): said so, with the command.
115
+ if (part && isEvidence(part))
116
+ throw attachedPart(part);
117
+ if (!part) {
118
+ throw new OteaError('invalid_fields', `${def.name} has no field "${key}"; its fields are ${fieldNames(def).join(', ')}`);
119
+ }
120
+ if (part.id in out)
121
+ throw new OteaError('invalid_fields', `${part.name} given twice`);
122
+ out[part.id] = valueFor(part, value);
123
+ }
124
+ return out;
125
+ }
126
+ // A part the agent attaches as a file named as a field: how to attach it instead. `id` and `file`
127
+ // fill the command where the caller knows them.
128
+ export function attachedPart(part, id = '<id>', file = '<file>') {
129
+ const named = (text) => (/^[\w.<>/-]+$/.test(text) ? text : `"${text}"`);
130
+ return new OteaError('invalid_fields', `${part.name} is a part you attach as a file, not a field: otea attach ${id} ${named(file)} --module ${named(part.name)}`);
131
+ }
132
+ // The evidence part a reader names (`--module Bocetos`), as the module id it was compiled to.
133
+ export function evidenceByName(def, key) {
134
+ const part = partByName(def, key);
135
+ if (part && isEvidence(part))
136
+ return part.id;
137
+ throw new OteaError('evidence_not_accepted', `${def.name} has no evidence "${key}"; its evidence is ${namesOf(namedParts(def).filter(isEvidence))}`);
138
+ }
139
+ // How a review reads after its step's name, in the board's language (Concepto (en revisión)).
140
+ const IN_REVIEW = { en: 'in review', es: 'en revisión' };
141
+ // A state as a reader says it: the step's name, with its review when it is one.
142
+ export function stateName(def, state) {
143
+ const position = positionOf(state);
144
+ if (isClosed(position))
145
+ return position.closed === DONE ? DONE_NAME : DROPPED_NAME;
146
+ const name = stepById(def, position.step)?.name ?? position.step;
147
+ if (position.phase === 'review')
148
+ return `${name} (${IN_REVIEW[langOf(def)]})`;
149
+ return name;
150
+ }
151
+ // A review named in either language reads as the board says it, so `(in review)` still finds
152
+ // `Concepto (en revisión)` and the other way round.
153
+ function reviewSaidAsBoard(def, wanted) {
154
+ const said = IN_REVIEW[langOf(def)];
155
+ return Object.values(IN_REVIEW).reduce((text, other) => text.endsWith(`(${other})`) ? `${text.slice(0, -other.length - 2)}(${said})` : text, wanted);
156
+ }
157
+ // Every state of the board's compiled workflow, closed ones included.
158
+ function statesOf(def) {
159
+ return [
160
+ ...def.steps.flatMap((step) => {
161
+ const doing = stateOf({ step: step.id, phase: 'doing' });
162
+ if (step.reviewer === 'none')
163
+ return [doing];
164
+ return [doing, stateOf({ step: step.id, phase: 'review' })];
165
+ }),
166
+ DONE,
167
+ DROPPED,
168
+ ];
169
+ }
170
+ // The state a reader names (`otea move CRI-1 "Concepto (in review)"`, `Animar`, `Hecho`), or the
171
+ // text as given when it names none, so a stored state still reads as itself.
172
+ export function stateByName(def, text) {
173
+ return findState(def, text) ?? text;
174
+ }
175
+ // The state a reader names, by name (in any case) or id; undefined when the board has none.
176
+ export function findState(def, text) {
177
+ const wanted = fold(reviewSaidAsBoard(def, text));
178
+ if (['hecho', 'done'].includes(wanted))
179
+ return DONE;
180
+ if (['descartado', 'dropped'].includes(wanted))
181
+ return DROPPED;
182
+ return statesOf(def).find((state) => state === text || fold(stateName(def, state)) === wanted);
183
+ }
184
+ // The names a reader can give the board's states, in its order: each step, its reviews, then
185
+ // Done and Dropped.
186
+ export function stateNames(def) {
187
+ return [...new Set(statesOf(def).map((state) => stateName(def, state)))];
188
+ }
189
+ // The names a reader can give the board's fields, its evidence aside.
190
+ export function fieldNames(def) {
191
+ return namedParts(def)
192
+ .filter((part) => !isEvidence(part))
193
+ .map(({ name }) => name);
194
+ }
195
+ // The language a board was made in: its title field is named in it (Título).
196
+ export function langOf(def) {
197
+ return def.title === TITLE_NAME.es ? 'es' : 'en';
198
+ }
199
+ // A stored value as a reader says it: choices by their names, a level in the board's language
200
+ // (Severidad: media), as its field's name is.
201
+ export function valueName(part, value, lang = 'en') {
202
+ if (part.kind === 'level' && typeof value === 'string')
203
+ return LEVEL_SAID[lang][value] ?? value;
204
+ if (CHOICE_KINDS.includes(part.kind) && value !== null && value !== undefined)
205
+ return listOf(value)
206
+ .map((id) => part.options.find((choice) => choice.id === id)?.name ?? id)
207
+ .join(', ');
208
+ return typeof value === 'string' ? value : JSON.stringify(value);
209
+ }
210
+ // An item's fields by name, choices by name, for a reader.
211
+ export function fieldsByName(def, fields) {
212
+ const out = {};
213
+ for (const [key, value] of Object.entries(fields)) {
214
+ const part = def.parts[key];
215
+ out[part?.name ?? key] = part
216
+ ? valueName(part, value, langOf(def))
217
+ : valueName({ id: key, name: key, kind: 'text', hint: '', options: [] }, value);
218
+ }
219
+ return out;
220
+ }