@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,146 @@
|
|
|
1
|
+
import { isClosed, positionOf, roundsOf, stateOf } from './engine.js';
|
|
2
|
+
import { stepIndex } from './model.js';
|
|
3
|
+
// A move the person took back while its toast was up leaves two events: the move and its undo
|
|
4
|
+
// (which names it). Both are dropped, as if the move never happened: an approval taken back starts
|
|
5
|
+
// no round, a send-back taken back leaves no note.
|
|
6
|
+
export function withoutUndone(events) {
|
|
7
|
+
const gone = new Set();
|
|
8
|
+
for (const e of events)
|
|
9
|
+
if (typeof e.data.undoes === 'number')
|
|
10
|
+
gone.add(e.data.undoes).add(e.id);
|
|
11
|
+
return gone.size === 0 ? events : events.filter((e) => !gone.has(e.id));
|
|
12
|
+
}
|
|
13
|
+
// The agent changed its handoff's note while the review waited (P3C-11): the note of the move
|
|
14
|
+
// before it.
|
|
15
|
+
export const HANDOFF_AMENDED = 'handoff_amended';
|
|
16
|
+
// Moves the board made itself, not the work: a publish or a restore placing the item, and the
|
|
17
|
+
// reading of a preset collection as a board.
|
|
18
|
+
const BOARD_MOVES = new Set(['publish', 'restore', 'migrate']);
|
|
19
|
+
const MIGRATE = 'migrate';
|
|
20
|
+
const words = (value) => typeof value === 'string' && value.trim() !== '';
|
|
21
|
+
function saidOf(data, by) {
|
|
22
|
+
const text = [data.note, data.reason, data.quote].find(words);
|
|
23
|
+
return text === undefined ? { by } : { by, text };
|
|
24
|
+
}
|
|
25
|
+
// The item's moves as the engine replays them, undone moves left out. A collection read from a
|
|
26
|
+
// preset starts its history at that reading: the states before it belong to the preset's workflow,
|
|
27
|
+
// not to the board's steps. A reading that carries a note (Falta información read as Completar)
|
|
28
|
+
// starts that step's next round, with the person's question as its note. `fallback`: where and
|
|
29
|
+
// when the item started when its history does not say.
|
|
30
|
+
export function historyOf(events, fallback) {
|
|
31
|
+
const live = withoutUndone(events);
|
|
32
|
+
const created = live.find(({ type }) => type === 'created');
|
|
33
|
+
const moved = live.filter(({ type, data }) => type === 'transitioned' && words(data.from) && words(data.to));
|
|
34
|
+
const migrated = moved.findLastIndex(({ data }) => data.reason === MIGRATE);
|
|
35
|
+
const reading = moved[migrated];
|
|
36
|
+
const out = {
|
|
37
|
+
initial: fallback.initial,
|
|
38
|
+
createdAt: fallback.createdAt,
|
|
39
|
+
moves: [],
|
|
40
|
+
said: [],
|
|
41
|
+
notes: [],
|
|
42
|
+
};
|
|
43
|
+
if (reading) {
|
|
44
|
+
out.initial = String(reading.data.to);
|
|
45
|
+
out.createdAt = reading.at;
|
|
46
|
+
out.readAt = reading.at;
|
|
47
|
+
const to = positionOf(out.initial);
|
|
48
|
+
const asked = words(reading.data.note) ? reading.data.note : undefined;
|
|
49
|
+
if (asked !== undefined && !isClosed(to)) {
|
|
50
|
+
out.moves.push({
|
|
51
|
+
from: stateOf({ step: to.step, phase: 'review' }),
|
|
52
|
+
to: to.step,
|
|
53
|
+
at: reading.at,
|
|
54
|
+
});
|
|
55
|
+
out.said.push({ by: reading.actor, text: asked, reading: true });
|
|
56
|
+
const by = moved
|
|
57
|
+
.slice(0, migrated)
|
|
58
|
+
.findLast(({ data }) => String(data.to) === String(reading.data.from))?.actor;
|
|
59
|
+
out.notes.push({
|
|
60
|
+
step: to.step,
|
|
61
|
+
before: 1,
|
|
62
|
+
note: asked,
|
|
63
|
+
at: reading.at,
|
|
64
|
+
by: by ?? reading.actor,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else if (typeof created?.data.state === 'string') {
|
|
69
|
+
out.initial = created.data.state;
|
|
70
|
+
}
|
|
71
|
+
for (const { data, at, actor } of moved.slice(migrated + 1)) {
|
|
72
|
+
const from = positionOf(String(data.from));
|
|
73
|
+
if (words(data.note) && !isClosed(from))
|
|
74
|
+
out.notes.push({ step: from.step, before: out.moves.length, note: data.note, at, by: actor });
|
|
75
|
+
out.moves.push({
|
|
76
|
+
from: String(data.from),
|
|
77
|
+
to: String(data.to),
|
|
78
|
+
at,
|
|
79
|
+
...(BOARD_MOVES.has(String(data.reason)) ? { quiet: true } : {}),
|
|
80
|
+
});
|
|
81
|
+
out.said.push(saidOf(data, actor));
|
|
82
|
+
}
|
|
83
|
+
// An amended note replaces the note of the handoff it follows.
|
|
84
|
+
const moves = moved.slice(migrated + 1);
|
|
85
|
+
for (const amend of live) {
|
|
86
|
+
if (amend.type !== HANDOFF_AMENDED || !words(amend.data.note))
|
|
87
|
+
continue;
|
|
88
|
+
const index = moves.findLastIndex(({ id }) => id < amend.id) + (out.moves.length - moves.length);
|
|
89
|
+
const said = out.said[index];
|
|
90
|
+
if (index < 0 || !said)
|
|
91
|
+
continue;
|
|
92
|
+
out.said[index] = { ...said, text: amend.data.note };
|
|
93
|
+
const kept = out.notes.find(({ before }) => before === index);
|
|
94
|
+
if (kept)
|
|
95
|
+
kept.note = amend.data.note;
|
|
96
|
+
}
|
|
97
|
+
return out;
|
|
98
|
+
}
|
|
99
|
+
// The step's round after the first `count` moves, as the engine counts it.
|
|
100
|
+
export function roundAfter(def, history, step, count) {
|
|
101
|
+
const { rounds } = roundsOf(def, history.initial, history.createdAt, history.moves.slice(0, count));
|
|
102
|
+
return rounds[step] ?? 1;
|
|
103
|
+
}
|
|
104
|
+
// Each handoff's note with the round of its step it closed, as the engine counts it.
|
|
105
|
+
export function handoffNotes(def, history) {
|
|
106
|
+
return history.notes.map(({ step, before, note, at, by }) => ({
|
|
107
|
+
step,
|
|
108
|
+
round: roundAfter(def, history, step, before),
|
|
109
|
+
note,
|
|
110
|
+
at,
|
|
111
|
+
by,
|
|
112
|
+
}));
|
|
113
|
+
}
|
|
114
|
+
// The rounds of one step, oldest first, each started by entering the step as the engine counts it.
|
|
115
|
+
// A round started by a send-back (from its review or a later step, or the question a reading
|
|
116
|
+
// carried) keeps what that move said; one started by moving forward says nothing here.
|
|
117
|
+
export function roundsOfStep(def, history, step) {
|
|
118
|
+
const out = [];
|
|
119
|
+
const index = stepIndex(def, step);
|
|
120
|
+
let before = 0;
|
|
121
|
+
for (let count = 0; count <= history.moves.length; count += 1) {
|
|
122
|
+
const { rounds } = roundsOf(def, history.initial, history.createdAt, history.moves.slice(0, count));
|
|
123
|
+
const now = rounds[step] ?? 0;
|
|
124
|
+
if (now > before) {
|
|
125
|
+
const move = count === 0 ? undefined : history.moves[count - 1];
|
|
126
|
+
const said = count === 0 ? undefined : history.said[count - 1];
|
|
127
|
+
const source = move ? positionOf(move.from) : undefined;
|
|
128
|
+
const live = move !== undefined && !move.quiet && source !== undefined;
|
|
129
|
+
const reopened = live && isClosed(source);
|
|
130
|
+
const back = live &&
|
|
131
|
+
(reopened ||
|
|
132
|
+
(!isClosed(source) &&
|
|
133
|
+
((source.step === step && source.phase !== 'doing') ||
|
|
134
|
+
stepIndex(def, source.step) > index)));
|
|
135
|
+
out.push({
|
|
136
|
+
round: now,
|
|
137
|
+
at: move?.at ?? history.createdAt,
|
|
138
|
+
...(back && said?.text
|
|
139
|
+
? { back: { said, at: move.at, ...(reopened ? { reopened: true } : {}) } }
|
|
140
|
+
: {}),
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
before = now;
|
|
144
|
+
}
|
|
145
|
+
return out;
|
|
146
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { clone, DONE, isEvidenceKind, SAME, TITLE } from './model.js';
|
|
2
|
+
export const ID_PATTERN = /^[a-z][a-z0-9]*$/;
|
|
3
|
+
const ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyz';
|
|
4
|
+
export function newId(kind) {
|
|
5
|
+
const bytes = new Uint8Array(7);
|
|
6
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
7
|
+
return kind + Array.from(bytes, (byte) => ALPHABET[byte % 36]).join('');
|
|
8
|
+
}
|
|
9
|
+
// Predictable ids for tests: s1, s2, f3…
|
|
10
|
+
export function sequenceIds() {
|
|
11
|
+
let next = 0;
|
|
12
|
+
return (kind) => `${kind}${++next}`;
|
|
13
|
+
}
|
|
14
|
+
const MENTION = /@\[([a-z][a-z0-9_-]*)\]/g;
|
|
15
|
+
function rewriteMentions(text, map) {
|
|
16
|
+
return text.replace(MENTION, (whole, ref) => {
|
|
17
|
+
const next = map.get(ref);
|
|
18
|
+
return next ? `@[${next}]` : whole;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
// A copy of a definition with a new id under every step, part and choice, and every reference
|
|
22
|
+
// rewritten: what a template or a duplicate gives, so nothing stays linked to the original.
|
|
23
|
+
export function freshIds(def, ids = newId) {
|
|
24
|
+
const out = clone(def);
|
|
25
|
+
const map = new Map();
|
|
26
|
+
const choiceMaps = new Map();
|
|
27
|
+
const parts = {};
|
|
28
|
+
for (const part of Object.values(out.parts)) {
|
|
29
|
+
const id = ids(isEvidenceKind(part.kind) ? 'e' : 'f');
|
|
30
|
+
map.set(part.id, id);
|
|
31
|
+
const choices = new Map();
|
|
32
|
+
part.options = part.options.map((choice) => {
|
|
33
|
+
const fresh = ids('c');
|
|
34
|
+
choices.set(choice.id, fresh);
|
|
35
|
+
return { ...choice, id: fresh };
|
|
36
|
+
});
|
|
37
|
+
choiceMaps.set(id, choices);
|
|
38
|
+
parts[id] = { ...part, id };
|
|
39
|
+
}
|
|
40
|
+
out.parts = parts;
|
|
41
|
+
for (const step of out.steps)
|
|
42
|
+
map.set(step.id, ids('s'));
|
|
43
|
+
out.drop = {
|
|
44
|
+
...out.drop,
|
|
45
|
+
motives: out.drop.motives.map((motive) => ({ ...motive, id: ids('c') })),
|
|
46
|
+
};
|
|
47
|
+
const ref = (old) => (old === TITLE ? TITLE : (map.get(old) ?? old));
|
|
48
|
+
const target = (old) => (old === DONE || old === SAME ? old : ref(old));
|
|
49
|
+
for (const step of out.steps) {
|
|
50
|
+
step.id = ref(step.id);
|
|
51
|
+
step.ways = step.ways.map(target);
|
|
52
|
+
step.back = target(step.back);
|
|
53
|
+
step.hand = step.hand.map((hand) => {
|
|
54
|
+
const next = { ...hand, ref: ref(hand.ref) };
|
|
55
|
+
if (hand.when) {
|
|
56
|
+
const part = ref(hand.when.part);
|
|
57
|
+
const value = choiceMaps.get(part)?.get(hand.when.value) ?? hand.when.value;
|
|
58
|
+
next.when = { part, value };
|
|
59
|
+
}
|
|
60
|
+
return next;
|
|
61
|
+
});
|
|
62
|
+
step.instructions = {
|
|
63
|
+
take: rewriteMentions(step.instructions.take, map),
|
|
64
|
+
before: rewriteMentions(step.instructions.before, map),
|
|
65
|
+
review: rewriteMentions(step.instructions.review, map),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
for (const part of Object.values(out.parts)) {
|
|
69
|
+
if (part.initial !== undefined)
|
|
70
|
+
part.initial = choiceMaps.get(part.id)?.get(part.initial) ?? part.initial;
|
|
71
|
+
if (part.guard)
|
|
72
|
+
part.guard = {
|
|
73
|
+
push: part.guard.push.map(ref),
|
|
74
|
+
...(part.guard.repo === undefined ? {} : { repo: ref(part.guard.repo) }),
|
|
75
|
+
...(part.guard.base === undefined ? {} : { base: part.guard.base }),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
if (out.list.group !== undefined)
|
|
79
|
+
out.list = { ...out.list, group: ref(out.list.group) };
|
|
80
|
+
out.form = out.form.map((entry) => ({ ...entry, ref: ref(entry.ref) }));
|
|
81
|
+
out.anytime = out.anytime.map(ref);
|
|
82
|
+
out.row = out.row.map(ref);
|
|
83
|
+
out.layout = Object.fromEntries(Object.entries(out.layout).map(([key, zone]) => [ref(key), zone]));
|
|
84
|
+
out.about = rewriteMentions(out.about, map);
|
|
85
|
+
out.idle = rewriteMentions(out.idle, map);
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { SAME } from './model.js';
|
|
2
|
+
// Every split between two boards, and every board that divides into its own items.
|
|
3
|
+
export function joinsOf(boards) {
|
|
4
|
+
return boards.flatMap((parent) => {
|
|
5
|
+
const split = parent.def.split;
|
|
6
|
+
if (!split)
|
|
7
|
+
return [];
|
|
8
|
+
const child = split.board === SAME ? parent : boards.find((board) => board.id === split.board);
|
|
9
|
+
return child ? [{ parent, child, always: split.always }] : [];
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
// The join whose parts are on `childId` (another board's, never its own), when there is one.
|
|
13
|
+
export function parentJoinOf(boards, childId) {
|
|
14
|
+
return joinsOf(boards).find(({ parent, child }) => child.id === childId && parent.id !== childId);
|
|
15
|
+
}
|
|
16
|
+
// Whether an item on `parent` may take an item on `child` as one of its parts: `ok`; `parent_type`
|
|
17
|
+
// when the parent board divides into another board; `across_boards` when the parent board divides
|
|
18
|
+
// into nothing and the child is on another board (plain parents stay within a board).
|
|
19
|
+
export function partRule(parent, child) {
|
|
20
|
+
const split = parent.def.split;
|
|
21
|
+
if (!split)
|
|
22
|
+
return parent.id === child.id ? 'ok' : 'across_boards';
|
|
23
|
+
const target = split.board === SAME ? parent.id : split.board;
|
|
24
|
+
return target === child.id ? 'ok' : 'parent_type';
|
|
25
|
+
}
|
|
26
|
+
// Whether a new item on `childId` needs a parent: the board that always divides into it.
|
|
27
|
+
export function requiredParent(boards, childId) {
|
|
28
|
+
const join = parentJoinOf(boards, childId);
|
|
29
|
+
return join?.always ? join.parent : undefined;
|
|
30
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { partOf, TITLE } from './model.js';
|
|
2
|
+
// Instructions mention steps, fields and evidence as `@[id]` tokens, so a mention follows a rename.
|
|
3
|
+
// People type `@Name`; the editor stores the token and shows the name.
|
|
4
|
+
const TOKEN = /@\[([a-z][a-z0-9_-]*)\]/g;
|
|
5
|
+
// What `@` can name: the steps in order, then the parts.
|
|
6
|
+
export function mentionables(def) {
|
|
7
|
+
return [
|
|
8
|
+
...def.steps.map(({ id, name }) => ({ ref: id, name, kind: 'step' })),
|
|
9
|
+
...Object.values(def.parts).map(({ id, name }) => ({ ref: id, name, kind: 'part' })),
|
|
10
|
+
];
|
|
11
|
+
}
|
|
12
|
+
// Whether a mention's ref names a step, the title or a part of the board.
|
|
13
|
+
export function mentionNames(def, ref) {
|
|
14
|
+
return nameOf(def, ref) !== null;
|
|
15
|
+
}
|
|
16
|
+
function nameOf(def, ref) {
|
|
17
|
+
const step = def.steps.find(({ id }) => id === ref);
|
|
18
|
+
if (step)
|
|
19
|
+
return step.name;
|
|
20
|
+
if (ref === TITLE)
|
|
21
|
+
return def.title;
|
|
22
|
+
return partOf(def, ref)?.name ?? null;
|
|
23
|
+
}
|
|
24
|
+
// Typed `@Name`s as tokens, matching the longest known name first; an `@` that names nothing stays.
|
|
25
|
+
export function toMentions(def, text) {
|
|
26
|
+
const names = mentionables(def)
|
|
27
|
+
.filter(({ name }) => name.trim() !== '')
|
|
28
|
+
.sort((a, b) => b.name.length - a.name.length);
|
|
29
|
+
let out = '';
|
|
30
|
+
for (let at = 0; at < text.length; at++) {
|
|
31
|
+
const char = text[at];
|
|
32
|
+
if (char === '@' && text[at + 1] !== '[') {
|
|
33
|
+
const rest = text.slice(at + 1);
|
|
34
|
+
const hit = names.find(({ name }) => rest.startsWith(name));
|
|
35
|
+
if (hit) {
|
|
36
|
+
out += `@[${hit.ref}]`;
|
|
37
|
+
at += hit.name.length;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
out += char;
|
|
42
|
+
}
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
export function mentionSegments(def, text) {
|
|
46
|
+
const out = [];
|
|
47
|
+
let last = 0;
|
|
48
|
+
for (const match of text.matchAll(TOKEN)) {
|
|
49
|
+
const ref = match[1] ?? '';
|
|
50
|
+
if (match.index > last)
|
|
51
|
+
out.push({ text: text.slice(last, match.index) });
|
|
52
|
+
out.push({ ref, name: nameOf(def, ref) });
|
|
53
|
+
last = match.index + match[0].length;
|
|
54
|
+
}
|
|
55
|
+
if (last < text.length)
|
|
56
|
+
out.push({ text: text.slice(last) });
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
// The text as an agent reads it: every token replaced by the current name (a removed one by "…").
|
|
60
|
+
export function mentionText(def, text) {
|
|
61
|
+
return mentionSegments(def, text)
|
|
62
|
+
.map((segment) => ('text' in segment ? segment.text : (segment.name ?? '…')))
|
|
63
|
+
.join('');
|
|
64
|
+
}
|
|
65
|
+
// The refs a text mentions, for "what changes when this is removed".
|
|
66
|
+
export function mentionedRefs(text) {
|
|
67
|
+
return [...text.matchAll(TOKEN)].map((match) => match[1] ?? '');
|
|
68
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const MERGED = 'merged';
|
|
2
|
+
// The merge of a Done item, as its last `merged` event says it; undefined until one is recorded.
|
|
3
|
+
export function mergedFrom(events) {
|
|
4
|
+
const event = events.findLast(({ type }) => type === MERGED);
|
|
5
|
+
if (!event)
|
|
6
|
+
return undefined;
|
|
7
|
+
const text = (key) => {
|
|
8
|
+
const value = event.data[key];
|
|
9
|
+
return typeof value === 'string' && value !== '' ? { [key]: value } : {};
|
|
10
|
+
};
|
|
11
|
+
return {
|
|
12
|
+
at: event.at,
|
|
13
|
+
by: event.actor.name,
|
|
14
|
+
...text('branch'),
|
|
15
|
+
...text('pr'),
|
|
16
|
+
...text('commit'),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// A board as Studio edits it: a row of steps laid on the two lanes (agents above, you below), the
|
|
2
|
+
// parts each step hands off, the creation form, how the item page is arranged and the instructions
|
|
3
|
+
// agents read. Every name is free text a person typed; a hidden id sits under every board, step,
|
|
4
|
+
// part (field or evidence) and choice, so a rename never breaks history, mentions or items.
|
|
5
|
+
//
|
|
6
|
+
// This module is pure and browser-safe: the server, the CLI, MCP and the web UI import it.
|
|
7
|
+
export const FIELD_KINDS = [
|
|
8
|
+
'text',
|
|
9
|
+
'long',
|
|
10
|
+
'check',
|
|
11
|
+
'choice',
|
|
12
|
+
'multi',
|
|
13
|
+
'level',
|
|
14
|
+
'number',
|
|
15
|
+
'date',
|
|
16
|
+
'yesno',
|
|
17
|
+
'url',
|
|
18
|
+
'branch',
|
|
19
|
+
];
|
|
20
|
+
export const EVIDENCE_KINDS = [
|
|
21
|
+
'images',
|
|
22
|
+
'video',
|
|
23
|
+
'audio',
|
|
24
|
+
'code',
|
|
25
|
+
'log',
|
|
26
|
+
'diagram',
|
|
27
|
+
'file',
|
|
28
|
+
];
|
|
29
|
+
// How a piece of evidence shows on the item page, for the kinds that show in more than one way.
|
|
30
|
+
// The first is the default.
|
|
31
|
+
export const EVIDENCE_SHOWS = {
|
|
32
|
+
// ab: A and B judged blind, never named before and after (P5-4).
|
|
33
|
+
images: ['gallery', 'one', 'ba', 'ab'],
|
|
34
|
+
video: ['strip', 'player'],
|
|
35
|
+
};
|
|
36
|
+
// The fixed scale of the level kind, from least to most severe (the severity module's keys).
|
|
37
|
+
export const LEVELS = ['low', 'medium', 'high', 'critical'];
|
|
38
|
+
// The kinds a "required only when…" can read: a value the item already carries.
|
|
39
|
+
export const WHEN_KINDS = ['choice', 'multi', 'level', 'yesno'];
|
|
40
|
+
// The kinds whose values are the part's own choices.
|
|
41
|
+
export const CHOICE_KINDS = ['choice', 'multi', 'check'];
|
|
42
|
+
export function isEvidenceKind(kind) {
|
|
43
|
+
return EVIDENCE_KINDS.includes(kind);
|
|
44
|
+
}
|
|
45
|
+
export function isFieldKind(kind) {
|
|
46
|
+
return FIELD_KINDS.includes(kind);
|
|
47
|
+
}
|
|
48
|
+
// How a long text shows on the item page: as text, or as options side by side (### A · Name).
|
|
49
|
+
export const LONG_SHOWS = ['text', 'options'];
|
|
50
|
+
// The kinds a "Empieza en…" reads.
|
|
51
|
+
export const INITIAL_KINDS = ['choice', 'level', 'yesno'];
|
|
52
|
+
// The title is the one field every item has. It is not stored in `parts`: its ref is TITLE and its
|
|
53
|
+
// name is the board's `title`.
|
|
54
|
+
export const TITLE = 'title';
|
|
55
|
+
// Where a way leads: a later step's id, or DONE.
|
|
56
|
+
export const DONE = 'done';
|
|
57
|
+
export const DROPPED = 'dropped';
|
|
58
|
+
// What an Entrega waits for besides its parts: `parts`, that none of the item's parts (the items it
|
|
59
|
+
// divides into) is still open; `blockers`, that nothing open blocks it, on any board.
|
|
60
|
+
export const WAITS = ['parts', 'blockers'];
|
|
61
|
+
// `ways` are the alternatives to the default way (the next step, or DONE after the last one), and
|
|
62
|
+
// the earlier steps the doer may take the item back to ("o regresarlo a…", always with a reason,
|
|
63
|
+
// with no review, starting that step's next round). `back` is where a send-back lands: SAME (this
|
|
64
|
+
// step) or an earlier step's id.
|
|
65
|
+
// `skipWhenReady` (first step only, nobody reviews it): an item created with everything its Entrega
|
|
66
|
+
// asks for starts at the next step. `doerMayDrop`: an agent doing it may drop the item, saying why.
|
|
67
|
+
export const SAME = 'same';
|
|
68
|
+
// A step's settings that every new step starts with.
|
|
69
|
+
export function stepDefaults() {
|
|
70
|
+
return { note: { req: 'no', hint: '' }, waits: [], skipWhenReady: false, doerMayDrop: false };
|
|
71
|
+
}
|
|
72
|
+
// Where a part shows on the item page (Acomodar). The list row is `row`, an ordered list of refs.
|
|
73
|
+
export const ZONES = ['top', 'main', 'side', 'hidden'];
|
|
74
|
+
export const STEP = 'step';
|
|
75
|
+
export const MOTIVE = 'motive';
|
|
76
|
+
// Two places Acomodar lays out besides the parts: the rounds of the review, and the item's parts.
|
|
77
|
+
export const ROUNDS = 'rounds';
|
|
78
|
+
export const PARTS = 'parts';
|
|
79
|
+
export const PLACES = [ROUNDS, PARTS];
|
|
80
|
+
export const BOARD_SCHEMA = 2;
|
|
81
|
+
// A board's settings that every new board starts with.
|
|
82
|
+
export function boardDefaults() {
|
|
83
|
+
return { drop: { by: 'anyone', motives: [] }, list: { as: 'list' } };
|
|
84
|
+
}
|
|
85
|
+
export function stepById(def, id) {
|
|
86
|
+
return def.steps.find((step) => step.id === id);
|
|
87
|
+
}
|
|
88
|
+
export function stepIndex(def, id) {
|
|
89
|
+
return def.steps.findIndex((step) => step.id === id);
|
|
90
|
+
}
|
|
91
|
+
// A part by ref, the title included; undefined for a ref that names nothing.
|
|
92
|
+
export function partOf(def, ref) {
|
|
93
|
+
if (ref === TITLE)
|
|
94
|
+
return { id: TITLE, name: def.title, kind: 'text', hint: '', options: [] };
|
|
95
|
+
return def.parts[ref];
|
|
96
|
+
}
|
|
97
|
+
export function isEvidence(part) {
|
|
98
|
+
return isEvidenceKind(part.kind);
|
|
99
|
+
}
|
|
100
|
+
// The motive of a discard, by id.
|
|
101
|
+
export function motiveById(def, id) {
|
|
102
|
+
return def.drop.motives.find((motive) => motive.id === id);
|
|
103
|
+
}
|
|
104
|
+
// The protected branch field, with its guard, when the board has one. A part the board no longer
|
|
105
|
+
// uses (left in `parts` for undo and reuse, as when a step that handed it was removed or an agent's
|
|
106
|
+
// draft left it out) is no field of the board, and guards nothing (P5-R3-2): the board Studio shows
|
|
107
|
+
// with no branch field gates no push, and tells no agent it may push.
|
|
108
|
+
export function guardedBranch(def) {
|
|
109
|
+
const used = usedRefs(def);
|
|
110
|
+
return Object.values(def.parts).find((part) => part.kind === 'branch' && part.guard !== undefined && used.has(part.id));
|
|
111
|
+
}
|
|
112
|
+
// The base a board works straight on, with no branches (Código en main): its protected branch
|
|
113
|
+
// starts at its base, so a push of the base is the item's own push and nothing is merged.
|
|
114
|
+
export function workedBase(def) {
|
|
115
|
+
const part = guardedBranch(def);
|
|
116
|
+
const base = part?.guard.base;
|
|
117
|
+
return base !== undefined && part?.initial === base ? base : undefined;
|
|
118
|
+
}
|
|
119
|
+
// The default way out of a step: the next step, or DONE after the last.
|
|
120
|
+
export function defaultWay(def, stepId) {
|
|
121
|
+
const index = stepIndex(def, stepId);
|
|
122
|
+
return def.steps[index + 1]?.id ?? DONE;
|
|
123
|
+
}
|
|
124
|
+
// Every part a draft uses: on the form, in a handoff or at any time. Unused parts stay in `parts`
|
|
125
|
+
// (so undo and reuse keep them) but are not part of the board's name space.
|
|
126
|
+
export function usedRefs(def) {
|
|
127
|
+
return new Set([
|
|
128
|
+
...def.form.map(({ ref }) => ref),
|
|
129
|
+
...def.steps.flatMap(({ hand }) => hand.map(({ ref }) => ref)),
|
|
130
|
+
...def.anytime,
|
|
131
|
+
]);
|
|
132
|
+
}
|
|
133
|
+
export function clone(value) {
|
|
134
|
+
return structuredClone(value);
|
|
135
|
+
}
|