@composable-os/pack-programs 0.0.0-stage → 0.1.0-beta.7

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 (39) hide show
  1. package/LICENSE +109 -0
  2. package/dist/authoring.d.ts +47 -0
  3. package/dist/authoring.js +493 -0
  4. package/dist/blocks/programs-bank/exercise-bank.d.ts +4 -0
  5. package/dist/blocks/programs-bank/exercise-bank.js +68 -0
  6. package/dist/blocks/programs-builder/program-builder.d.ts +26 -0
  7. package/dist/blocks/programs-builder/program-builder.js +295 -0
  8. package/dist/blocks/programs-class-today/class-today.d.ts +6 -0
  9. package/dist/blocks/programs-class-today/class-today.js +15 -0
  10. package/dist/blocks/programs-coach-client/coach-client.d.ts +5 -0
  11. package/dist/blocks/programs-coach-client/coach-client.js +10 -0
  12. package/dist/blocks/programs-native-class-today/class-today-screen.d.ts +6 -0
  13. package/dist/blocks/programs-native-class-today/class-today-screen.js +14 -0
  14. package/dist/blocks/programs-native-coach-client/coach-client-screen.d.ts +7 -0
  15. package/dist/blocks/programs-native-coach-client/coach-client-screen.js +9 -0
  16. package/dist/blocks/programs-native-progress/progress-screen.d.ts +5 -0
  17. package/dist/blocks/programs-native-progress/progress-screen.js +31 -0
  18. package/dist/blocks/programs-native-session/session-screen.d.ts +7 -0
  19. package/dist/blocks/programs-native-session/session-screen.js +130 -0
  20. package/dist/blocks/programs-native-today/today-screen.d.ts +7 -0
  21. package/dist/blocks/programs-native-today/today-screen.js +11 -0
  22. package/dist/blocks/programs-progress/progress.d.ts +10 -0
  23. package/dist/blocks/programs-progress/progress.js +40 -0
  24. package/dist/blocks/programs-session/session-view.d.ts +9 -0
  25. package/dist/blocks/programs-session/session-view.js +116 -0
  26. package/dist/blocks/programs-today/today.d.ts +7 -0
  27. package/dist/blocks/programs-today/today.js +16 -0
  28. package/dist/client/index.d.ts +1721 -0
  29. package/dist/client/index.js +778 -0
  30. package/dist/dashboards.d.ts +5 -0
  31. package/dist/dashboards.js +145 -0
  32. package/dist/index.d.ts +1181 -0
  33. package/dist/index.js +608 -0
  34. package/dist/layout.d.ts +88 -0
  35. package/dist/layout.js +268 -0
  36. package/dist/tools.d.ts +344 -0
  37. package/dist/tools.js +930 -0
  38. package/package.json +36 -4
  39. package/README.md +0 -3
package/LICENSE ADDED
@@ -0,0 +1,109 @@
1
+ # Functional Source License, Version 1.1, ALv2 Future License
2
+
3
+ > This licence covers the repository except the directories listed in NOTICE. In particular, the
4
+ > assistant packages `packages/agent-*` (agent-core, agent-a2ui, agent-voice, agent-plugins) are
5
+ > licensed under the MIT License; see the LICENSE file in each of those directories (ADR 0350).
6
+
7
+ ## Abbreviation
8
+
9
+ FSL-1.1-ALv2
10
+
11
+ ## Notice
12
+
13
+ Copyright 2026 Tim O'Connell
14
+
15
+ ## Terms and Conditions
16
+
17
+ ### Licensor ("We")
18
+
19
+ The party offering the Software under these Terms and Conditions.
20
+
21
+ ### The Software
22
+
23
+ The "Software" is each version of the software that we make available under
24
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
25
+ Conditions with the Software.
26
+
27
+ ### License Grant
28
+
29
+ Subject to your compliance with this License Grant and the Patents,
30
+ Redistribution and Trademark clauses below, we hereby grant you the right to
31
+ use, copy, modify, create derivative works, publicly perform, publicly display
32
+ and redistribute the Software for any Permitted Purpose identified below.
33
+
34
+ ### Permitted Purpose
35
+
36
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
37
+ means making the Software available to others in a commercial product or
38
+ service that:
39
+
40
+ 1. substitutes for the Software;
41
+
42
+ 2. substitutes for any other product or service we offer using the Software
43
+ that exists as of the date we make the Software available; or
44
+
45
+ 3. offers the same or substantially similar functionality as the Software.
46
+
47
+ Permitted Purposes specifically include using the Software:
48
+
49
+ 1. for your internal use and access;
50
+
51
+ 2. for non-commercial education;
52
+
53
+ 3. for non-commercial research; and
54
+
55
+ 4. in connection with professional services that you provide to a licensee
56
+ using the Software in accordance with these Terms and Conditions.
57
+
58
+ ### Patents
59
+
60
+ To the extent your use for a Permitted Purpose would necessarily infringe our
61
+ patents, the license grant above includes a license under our patents. If you
62
+ make a claim against any party that the Software infringes or contributes to
63
+ the infringement of any patent, then your patent license to the Software ends
64
+ immediately.
65
+
66
+ ### Redistribution
67
+
68
+ The Terms and Conditions apply to all copies, modifications and derivatives of
69
+ the Software.
70
+
71
+ If you redistribute any copies, modifications or derivatives of the Software,
72
+ you must include a copy of or a link to these Terms and Conditions and not
73
+ remove any copyright notices provided in or with the Software.
74
+
75
+ ### Disclaimer
76
+
77
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
78
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
79
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
80
+
81
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
82
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
83
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
84
+
85
+ ### Trademarks
86
+
87
+ Except for displaying the License Details and identifying us as the origin of
88
+ the Software, you have no right under these Terms and Conditions to use our
89
+ trademarks, trade names, service marks or product names.
90
+
91
+ ## Grant of Future License
92
+
93
+ We hereby irrevocably grant you an additional license to use the Software under
94
+ the Apache License, Version 2.0 that is effective on the second anniversary of
95
+ the date we make the Software available. On or after that date, you may use the
96
+ Software under the Apache License, Version 2.0, in which case the following
97
+ will apply:
98
+
99
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
100
+ this file except in compliance with the License.
101
+
102
+ You may obtain a copy of the License at
103
+
104
+ http://www.apache.org/licenses/LICENSE-2.0
105
+
106
+ Unless required by applicable law or agreed to in writing, software distributed
107
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
108
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
109
+ specific language governing permissions and limitations under the License.
@@ -0,0 +1,47 @@
1
+ import type { Layout, SetTarget } from "./layout.ts";
2
+ export interface BankExercise {
3
+ id: string;
4
+ name: string;
5
+ measure?: string | null;
6
+ theme?: string | null;
7
+ level?: string | null;
8
+ }
9
+ /** A line the import could not turn into the layout, and why. */
10
+ export interface UnreadLine {
11
+ line: number;
12
+ text: string;
13
+ reason: string;
14
+ }
15
+ export interface ImportResult {
16
+ title: string | null;
17
+ guidance: string | null;
18
+ layout: Layout;
19
+ unread: UnreadLine[];
20
+ }
21
+ /**
22
+ * A prescription's text ("8-12 sec", "3 reps with a 5 sec hold each rep", "10", "5 each side")
23
+ * as typed sets: `count` of them (a block's rounds), each the same target. Whatever the numbers
24
+ * do not say stays in the prescription's note, in the coach's words.
25
+ */
26
+ export declare function readTarget(rx: string | undefined, measure: string | null | undefined, count: number): {
27
+ sets: SetTarget[];
28
+ note?: string;
29
+ } | string;
30
+ /** Reads shorthand into a layout over `bank`, listing every line it could not use. */
31
+ export declare function readProgramText(text: string, bank: readonly BankExercise[]): ImportResult;
32
+ export interface DraftPlan {
33
+ weeks: number;
34
+ sessionsPerWeek: number;
35
+ /** Words the brief is about (themes, body areas, moves): what picks exercises from the bank. */
36
+ focus: string[];
37
+ }
38
+ /** A brief's numbers and words, read without a model: the fallback and the floor for one. */
39
+ export declare function readBrief(brief: string): DraftPlan;
40
+ /** The bank's exercises the brief is about, best first; the whole bank when none matches. */
41
+ export declare function pickExercises(bank: readonly BankExercise[], focus: readonly string[]): BankExercise[];
42
+ /**
43
+ * A draft layout: `weeks` weeks of `sessionsPerWeek` sessions on spread-out days, each two blocks
44
+ * of exercises taken in turn from `chosen` (bank exercises only), with three sets each, the same
45
+ * every week: a coach's starting point, not a finished program.
46
+ */
47
+ export declare function draftLayout(plan: DraftPlan, chosen: readonly BankExercise[]): Layout;
@@ -0,0 +1,493 @@
1
+ const norm = (name) => name
2
+ .toLowerCase()
3
+ .replace(/[’'"“”]/g, "")
4
+ .replace(/[^a-z0-9]+/g, " ")
5
+ .trim();
6
+ const WEEKDAYS = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"];
7
+ /** The bank by normalised name, and a lookup that also tries without a trailing plural "s". */
8
+ function bankIndex(bank) {
9
+ const byName = new Map();
10
+ for (const e of bank)
11
+ byName.set(norm(e.name), e);
12
+ return (name) => {
13
+ const n = norm(name);
14
+ return byName.get(n) ?? byName.get(n.replace(/s$/, "")) ?? byName.get(`${n}s`);
15
+ };
16
+ }
17
+ /**
18
+ * A prescription's text ("8-12 sec", "3 reps with a 5 sec hold each rep", "10", "5 each side")
19
+ * as typed sets: `count` of them (a block's rounds), each the same target. Whatever the numbers
20
+ * do not say stays in the prescription's note, in the coach's words.
21
+ */
22
+ export function readTarget(rx, measure, count) {
23
+ const text = (rx ?? "").trim();
24
+ const sets = (target) => Array.from({ length: Math.max(1, Math.min(count, 12)) }, () => ({ ...target }));
25
+ const extra = (used) => {
26
+ const rest = text.replace(used, "").replace(/^[\s,;:-]+|[\s,;:-]+$/g, "");
27
+ return rest ? { note: text.length <= 300 ? text : text.slice(0, 300) } : {};
28
+ };
29
+ if (!text) {
30
+ if (measure === "time" || measure === "hold")
31
+ return "no time given";
32
+ return "no reps or time given";
33
+ }
34
+ const hold = /(\d+)\s*(?:-\s*\d+\s*)?(?:s|sec|secs|seconds)\s+hold/i.exec(text);
35
+ const reps = /^(\d+)(?:\s*-\s*(\d+))?(?:\s*(?:reps?|each|\/))?/i.exec(text);
36
+ const secs = /^(\d+)(?:\s*-\s*(\d+))?\s*(?:s|sec|secs|seconds)\b/i.exec(text);
37
+ const mins = /^(\d+)(?:\s*-\s*(\d+))?\s*(?:min|mins|minutes)\b/i.exec(text);
38
+ if (secs) {
39
+ const seconds = Math.min(Number(secs[1]), 7200);
40
+ if (seconds < 1)
41
+ return "a time of 0";
42
+ const target = measure === "hold"
43
+ ? { kind: "hold", seconds: Math.min(seconds, 600) }
44
+ : { kind: "time", seconds };
45
+ return { sets: sets(target), ...extra(secs[0]) };
46
+ }
47
+ if (mins) {
48
+ const seconds = Math.min(Number(mins[1]) * 60, 7200);
49
+ return { sets: sets({ kind: "time", seconds }), ...extra(mins[0]) };
50
+ }
51
+ if (reps) {
52
+ const count1 = Number(reps[1]);
53
+ if (count1 < 1 || count1 > 999)
54
+ return `${count1} reps is not a number of reps`;
55
+ const top = reps[2] ? Number(reps[2]) : undefined;
56
+ const target = {
57
+ kind: "reps",
58
+ reps: count1,
59
+ ...(top && top > count1 && top <= 999 ? { repsMax: top } : {}),
60
+ };
61
+ return { sets: sets(target), ...(hold || text !== reps[0] ? extra(reps[0]) : {}) };
62
+ }
63
+ return `"${text.slice(0, 60)}" has no number of reps or seconds`;
64
+ }
65
+ /** "Name x rx (TEMPO) <link>" → the parts. */
66
+ function splitExercise(raw) {
67
+ let s = raw.replace(/<\s*https?:\/\/[^>\s]+\s*>/gi, " ");
68
+ let tempo;
69
+ s = s.replace(/[\s,]*\(\s*([0-9xX]{4})\s*\)[\s,]*$/, (_m, t) => {
70
+ tempo = t.toUpperCase();
71
+ return " ";
72
+ });
73
+ s = s
74
+ .replace(/\s+/g, " ")
75
+ .replace(/[\s,]+$/, "")
76
+ .trim();
77
+ const sep = /\s+[x×]\s+/gi;
78
+ for (let hit = sep.exec(s); hit; hit = sep.exec(s)) {
79
+ if (/[a-z]/i.test(s.slice(0, hit.index))) {
80
+ return {
81
+ name: s.slice(0, hit.index).trim(),
82
+ rx: s.slice(hit.index + hit[0].length).trim(),
83
+ ...(tempo ? { tempo } : {}),
84
+ };
85
+ }
86
+ }
87
+ return { name: s, ...(tempo ? { tempo } : {}) };
88
+ }
89
+ const RE = {
90
+ title: /^title\s*:\s*(.*)$/i,
91
+ guidance: /^guidance\s*:\s*(.*)$/i,
92
+ week: /^week\s*:?\s*(\d+)\s*(?::\s*(.*))?$/i,
93
+ session: /^session\s*:\s*(.*)$/i,
94
+ focus: /^focus\s*:\s*(.*)$/i,
95
+ warmup: /^warm[\s-]?up\s*:?\s*(.*)$/i,
96
+ block: /^block\s+([A-Za-z0-9]{1,4})\s*(?::\s*(.*))?$/i,
97
+ loading: /^loading\s*:\s*(.*)$/i,
98
+ item: /^([A-Z][0-9]{1,2}[a-z]?)\s*[:.]\s*(.*)$/,
99
+ level: /^(?:level\s*|l)?([0-9])\s*[:.]\s*(.*)$/i,
100
+ dash: /^[-•]\s+(.*)$/,
101
+ coachNote: /^\*+\s*(.*)$/,
102
+ memberNote: /^(?:tv|members?)\s*:\s*(.*)$/i,
103
+ };
104
+ /** Reads shorthand into a layout over `bank`, listing every line it could not use. */
105
+ export function readProgramText(text, bank) {
106
+ const find = bankIndex(bank);
107
+ const unread = [];
108
+ let title = null;
109
+ let guidance = null;
110
+ const weeks = [];
111
+ let week = null;
112
+ let session = null;
113
+ let block = null;
114
+ let item = null;
115
+ let rounds = 1;
116
+ let continueTo = null;
117
+ const lines = text.replace(/\r\n?/g, "\n").split("\n");
118
+ const skip = (n, raw, reason) => {
119
+ unread.push({ line: n, text: raw.trim().slice(0, 300), reason });
120
+ };
121
+ /** Where a note goes: the item, else the block, else the session. */
122
+ const notesHere = () => {
123
+ const owner = item ?? block ?? session;
124
+ if (!owner)
125
+ return null;
126
+ owner.notes = owner.notes ?? [];
127
+ return owner.notes;
128
+ };
129
+ /** The prescriptions a level or item line names, or why it cannot. */
130
+ const prescriptionsOf = (raw) => {
131
+ const joiner = /\s\|\s/.test(raw) ? "|" : /\s\+\s/.test(raw) ? "+" : null;
132
+ const parts = raw.split(/\s+[+|]\s+/).filter((p) => p.trim());
133
+ const list = [];
134
+ for (const part of parts) {
135
+ const { name, rx, tempo } = splitExercise(part);
136
+ const exercise = find(name);
137
+ if (!exercise)
138
+ return `no exercise in the bank is called "${name.slice(0, 80)}"`;
139
+ const target = readTarget(rx, exercise.measure, rounds);
140
+ if (typeof target === "string")
141
+ return `${exercise.name}: ${target}`;
142
+ if (tempo && target.sets[0]?.kind === "reps") {
143
+ for (const set of target.sets)
144
+ if (set.kind === "reps")
145
+ set.tempo = tempo;
146
+ }
147
+ list.push({
148
+ exercise: exercise.id,
149
+ sets: target.sets,
150
+ ...(target.note ? { note: target.note } : {}),
151
+ });
152
+ }
153
+ if (list.length > 3)
154
+ return "more than three exercises in one line";
155
+ return { list, joiner };
156
+ };
157
+ const needWeek = () => {
158
+ if (!week) {
159
+ week = { sessions: [] };
160
+ weeks.push(week);
161
+ }
162
+ return week;
163
+ };
164
+ const readLine = (rawLine, index) => {
165
+ const n = index + 1;
166
+ if (!rawLine.trim()) {
167
+ continueTo = null;
168
+ return;
169
+ }
170
+ const indented = /^\s/.test(rawLine);
171
+ const line = rawLine.trim();
172
+ let m;
173
+ m = RE.coachNote.exec(line) ?? RE.memberNote.exec(line);
174
+ if (m) {
175
+ const note = {
176
+ text: (m[1] ?? "").trim().slice(0, 800),
177
+ ...(RE.memberNote.test(line) ? { members: true } : {}),
178
+ };
179
+ if (!note.text)
180
+ return;
181
+ const target = notesHere();
182
+ if (!target)
183
+ return skip(n, rawLine, "a note before any session");
184
+ if (target.length >= 10)
185
+ return skip(n, rawLine, "more than ten notes in one place");
186
+ target.push(note);
187
+ return;
188
+ }
189
+ // An indented line under guidance or a warm-up's words continues them.
190
+ if (indented && continueTo && !RE.level.test(line) && !RE.dash.test(line)) {
191
+ continueTo(line);
192
+ return;
193
+ }
194
+ m = RE.title.exec(line);
195
+ if (m) {
196
+ title = (m[1] ?? "").trim().slice(0, 200) || null;
197
+ continueTo = null;
198
+ return;
199
+ }
200
+ m = RE.guidance.exec(line);
201
+ if (m) {
202
+ guidance = (m[1] ?? "").trim();
203
+ continueTo = (more) => {
204
+ guidance = `${guidance}\n${more}`;
205
+ };
206
+ return;
207
+ }
208
+ m = RE.week.exec(line);
209
+ if (m) {
210
+ week = { ...(m[2] ? { label: m[2].trim().slice(0, 60) } : {}), sessions: [] };
211
+ weeks.push(week);
212
+ session = block = item = null;
213
+ return;
214
+ }
215
+ m = RE.session.exec(line);
216
+ if (m) {
217
+ const name = (m[1] ?? "").trim().slice(0, 60) || "Session";
218
+ const w = needWeek();
219
+ if (w.sessions.length >= 14)
220
+ return skip(n, rawLine, "more than fourteen sessions in a week");
221
+ const weekday = WEEKDAYS.findIndex((d) => norm(name).split(" ").includes(d));
222
+ const used = new Set(w.sessions.map((s) => s.day));
223
+ const day = weekday >= 0 ? weekday + 1 : ([1, 2, 3, 4, 5, 6, 7].find((d) => !used.has(d)) ?? 7);
224
+ session = { name, day, blocks: [] };
225
+ w.sessions.push(session);
226
+ block = item = null;
227
+ continueTo = null;
228
+ return;
229
+ }
230
+ if (!session)
231
+ return skip(n, rawLine, 'put a "Session: …" line first');
232
+ const s = session;
233
+ m = RE.focus.exec(line);
234
+ if (m) {
235
+ s.focus = (m[1] ?? "").trim().slice(0, 200);
236
+ return;
237
+ }
238
+ m = RE.warmup.exec(line);
239
+ if (m) {
240
+ s.warmup = { ...(m[1]?.trim() ? { text: m[1].trim().slice(0, 1200) } : {}) };
241
+ block = item = null;
242
+ continueTo = (more) => {
243
+ const w = s.warmup ?? {};
244
+ w.text = `${w.text ? `${w.text}\n` : ""}${more}`.slice(0, 1200);
245
+ s.warmup = w;
246
+ };
247
+ return;
248
+ }
249
+ m = RE.dash.exec(line);
250
+ if (m && !block && s.warmup) {
251
+ const found = prescriptionsOf(m[1] ?? "");
252
+ const w = s.warmup;
253
+ if (typeof found === "string") {
254
+ // A warm-up line the bank does not have stays as words in the warm-up.
255
+ w.text = `${w.text ? `${w.text}\n` : ""}- ${m[1]}`.slice(0, 1200);
256
+ return skip(n, rawLine, `kept as warm-up text: ${found}`);
257
+ }
258
+ w.exercises = [...(w.exercises ?? []), ...found.list].slice(0, 15);
259
+ return;
260
+ }
261
+ m = RE.block.exec(line);
262
+ if (m) {
263
+ const label = (m[1] ?? "").toUpperCase();
264
+ if (s.blocks.some((b) => b.label === label))
265
+ return skip(n, rawLine, `block ${label} is there twice`);
266
+ const about = (m[2] ?? "").trim();
267
+ const count = /(\d+)\s*(?:-\s*\d+\s*)?rounds?/i.exec(about) ?? /rounds?\s*:?\s*(\d+)/i.exec(about);
268
+ rounds = count ? Math.min(Math.max(Number(count[1]), 1), 12) : 1;
269
+ block = {
270
+ label,
271
+ ...(count ? { rounds: Math.min(Number(count[1]), 50) } : {}),
272
+ items: [],
273
+ ...(about ? { notes: [{ text: about.slice(0, 800), members: true }] } : {}),
274
+ };
275
+ s.blocks.push(block);
276
+ item = null;
277
+ continueTo = null;
278
+ return;
279
+ }
280
+ m = RE.loading.exec(line);
281
+ if (m && block) {
282
+ // How the rounds load: words for members on the block, continued by indented lines.
283
+ block.notes = block.notes ?? [];
284
+ const notes = block.notes;
285
+ const note = { text: (m[1] ?? "").trim().slice(0, 800), members: true };
286
+ if (notes.length >= 10)
287
+ return skip(n, rawLine, "more than ten notes in one place");
288
+ notes.push(note);
289
+ continueTo = (more) => {
290
+ note.text = `${note.text}\n${more}`.slice(0, 800);
291
+ };
292
+ return;
293
+ }
294
+ m = RE.item.exec(line);
295
+ if (m) {
296
+ if (!block) {
297
+ block = { label: (m[1] ?? "A").charAt(0), items: [] };
298
+ s.blocks.push(block);
299
+ }
300
+ const label = m[1];
301
+ if (block.items.some((i) => i.label === label))
302
+ return skip(n, rawLine, `item ${label} is there twice`);
303
+ const rest = (m[2] ?? "").trim();
304
+ // An exercise on the line: for everyone. A name alone: its levels follow.
305
+ const found = rest ? prescriptionsOf(rest) : "an item with nothing after its label";
306
+ if (typeof found !== "string") {
307
+ item = { kind: "all", label, exercises: found.list };
308
+ block.items.push(item);
309
+ return;
310
+ }
311
+ const looksLikeHead = rest && !/\s[x×]\s/i.test(rest);
312
+ if (looksLikeHead || !rest) {
313
+ item = {
314
+ kind: "levels",
315
+ label,
316
+ levels: [],
317
+ ...(rest ? { notes: [{ text: rest.slice(0, 800), members: true }] } : {}),
318
+ };
319
+ block.items.push(item);
320
+ return;
321
+ }
322
+ item = null;
323
+ return skip(n, rawLine, found);
324
+ }
325
+ m = RE.level.exec(line);
326
+ if (m && item?.kind === "levels") {
327
+ const number = Number(m[1]);
328
+ if (number < 1 || number > 5)
329
+ return skip(n, rawLine, "a level is 1 to 5");
330
+ if (item.levels.some((l) => l.level === number))
331
+ return skip(n, rawLine, `level ${number} is there twice`);
332
+ const found = prescriptionsOf(m[2] ?? "");
333
+ if (typeof found === "string")
334
+ return skip(n, rawLine, found);
335
+ const level = found.list.length === 1
336
+ ? { mode: "one", level: number, exercise: found.list[0] }
337
+ : {
338
+ mode: found.joiner === "|" ? "alternatives" : "together",
339
+ level: number,
340
+ exercises: found.list,
341
+ };
342
+ item.levels.push(level);
343
+ item.levels.sort((a, b) => a.level - b.level);
344
+ return;
345
+ }
346
+ if (indented && continueTo) {
347
+ continueTo(line);
348
+ return;
349
+ }
350
+ skip(n, rawLine, "not a line the import knows");
351
+ };
352
+ for (const [index, rawLine] of lines.entries())
353
+ readLine(rawLine, index);
354
+ // An item whose levels all failed, or a block left empty, cannot be in the layout: say so.
355
+ for (const w of weeks) {
356
+ for (const s of w.sessions) {
357
+ for (const b of s.blocks) {
358
+ const kept = b.items.filter((i) => i.kind === "all" || i.levels.length > 0);
359
+ for (const dropped of b.items.filter((i) => !kept.includes(i))) {
360
+ unread.push({
361
+ line: 0,
362
+ text: `${s.name} › ${dropped.label}`,
363
+ reason: "no level of this item could be read",
364
+ });
365
+ }
366
+ b.items = kept;
367
+ }
368
+ const blocks = s.blocks.filter((b) => b.items.length > 0);
369
+ for (const dropped of s.blocks.filter((b) => !blocks.includes(b))) {
370
+ unread.push({
371
+ line: 0,
372
+ text: `${s.name} › block ${dropped.label}`,
373
+ reason: "no item of this block could be read",
374
+ });
375
+ }
376
+ s.blocks = blocks;
377
+ }
378
+ }
379
+ if (!weeks.length)
380
+ weeks.push({ sessions: [] });
381
+ unread.sort((a, b) => a.line - b.line);
382
+ return {
383
+ title,
384
+ guidance: guidance ? guidance.slice(0, 5000) : null,
385
+ layout: { weeks },
386
+ unread,
387
+ };
388
+ }
389
+ /** A brief's numbers and words, read without a model: the fallback and the floor for one. */
390
+ export function readBrief(brief) {
391
+ const weeks = /(\d+)\s*-?\s*weeks?/i.exec(brief);
392
+ const perWeek = /(\d+)\s*(?:sessions?|days?|x)\s*(?:a|per|\/)\s*week/i.exec(brief) ??
393
+ /(\d+)\s*(?:sessions?|days?)\b/i.exec(brief);
394
+ const focus = norm(brief)
395
+ .split(" ")
396
+ .filter((word) => word.length > 3 && !/^\d+$/.test(word) && !STOP.has(word));
397
+ return {
398
+ weeks: clamp(weeks ? Number(weeks[1]) : 4, 1, 52),
399
+ sessionsPerWeek: clamp(perWeek ? Number(perWeek[1]) : 3, 1, 7),
400
+ focus: [...new Set(focus)],
401
+ };
402
+ }
403
+ const STOP = new Set([
404
+ "week",
405
+ "weeks",
406
+ "session",
407
+ "sessions",
408
+ "with",
409
+ "that",
410
+ "this",
411
+ "from",
412
+ "into",
413
+ "program",
414
+ "programme",
415
+ "client",
416
+ "class",
417
+ "days",
418
+ "each",
419
+ "some",
420
+ "focus",
421
+ "build",
422
+ "make",
423
+ "about",
424
+ "they",
425
+ "their",
426
+ "them",
427
+ "work",
428
+ "working",
429
+ ]);
430
+ const clamp = (n, low, high) => Math.min(Math.max(Math.round(n), low), high);
431
+ /** The bank's exercises the brief is about, best first; the whole bank when none matches. */
432
+ export function pickExercises(bank, focus) {
433
+ const score = (e) => {
434
+ const words = new Set(norm(`${e.name} ${e.theme ?? ""} ${e.level ?? ""}`).split(" "));
435
+ return focus.filter((f) => words.has(f) || [...words].some((w) => w.startsWith(f) || f.startsWith(w))).length;
436
+ };
437
+ const scored = bank.map((e) => ({ e, s: score(e) })).filter((x) => x.s > 0);
438
+ scored.sort((a, b) => b.s - a.s || a.e.name.localeCompare(b.e.name));
439
+ return scored.length ? scored.map((x) => x.e) : [...bank];
440
+ }
441
+ /** A sensible default target for an exercise of `measure`: 3 sets. */
442
+ function defaultSets(measure) {
443
+ const one = measure === "time"
444
+ ? { kind: "time", seconds: 30, rest: 60 }
445
+ : measure === "hold"
446
+ ? { kind: "hold", seconds: 20, rest: 60 }
447
+ : { kind: "reps", reps: 8, rest: 90 };
448
+ return [one, { ...one }, { ...one }];
449
+ }
450
+ /**
451
+ * A draft layout: `weeks` weeks of `sessionsPerWeek` sessions on spread-out days, each two blocks
452
+ * of exercises taken in turn from `chosen` (bank exercises only), with three sets each, the same
453
+ * every week: a coach's starting point, not a finished program.
454
+ */
455
+ export function draftLayout(plan, chosen) {
456
+ const days = [
457
+ [1],
458
+ [1, 4],
459
+ [1, 3, 5],
460
+ [1, 2, 4, 5],
461
+ [1, 2, 3, 4, 5],
462
+ [1, 2, 3, 4, 5, 6],
463
+ [1, 2, 3, 4, 5, 6, 7],
464
+ ][plan.sessionsPerWeek - 1];
465
+ const pool = chosen.length ? chosen : [];
466
+ let next = 0;
467
+ const take = () => {
468
+ const e = pool[next % pool.length];
469
+ next += 1;
470
+ return { exercise: e.id, sets: defaultSets(e.measure) };
471
+ };
472
+ const sessionsOfWeek = days.map((day, s) => ({
473
+ name: `Session ${String.fromCharCode(65 + s)}`,
474
+ day,
475
+ blocks: pool.length
476
+ ? ["A", "B"].map((label) => ({
477
+ label,
478
+ rounds: 3,
479
+ items: [1, 2].map((k) => ({
480
+ kind: "all",
481
+ label: `${label}${k}`,
482
+ exercises: [take()],
483
+ })),
484
+ }))
485
+ : [],
486
+ }));
487
+ return {
488
+ weeks: Array.from({ length: plan.weeks }, (_, w) => ({
489
+ label: `Week ${w + 1}`,
490
+ sessions: JSON.parse(JSON.stringify(sessionsOfWeek)),
491
+ })),
492
+ };
493
+ }
@@ -0,0 +1,4 @@
1
+ import type { ProgramsHooks } from "@composable-os/pack-programs/client";
2
+ export declare function ExerciseBank({ programs, }: {
3
+ programs: Pick<ProgramsHooks, "useBank" | "useCreateExercise" | "useUpdateExercise">;
4
+ }): import("react").JSX.Element;