@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.
- package/LICENSE +661 -0
- package/README.es.md +151 -0
- package/README.md +252 -2
- package/THIRD_PARTY_NOTICES.md +114 -0
- package/bin/otea.mjs +28 -0
- package/dist/app/agent-detail.js +26 -0
- package/dist/app/agent-draft.js +429 -0
- package/dist/app/agent-prompts.js +52 -0
- package/dist/app/agents.js +77 -0
- package/dist/app/asking.js +43 -0
- package/dist/app/board-archive.js +243 -0
- package/dist/app/board-migration.js +272 -0
- package/dist/app/boards.js +870 -0
- package/dist/app/branch-owner.js +48 -0
- package/dist/app/brief.js +53 -0
- package/dist/app/choices.js +61 -0
- package/dist/app/collections.js +101 -0
- package/dist/app/context.js +1 -0
- package/dist/app/crop.js +56 -0
- package/dist/app/devices.js +62 -0
- package/dist/app/draft-request.js +82 -0
- package/dist/app/events.js +12 -0
- package/dist/app/evidence.js +287 -0
- package/dist/app/gates.js +610 -0
- package/dist/app/guide.js +37 -0
- package/dist/app/home.js +145 -0
- package/dist/app/init-boards.js +36 -0
- package/dist/app/intake.js +25 -0
- package/dist/app/item-search.js +141 -0
- package/dist/app/items.js +318 -0
- package/dist/app/keep-waiting.js +44 -0
- package/dist/app/land-order.js +107 -0
- package/dist/app/language.js +52 -0
- package/dist/app/launcher.js +56 -0
- package/dist/app/lease-take.js +54 -0
- package/dist/app/leases.js +86 -0
- package/dist/app/machine.js +39 -0
- package/dist/app/merged.js +89 -0
- package/dist/app/migrate.js +171 -0
- package/dist/app/next.js +1637 -0
- package/dist/app/notes.js +319 -0
- package/dist/app/notify-targets.js +113 -0
- package/dist/app/opened.js +25 -0
- package/dist/app/owner-only.js +34 -0
- package/dist/app/performance.js +28 -0
- package/dist/app/phone.js +97 -0
- package/dist/app/presence.js +596 -0
- package/dist/app/preset-views.js +25 -0
- package/dist/app/presets.js +129 -0
- package/dist/app/priority.js +156 -0
- package/dist/app/profile.js +86 -0
- package/dist/app/project.js +247 -0
- package/dist/app/proofs.js +179 -0
- package/dist/app/questions.js +215 -0
- package/dist/app/reader-filter.js +58 -0
- package/dist/app/relations.js +164 -0
- package/dist/app/relay.js +98 -0
- package/dist/app/repos.js +176 -0
- package/dist/app/restart.js +92 -0
- package/dist/app/set-aside.js +64 -0
- package/dist/app/system-locale.js +6 -0
- package/dist/app/tailscale-cli.js +77 -0
- package/dist/app/tailscale-testing.js +41 -0
- package/dist/app/tailscale.js +177 -0
- package/dist/app/tips.js +30 -0
- package/dist/app/topics-everywhere.js +53 -0
- package/dist/app/topics.js +453 -0
- package/dist/app/undo.js +52 -0
- package/dist/app/validate.js +131 -0
- package/dist/app/watch.js +48 -0
- package/dist/cli/command.js +44 -0
- package/dist/cli/commands.js +3303 -0
- package/dist/cli/exit-codes.js +70 -0
- package/dist/cli/forge.js +176 -0
- package/dist/cli/format.js +340 -0
- package/dist/cli/gh.js +17 -0
- package/dist/cli/gitrepo.js +489 -0
- package/dist/cli/help.js +101 -0
- package/dist/cli/hooks.js +232 -0
- package/dist/cli/main.js +37 -0
- package/dist/cli/merged-outside.js +58 -0
- package/dist/cli/names.js +154 -0
- package/dist/cli/opener.js +21 -0
- package/dist/cli/owner.js +154 -0
- package/dist/cli/phone.js +221 -0
- package/dist/cli/ports.js +24 -0
- package/dist/cli/probe.js +18 -0
- package/dist/cli/run.js +246 -0
- package/dist/cli/serve-file.js +21 -0
- package/dist/cli/stats.js +55 -0
- package/dist/cli/version.js +3 -0
- package/dist/core/agent-guide.js +31 -0
- package/dist/core/agent-prompts.js +139 -0
- package/dist/core/authority.js +94 -0
- package/dist/core/board/analysis.js +86 -0
- package/dist/core/board/choices.js +100 -0
- package/dist/core/board/compile.js +362 -0
- package/dist/core/board/engine.js +523 -0
- package/dist/core/board/hints.js +46 -0
- package/dist/core/board/history.js +146 -0
- package/dist/core/board/ids.js +87 -0
- package/dist/core/board/joins.js +30 -0
- package/dist/core/board/mentions.js +68 -0
- package/dist/core/board/merged.js +18 -0
- package/dist/core/board/model.js +135 -0
- package/dist/core/board/next.js +1116 -0
- package/dist/core/board/notes.js +298 -0
- package/dist/core/board/performance.js +218 -0
- package/dist/core/board/plan.js +299 -0
- package/dist/core/board/problems.js +232 -0
- package/dist/core/board/proofs.js +84 -0
- package/dist/core/board/questions.js +114 -0
- package/dist/core/board/reading.js +220 -0
- package/dist/core/board/readings.js +534 -0
- package/dist/core/board/schema.js +335 -0
- package/dist/core/board/shape-words.js +179 -0
- package/dist/core/board/template-words.js +23 -0
- package/dist/core/board/templates-catalogue.js +965 -0
- package/dist/core/board/templates-coverage.js +261 -0
- package/dist/core/board/templates-flows.js +779 -0
- package/dist/core/board/templates.js +586 -0
- package/dist/core/brief.js +93 -0
- package/dist/core/diagram.js +80 -0
- package/dist/core/errors.js +12 -0
- package/dist/core/evidence.js +33 -0
- package/dist/core/fields.js +129 -0
- package/dist/core/hierarchy.js +30 -0
- package/dist/core/icons.js +181 -0
- package/dist/core/image-crop.js +166 -0
- package/dist/core/item.js +49 -0
- package/dist/core/lease.js +31 -0
- package/dist/core/modules.js +318 -0
- package/dist/core/notify/planner.js +117 -0
- package/dist/core/notify/signals.js +66 -0
- package/dist/core/notify/text.js +60 -0
- package/dist/core/path-key.js +22 -0
- package/dist/core/placement.js +161 -0
- package/dist/core/preset-labels.js +66 -0
- package/dist/core/preset-notes.js +109 -0
- package/dist/core/preset.js +541 -0
- package/dist/core/profile.js +55 -0
- package/dist/core/project-id.js +20 -0
- package/dist/core/refusal.js +1 -0
- package/dist/core/relations.js +208 -0
- package/dist/core/repo.js +54 -0
- package/dist/core/samples.js +161 -0
- package/dist/core/search-words.js +68 -0
- package/dist/core/test-report.js +120 -0
- package/dist/core/time.js +8 -0
- package/dist/core/validation.js +60 -0
- package/dist/core/views.js +171 -0
- package/dist/core/workflow.js +51 -0
- package/dist/mcp/commands.js +101 -0
- package/dist/mcp/server.js +239 -0
- package/dist/mcp/words.js +95 -0
- package/dist/server/boards.js +232 -0
- package/dist/server/changes.js +42 -0
- package/dist/server/diff-tip.js +83 -0
- package/dist/server/drift.js +87 -0
- package/dist/server/errors.js +87 -0
- package/dist/server/evidence.js +82 -0
- package/dist/server/hosts.js +6 -0
- package/dist/server/hub.js +98 -0
- package/dist/server/lan-access.js +62 -0
- package/dist/server/lan.js +164 -0
- package/dist/server/listen.js +70 -0
- package/dist/server/notifier.js +156 -0
- package/dist/server/notify-api.js +151 -0
- package/dist/server/pairing.js +124 -0
- package/dist/server/projects.js +191 -0
- package/dist/server/push.js +199 -0
- package/dist/server/server.js +960 -0
- package/dist/server/session.js +43 -0
- package/dist/server/stream.js +36 -0
- package/dist/server/test-push.js +38 -0
- package/dist/server/token.js +37 -0
- package/dist/server/transports.js +54 -0
- package/dist/server/ui.js +44 -0
- package/dist/server/writes.js +361 -0
- package/dist/server/wrong-address.js +36 -0
- package/dist/store/boards.js +111 -0
- package/dist/store/database.js +45 -0
- package/dist/store/machine.js +77 -0
- package/dist/store/migrations.js +493 -0
- package/dist/store/queries.js +585 -0
- package/dist/store/registry.js +72 -0
- package/package.json +73 -4
- package/presets/architecture/playbook.md +69 -0
- package/presets/architecture/preset.yaml +80 -0
- package/presets/architecture/samples.yaml +23 -0
- package/presets/bug-triage/playbook.md +129 -0
- package/presets/bug-triage/preset.yaml +127 -0
- package/presets/bug-triage/samples/wall-slide-after.png +0 -0
- package/presets/bug-triage/samples/wall-slide-before.png +0 -0
- package/presets/bug-triage/samples.yaml +72 -0
- package/presets/change/playbook.md +115 -0
- package/presets/change/preset.yaml +141 -0
- package/presets/change/samples.yaml +62 -0
- package/presets/review/playbook.md +51 -0
- package/presets/review/preset.yaml +62 -0
- package/presets/review/samples.yaml +27 -0
- package/presets/tasks/playbook.md +78 -0
- package/presets/tasks/preset.yaml +61 -0
- package/presets/tasks/samples.yaml +46 -0
- package/schemas/board.schema.json +764 -0
- package/ui/dist/THIRD_PARTY_NOTICES.md +114 -0
- package/ui/dist/assets/dm-mono-latin-400-normal--0xN8mdc.woff +0 -0
- package/ui/dist/assets/dm-mono-latin-400-normal-4GdczIuU.woff2 +0 -0
- package/ui/dist/assets/dm-mono-latin-500-normal-CN8Miw6E.woff +0 -0
- package/ui/dist/assets/dm-mono-latin-500-normal-DRMDZjhP.woff2 +0 -0
- package/ui/dist/assets/dm-mono-latin-ext-400-normal-1aZr6b2b.woff +0 -0
- package/ui/dist/assets/dm-mono-latin-ext-400-normal-C2zvOubV.woff2 +0 -0
- package/ui/dist/assets/dm-mono-latin-ext-500-normal-BtRyHRi6.woff2 +0 -0
- package/ui/dist/assets/dm-mono-latin-ext-500-normal-Dw3M13d8.woff +0 -0
- package/ui/dist/assets/index-C3OzJope.js +103 -0
- package/ui/dist/assets/index-COdEjckQ.css +1 -0
- package/ui/dist/assets/newsreader-latin-ext-opsz-italic-CSPGnFdO.woff2 +0 -0
- package/ui/dist/assets/newsreader-latin-ext-opsz-normal-BQn1nviT.woff2 +0 -0
- package/ui/dist/assets/newsreader-latin-opsz-italic-kJKFiXvB.woff2 +0 -0
- package/ui/dist/assets/newsreader-latin-opsz-normal-s-izfB6B.woff2 +0 -0
- package/ui/dist/assets/newsreader-vietnamese-opsz-italic-DTr-ymY4.woff2 +0 -0
- package/ui/dist/assets/newsreader-vietnamese-opsz-normal-BjhtXyW2.woff2 +0 -0
- package/ui/dist/assets/pdf-YwugTw7Y.js +54 -0
- package/ui/dist/assets/pdf-engine-CkBopwck.js +1 -0
- package/ui/dist/assets/pdf-rELvHkft.js +56 -0
- package/ui/dist/assets/pdf.worker.min-B5Yc7dP4.mjs +27 -0
- package/ui/dist/assets/pdf.worker.min-B7U8ptvh.js +1 -0
- package/ui/dist/assets/pdf.worker.min-CIqJB0yW.mjs +28 -0
- package/ui/dist/assets/pdf.worker.min-UqOn5EDC.js +1 -0
- package/ui/dist/assets/schibsted-grotesk-latin-ext-wght-normal-hsMS0n0O.woff2 +0 -0
- package/ui/dist/assets/schibsted-grotesk-latin-wght-normal-Bb8VGrTG.woff2 +0 -0
- package/ui/dist/icons/apple-touch-icon.png +0 -0
- package/ui/dist/icons/otea-192.png +0 -0
- package/ui/dist/icons/otea-512.png +0 -0
- package/ui/dist/icons/otea-badge.png +0 -0
- package/ui/dist/icons/otea-maskable-512.png +0 -0
- package/ui/dist/index.html +25 -0
- package/ui/dist/manifest.webmanifest +24 -0
- package/ui/dist/otea-idle.svg +5 -0
- package/ui/dist/otea-working.svg +5 -0
- package/ui/dist/otea-yours-working.svg +5 -0
- package/ui/dist/otea-yours.svg +5 -0
- package/ui/dist/sw.js +1 -0
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import { OteaError } from '../errors.js';
|
|
2
|
+
import { readPreset } from '../preset.js';
|
|
3
|
+
import { backTarget, backWaysOf, isLandStep, stateOf, waysOf } from './engine.js';
|
|
4
|
+
import { DONE, DROPPED, guardedBranch, INITIAL_KINDS, isEvidenceKind, LEVELS, MOTIVE, PARTS, partOf, ROUNDS, STEP, stepById, TITLE, usedRefs, } from './model.js';
|
|
5
|
+
import { stateName } from './reading.js';
|
|
6
|
+
import { defaultZone, LANGS } from './templates.js';
|
|
7
|
+
// A published board version compiled into the preset the rest of Otea already reads (items, moves,
|
|
8
|
+
// leases, lanes, the item page): one type, `item`; a workflow state per step phase (stateOf); a
|
|
9
|
+
// field per field part and an evidence module per evidence part, all keyed by their hidden ids.
|
|
10
|
+
// The step engine stays the authority on handoffs; the compiled workflow only lets through the
|
|
11
|
+
// moves the engine can make, so no older path (otea move) can walk around it.
|
|
12
|
+
export const BOARD_TYPE = 'item';
|
|
13
|
+
const FIELD_MODULE = {
|
|
14
|
+
text: 'text',
|
|
15
|
+
long: 'markdown',
|
|
16
|
+
check: 'text',
|
|
17
|
+
choice: 'enum',
|
|
18
|
+
multi: 'text',
|
|
19
|
+
level: 'severity',
|
|
20
|
+
number: 'text',
|
|
21
|
+
date: 'text',
|
|
22
|
+
yesno: 'enum',
|
|
23
|
+
url: 'text',
|
|
24
|
+
branch: 'text',
|
|
25
|
+
};
|
|
26
|
+
// Evidence kinds and the module that draws them; audio and other files are offered by files.
|
|
27
|
+
const EVIDENCE_MODULE = {
|
|
28
|
+
images: 'images',
|
|
29
|
+
video: 'recording',
|
|
30
|
+
code: 'diff',
|
|
31
|
+
log: 'log',
|
|
32
|
+
diagram: 'diagram',
|
|
33
|
+
audio: 'files',
|
|
34
|
+
file: 'files',
|
|
35
|
+
};
|
|
36
|
+
// An audio part is a voice note: it takes audio only, while a file part takes any file.
|
|
37
|
+
const ACCEPTS = {
|
|
38
|
+
audio: ['audio'],
|
|
39
|
+
};
|
|
40
|
+
const VARIANT = {
|
|
41
|
+
gallery: 'gallery',
|
|
42
|
+
one: 'single',
|
|
43
|
+
ba: 'compare',
|
|
44
|
+
ab: 'compare',
|
|
45
|
+
strip: 'frames',
|
|
46
|
+
player: 'player',
|
|
47
|
+
};
|
|
48
|
+
const WORDS = {
|
|
49
|
+
en: {
|
|
50
|
+
done: 'Done',
|
|
51
|
+
dropped: 'Dropped',
|
|
52
|
+
yes: 'Yes',
|
|
53
|
+
no: 'No',
|
|
54
|
+
low: 'low',
|
|
55
|
+
medium: 'medium',
|
|
56
|
+
high: 'high',
|
|
57
|
+
critical: 'critical',
|
|
58
|
+
},
|
|
59
|
+
es: {
|
|
60
|
+
done: 'Hecho',
|
|
61
|
+
dropped: 'Descartado',
|
|
62
|
+
yes: 'Sí',
|
|
63
|
+
no: 'No',
|
|
64
|
+
low: 'baja',
|
|
65
|
+
medium: 'media',
|
|
66
|
+
high: 'alta',
|
|
67
|
+
critical: 'crítica',
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
function fieldOf(part, required) {
|
|
71
|
+
let module = FIELD_MODULE[part.kind] ?? 'text';
|
|
72
|
+
const values = part.kind === 'yesno'
|
|
73
|
+
? ['yes', 'no']
|
|
74
|
+
: part.kind === 'choice'
|
|
75
|
+
? part.options.map(({ id }) => id)
|
|
76
|
+
: undefined;
|
|
77
|
+
if (module === 'enum' && (values ?? []).length === 0)
|
|
78
|
+
module = 'text';
|
|
79
|
+
return {
|
|
80
|
+
module,
|
|
81
|
+
...(required ? { required: 'create' } : {}),
|
|
82
|
+
...(module === 'enum' && values ? { values } : {}),
|
|
83
|
+
...(part.initial !== undefined &&
|
|
84
|
+
((INITIAL_KINDS.includes(part.kind) && module !== 'text') || part.kind === 'branch')
|
|
85
|
+
? { default: part.initial }
|
|
86
|
+
: {}),
|
|
87
|
+
label: part.name,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function entryOf(part) {
|
|
91
|
+
if (!isEvidenceKind(part.kind)) {
|
|
92
|
+
const module = FIELD_MODULE[part.kind] ?? 'text';
|
|
93
|
+
const enumless = module === 'enum' && part.kind === 'choice' && part.options.length === 0;
|
|
94
|
+
return {
|
|
95
|
+
module: (enumless ? 'text' : module),
|
|
96
|
+
field: part.id,
|
|
97
|
+
label: part.name,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
const module = EVIDENCE_MODULE[part.kind];
|
|
101
|
+
if (!module)
|
|
102
|
+
return undefined;
|
|
103
|
+
const variant = part.show ? VARIANT[part.show] : undefined;
|
|
104
|
+
const accepts = ACCEPTS[part.kind];
|
|
105
|
+
return {
|
|
106
|
+
module: module,
|
|
107
|
+
id: part.id,
|
|
108
|
+
...(variant ? { variant } : {}),
|
|
109
|
+
...(part.show === 'ab' ? { blind: true } : {}),
|
|
110
|
+
label: part.name,
|
|
111
|
+
...(accepts ? { accepts: [...accepts] } : {}),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
function phasesOf(step) {
|
|
115
|
+
const doing = {
|
|
116
|
+
state: stateOf({ step: step.id, phase: 'doing' }),
|
|
117
|
+
turn: step.doer === 'you' ? 'human' : 'agent',
|
|
118
|
+
label: () => step.name,
|
|
119
|
+
};
|
|
120
|
+
if (step.reviewer === 'none')
|
|
121
|
+
return [doing];
|
|
122
|
+
const review = {
|
|
123
|
+
state: stateOf({ step: step.id, phase: 'review' }),
|
|
124
|
+
turn: step.reviewer === 'you' ? 'human' : 'agent',
|
|
125
|
+
// A board is its steps: a review reads as the step it reviews, whose turn says who acts.
|
|
126
|
+
label: () => step.name,
|
|
127
|
+
};
|
|
128
|
+
return [doing, review];
|
|
129
|
+
}
|
|
130
|
+
// Only the person says Hecho, and only on the item page: an agent cannot relay it.
|
|
131
|
+
function closingByYou(transition) {
|
|
132
|
+
return transition.by === 'human' && transition.to === DONE
|
|
133
|
+
? { ...transition, by: 'human-ui' }
|
|
134
|
+
: transition;
|
|
135
|
+
}
|
|
136
|
+
function transitionsOf(def) {
|
|
137
|
+
const out = [];
|
|
138
|
+
const target = (way) => (way === DONE ? DONE : stateOf({ step: way, phase: 'doing' }));
|
|
139
|
+
for (const step of def.steps) {
|
|
140
|
+
const doing = stateOf({ step: step.id, phase: 'doing' });
|
|
141
|
+
const doer = step.doer === 'you' ? 'human' : 'agent';
|
|
142
|
+
const ways = waysOf(def, step.id).map(target);
|
|
143
|
+
const back = stateOf({ step: backTarget(def, step.id), phase: 'doing' });
|
|
144
|
+
// A handoff that carries the round's note says it as the move's reason.
|
|
145
|
+
const note = step.note.req === 'always' ? { reason: 'required' } : {};
|
|
146
|
+
for (const earlier of backWaysOf(def, step.id))
|
|
147
|
+
out.push({ from: doing, to: target(earlier), by: doer, reason: 'required' });
|
|
148
|
+
if (step.reviewer === 'none') {
|
|
149
|
+
const land = isLandStep(def, step.id) ? { land: true } : {};
|
|
150
|
+
for (const to of ways)
|
|
151
|
+
out.push({ from: doing, to, by: doer, ...note, ...(to === DONE ? land : {}) });
|
|
152
|
+
// The person may send an approved item back from its land step, before it lands, to the
|
|
153
|
+
// step they approved, saying why.
|
|
154
|
+
if (land.land)
|
|
155
|
+
for (const into of def.steps)
|
|
156
|
+
if (into.id !== step.id && waysOf(def, into.id).includes(step.id))
|
|
157
|
+
out.push({
|
|
158
|
+
from: doing,
|
|
159
|
+
to: stateOf({ step: into.id, phase: 'doing' }),
|
|
160
|
+
by: 'human',
|
|
161
|
+
reason: 'required',
|
|
162
|
+
});
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
const review = stateOf({ step: step.id, phase: 'review' });
|
|
166
|
+
const reviewer = step.reviewer === 'you' ? 'human' : 'agent';
|
|
167
|
+
out.push({ from: doing, to: review, by: doer, ...note });
|
|
168
|
+
for (const to of ways)
|
|
169
|
+
out.push({ from: review, to, by: reviewer });
|
|
170
|
+
out.push({ from: review, to: back, by: reviewer, reason: 'required' });
|
|
171
|
+
}
|
|
172
|
+
return out.map(closingByYou);
|
|
173
|
+
}
|
|
174
|
+
// The published list: a list or a table (grid) whose columns are the list row, grouped by a field,
|
|
175
|
+
// or by the step (state) when it groups by Paso or Motivo.
|
|
176
|
+
function viewOf(def, row) {
|
|
177
|
+
const group = def.list.group;
|
|
178
|
+
const byState = group === STEP || group === MOTIVE;
|
|
179
|
+
const groupBy = group === undefined ? undefined : byState ? 'state' : group;
|
|
180
|
+
const fields = row.flatMap(({ field }) => (field && field !== groupBy ? [field] : []));
|
|
181
|
+
return {
|
|
182
|
+
kind: def.list.as === 'table' ? 'grid' : 'list',
|
|
183
|
+
...(groupBy ? { group_by: groupBy } : {}),
|
|
184
|
+
...(def.list.as === 'table'
|
|
185
|
+
? { columns: ['id', 'title', ...fields, 'state', 'who', 'age'] }
|
|
186
|
+
: {}),
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
function zoneOf(def, part) {
|
|
190
|
+
return def.layout[part.id] ?? defaultZone(part.kind);
|
|
191
|
+
}
|
|
192
|
+
// The name of the part (fields.<id>) or step (workflow.states.<id>__…) a preset problem is about.
|
|
193
|
+
function uncompiled(def, problems) {
|
|
194
|
+
for (const problem of problems) {
|
|
195
|
+
const field = /^fields\.([^:.\s]+)/.exec(problem)?.[1];
|
|
196
|
+
const part = field === undefined ? undefined : def.parts[field];
|
|
197
|
+
if (part)
|
|
198
|
+
return part.name;
|
|
199
|
+
const state = /^workflow\.states\.([^:.\s]+)/.exec(problem)?.[1];
|
|
200
|
+
const step = def.steps.find(({ id }) => state?.startsWith(id));
|
|
201
|
+
if (step)
|
|
202
|
+
return step.name;
|
|
203
|
+
}
|
|
204
|
+
return undefined;
|
|
205
|
+
}
|
|
206
|
+
// Compiles a version of a board: `id` names the preset (the board's hidden id), `version` its
|
|
207
|
+
// version. Throws when the board cannot be published: problemsOf says why in words first.
|
|
208
|
+
export function compileBoard(id, version, def) {
|
|
209
|
+
const first = def.steps[0];
|
|
210
|
+
if (!first)
|
|
211
|
+
throw new OteaError('invalid_board', `Board ${def.name} has no steps`);
|
|
212
|
+
const used = usedRefs(def);
|
|
213
|
+
// Layout order: the parts Acomodar placed, in its order, then the rest in board order.
|
|
214
|
+
const ordered = [
|
|
215
|
+
...Object.keys(def.layout),
|
|
216
|
+
...Object.keys(def.parts).filter((ref) => !(ref in def.layout)),
|
|
217
|
+
]
|
|
218
|
+
.filter((ref) => used.has(ref))
|
|
219
|
+
.map((ref) => def.parts[ref])
|
|
220
|
+
.filter((part) => part !== undefined);
|
|
221
|
+
const required = new Set(def.form.filter((entry) => entry.required).map(({ ref }) => ref));
|
|
222
|
+
const fields = {
|
|
223
|
+
title: { module: 'text', required: 'create', label: def.title },
|
|
224
|
+
};
|
|
225
|
+
for (const part of ordered) {
|
|
226
|
+
if (!isEvidenceKind(part.kind))
|
|
227
|
+
fields[part.id] = fieldOf(part, required.has(part.id));
|
|
228
|
+
}
|
|
229
|
+
const phases = def.steps.flatMap(phasesOf);
|
|
230
|
+
const states = {};
|
|
231
|
+
for (const phase of phases)
|
|
232
|
+
states[phase.state] = { turn: phase.turn };
|
|
233
|
+
states[DONE] = { turn: 'none', closes: 'done' };
|
|
234
|
+
// Plain Descartado stays besides the motives: it holds what was discarded before them.
|
|
235
|
+
const drops = [
|
|
236
|
+
DROPPED,
|
|
237
|
+
...def.drop.motives.map(({ id: motive }) => stateOf({ closed: DROPPED, motive })),
|
|
238
|
+
];
|
|
239
|
+
for (const state of drops)
|
|
240
|
+
states[state] = { turn: 'none', closes: 'discarded' };
|
|
241
|
+
const dropper = def.drop.by === 'page' ? 'human-ui' : 'human';
|
|
242
|
+
const agentDrops = def.steps.flatMap((step) => step.doerMayDrop && step.doer !== 'you'
|
|
243
|
+
? drops.map((to) => ({
|
|
244
|
+
from: stateOf({ step: step.id, phase: 'doing' }),
|
|
245
|
+
to,
|
|
246
|
+
by: 'agent',
|
|
247
|
+
reason: 'required',
|
|
248
|
+
}))
|
|
249
|
+
: []);
|
|
250
|
+
const transitions = [
|
|
251
|
+
...transitionsOf(def),
|
|
252
|
+
...phases.flatMap(({ state }) => drops.map((to) => ({ from: state, to, by: dropper, reason: 'required' }))),
|
|
253
|
+
...agentDrops,
|
|
254
|
+
];
|
|
255
|
+
const branch = guardedBranch(def);
|
|
256
|
+
const pushes = (branch?.guard.push ?? [])
|
|
257
|
+
.filter((stepId) => stepById(def, stepId))
|
|
258
|
+
.map((stepId) => stateOf({ step: stepId, phase: 'doing' }));
|
|
259
|
+
const gates = branch
|
|
260
|
+
? { ...(pushes.length > 0 ? { push: pushes } : {}), merge: [DONE] }
|
|
261
|
+
: undefined;
|
|
262
|
+
// The rounds and the parts take a place only where Acomodar put them (the parts only on a board
|
|
263
|
+
// that divides), first in their column: on top they read in the main column, hidden nowhere.
|
|
264
|
+
const places = {
|
|
265
|
+
[ROUNDS]: { module: 'rounds' },
|
|
266
|
+
...(def.split ? { [PARTS]: { module: 'children' } } : {}),
|
|
267
|
+
};
|
|
268
|
+
const placed = (wanted) => Object.entries(def.layout).flatMap(([ref, at]) => {
|
|
269
|
+
const entry = places[ref];
|
|
270
|
+
const column = at === 'top' ? 'main' : at;
|
|
271
|
+
return entry && column === wanted ? [entry] : [];
|
|
272
|
+
});
|
|
273
|
+
const zone = (wanted) => ordered.filter((part) => zoneOf(def, part) === wanted).flatMap((part) => entryOf(part) ?? []);
|
|
274
|
+
const fieldEntries = (entries) => entries.filter((entry) => entry.field);
|
|
275
|
+
const evidenceEntries = (entries) => entries.filter((entry) => entry.id);
|
|
276
|
+
const top = zone('top');
|
|
277
|
+
const layout = {
|
|
278
|
+
header: fieldEntries(top),
|
|
279
|
+
evidence: [],
|
|
280
|
+
body: [...placed('main'), ...evidenceEntries(top), ...zone('main')],
|
|
281
|
+
side: [...placed('side'), ...zone('side'), { module: 'relations' }],
|
|
282
|
+
// A column of a part nothing uses any more has no field to read.
|
|
283
|
+
row: def.row.flatMap((ref) => {
|
|
284
|
+
if (!used.has(ref))
|
|
285
|
+
return [];
|
|
286
|
+
const part = partOf(def, ref);
|
|
287
|
+
const entry = part && ref !== TITLE ? entryOf(part) : undefined;
|
|
288
|
+
return entry?.field ? [entry] : [];
|
|
289
|
+
}),
|
|
290
|
+
// Hidden evidence still needs a module to be attached to; the phone slot carries it until the
|
|
291
|
+
// phone layout is designed.
|
|
292
|
+
phone: evidenceEntries(zone('hidden')),
|
|
293
|
+
intake: [
|
|
294
|
+
{ module: 'text', field: TITLE, label: def.title },
|
|
295
|
+
...def.form.flatMap(({ ref }) => {
|
|
296
|
+
const part = def.parts[ref];
|
|
297
|
+
const entry = part ? entryOf(part) : undefined;
|
|
298
|
+
return entry?.field ? [entry] : [];
|
|
299
|
+
}),
|
|
300
|
+
],
|
|
301
|
+
};
|
|
302
|
+
const labels = Object.fromEntries(LANGS.map((lang) => [
|
|
303
|
+
lang,
|
|
304
|
+
{
|
|
305
|
+
name: def.name,
|
|
306
|
+
types: { [BOARD_TYPE]: def.item },
|
|
307
|
+
states: {
|
|
308
|
+
...Object.fromEntries(phases.map((phase) => [phase.state, phase.label(lang)])),
|
|
309
|
+
[DONE]: WORDS[lang].done,
|
|
310
|
+
[DROPPED]: WORDS[lang].dropped,
|
|
311
|
+
// A discard with a motive reads as its motive (Duplicado).
|
|
312
|
+
...Object.fromEntries(def.drop.motives.map(({ id: motive, name }) => [
|
|
313
|
+
stateOf({ closed: DROPPED, motive }),
|
|
314
|
+
name,
|
|
315
|
+
])),
|
|
316
|
+
},
|
|
317
|
+
fields: Object.fromEntries(Object.entries(fields).map(([key, field]) => [key, field.label])),
|
|
318
|
+
values: Object.fromEntries(ordered
|
|
319
|
+
// A checklist and a multi choice hold their options' ids too (a JSON list).
|
|
320
|
+
.filter((part) => fields[part.id]?.module === 'enum' ||
|
|
321
|
+
part.kind === 'level' ||
|
|
322
|
+
part.kind === 'check' ||
|
|
323
|
+
part.kind === 'multi')
|
|
324
|
+
.filter((part) => fields[part.id] !== undefined)
|
|
325
|
+
.map((part) => [
|
|
326
|
+
part.id,
|
|
327
|
+
part.kind === 'yesno'
|
|
328
|
+
? { yes: WORDS[lang].yes, no: WORDS[lang].no }
|
|
329
|
+
: part.kind === 'level'
|
|
330
|
+
? Object.fromEntries(LEVELS.map((level) => [level, WORDS[lang][level] ?? level]))
|
|
331
|
+
: Object.fromEntries(part.options.map((choice) => [choice.id, choice.name])),
|
|
332
|
+
])),
|
|
333
|
+
},
|
|
334
|
+
]));
|
|
335
|
+
const raw = {
|
|
336
|
+
preset: id,
|
|
337
|
+
preset_version: version,
|
|
338
|
+
icon: def.icon,
|
|
339
|
+
fields,
|
|
340
|
+
workflow: {
|
|
341
|
+
initial: stateOf({ step: first.id, phase: 'doing' }),
|
|
342
|
+
states,
|
|
343
|
+
transitions,
|
|
344
|
+
...(gates ? { gates } : {}),
|
|
345
|
+
},
|
|
346
|
+
types: { [BOARD_TYPE]: { label: def.item, icon: def.icon, layout } },
|
|
347
|
+
view: viewOf(def, layout.row),
|
|
348
|
+
labels,
|
|
349
|
+
};
|
|
350
|
+
const reading = readPreset(JSON.stringify(raw));
|
|
351
|
+
if (!reading.ok) {
|
|
352
|
+
// Said as the part or step it is about, for Studio to word: never the preset's own words.
|
|
353
|
+
const named = uncompiled(def, reading.problems);
|
|
354
|
+
throw new OteaError('invalid_board', `Board ${def.name} does not compile${named ? `: "${named}" has an id Otea cannot use` : ''}: ${reading.problems.join('; ')}`, { kind: 'draft_uncompilable', ...(named ? { part: named } : {}) });
|
|
355
|
+
}
|
|
356
|
+
// Its states are hidden ids: each reads as its step (Refinar (in review)), in what Otea says.
|
|
357
|
+
const { preset } = reading;
|
|
358
|
+
for (const workflow of [preset.workflow, ...preset.types.map((type) => type.workflow)])
|
|
359
|
+
for (const state of workflow.states)
|
|
360
|
+
state.label = stateName(def, state.name);
|
|
361
|
+
return preset;
|
|
362
|
+
}
|