@trainheroic-unofficial/cli 1.2.0 → 1.3.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/dist/cli.mjs +264 -1
- package/package.json +3 -3
package/dist/cli.mjs
CHANGED
|
@@ -475,6 +475,14 @@ function coerceInt(value) {
|
|
|
475
475
|
}
|
|
476
476
|
return null;
|
|
477
477
|
}
|
|
478
|
+
function coerceNum(value) {
|
|
479
|
+
if (typeof value === "number") return Number.isFinite(value) ? value : null;
|
|
480
|
+
if (typeof value === "string" && value.trim() !== "") {
|
|
481
|
+
const n = Number(value);
|
|
482
|
+
return Number.isFinite(n) ? n : null;
|
|
483
|
+
}
|
|
484
|
+
return null;
|
|
485
|
+
}
|
|
478
486
|
function unitLabel(paramType) {
|
|
479
487
|
const t = coerceInt(paramType);
|
|
480
488
|
if (t === null) return null;
|
|
@@ -1556,6 +1564,7 @@ function presentExerciseHistory(detail) {
|
|
|
1556
1564
|
description: p.description ?? null,
|
|
1557
1565
|
reps: p.reps ?? null,
|
|
1558
1566
|
weight: p.weight ?? null,
|
|
1567
|
+
units: p.units ?? null,
|
|
1559
1568
|
date: p.dateCompleted ?? null
|
|
1560
1569
|
})),
|
|
1561
1570
|
sessions: (detail.history ?? []).map((h) => ({
|
|
@@ -1573,6 +1582,37 @@ function presentExerciseHistory(detail) {
|
|
|
1573
1582
|
function emailList(emails) {
|
|
1574
1583
|
return [...new Set(emails.map((e) => e.trim()).filter((e) => e.length > 0))];
|
|
1575
1584
|
}
|
|
1585
|
+
/** The display name on a /v5/athletes row: `fullName` (e.g. "Cohen, A"), else first+last. */
|
|
1586
|
+
function rosterName(rec) {
|
|
1587
|
+
const full = typeof rec.fullName === "string" ? rec.fullName.trim() : "";
|
|
1588
|
+
if (full !== "") return full;
|
|
1589
|
+
const combined = `${typeof rec.firstName === "string" ? rec.firstName : ""} ${typeof rec.lastName === "string" ? rec.lastName : ""}`.trim();
|
|
1590
|
+
return combined !== "" ? combined : null;
|
|
1591
|
+
}
|
|
1592
|
+
/**
|
|
1593
|
+
* The coach's roster as id + display name, from /v5/athletes. One home for the id coercion and the
|
|
1594
|
+
* name-field choice (the API uses `fullName` / `firstName`+`lastName`), so the CLI, the MCP tools,
|
|
1595
|
+
* and the warehouse store map the roster identically. Includes the account owner and
|
|
1596
|
+
* demo/placeholder athletes (the raw roster does); pass `ids` to keep only a subset.
|
|
1597
|
+
*/
|
|
1598
|
+
async function fetchCoachRoster(client, ids) {
|
|
1599
|
+
const res = await client.request("GET", "/v5/athletes");
|
|
1600
|
+
if (!res.ok || !Array.isArray(res.data)) throw new Error(`List athletes failed (HTTP ${res.status}).`);
|
|
1601
|
+
const keep = ids && ids.length > 0 ? new Set(ids) : null;
|
|
1602
|
+
const out = [];
|
|
1603
|
+
for (const row of res.data) {
|
|
1604
|
+
if (typeof row !== "object" || row === null) continue;
|
|
1605
|
+
const rec = row;
|
|
1606
|
+
const id = coerceInt(rec.id);
|
|
1607
|
+
if (id === null || id <= 0) continue;
|
|
1608
|
+
if (keep && !keep.has(id)) continue;
|
|
1609
|
+
out.push({
|
|
1610
|
+
id,
|
|
1611
|
+
name: rosterName(rec)
|
|
1612
|
+
});
|
|
1613
|
+
}
|
|
1614
|
+
return out;
|
|
1615
|
+
}
|
|
1576
1616
|
/**
|
|
1577
1617
|
* Invite athletes to a team — TrainHeroic's two-step "create athlete" flow: validate the
|
|
1578
1618
|
* addresses (`POST /v5/emails/validate`), then invite the validated ones
|
|
@@ -1852,6 +1892,213 @@ async function teamVolume(client, args) {
|
|
|
1852
1892
|
};
|
|
1853
1893
|
}
|
|
1854
1894
|
//#endregion
|
|
1895
|
+
//#region ../js/src/main-lifts.ts
|
|
1896
|
+
/**
|
|
1897
|
+
* The "main lifts" — Big 4 plus the two Olympic lifts. ORDER MATTERS: a title is classified by the
|
|
1898
|
+
* first family that matches, so the more specific / easily-confused families come before the broad
|
|
1899
|
+
* overhead-press rule. That ordering is why "Bench Press" classifies as `bench` and never gets
|
|
1900
|
+
* swept up as an overhead press, and why "Clean & Jerk" is not mistaken for a clean-only movement.
|
|
1901
|
+
* This is the single place to edit the lift set.
|
|
1902
|
+
*/
|
|
1903
|
+
const MAIN_LIFT_FAMILIES = [
|
|
1904
|
+
{
|
|
1905
|
+
key: "cleanjerk",
|
|
1906
|
+
label: "Clean & Jerk",
|
|
1907
|
+
matches: (t) => t.includes("jerk") || t.includes("clean") && !t.includes("clean pull")
|
|
1908
|
+
},
|
|
1909
|
+
{
|
|
1910
|
+
key: "snatch",
|
|
1911
|
+
label: "Snatch",
|
|
1912
|
+
matches: (t) => t.includes("snatch")
|
|
1913
|
+
},
|
|
1914
|
+
{
|
|
1915
|
+
key: "deadlift",
|
|
1916
|
+
label: "Deadlift",
|
|
1917
|
+
matches: (t) => t.includes("deadlift")
|
|
1918
|
+
},
|
|
1919
|
+
{
|
|
1920
|
+
key: "squat",
|
|
1921
|
+
label: "Squat",
|
|
1922
|
+
matches: (t) => t.includes("squat")
|
|
1923
|
+
},
|
|
1924
|
+
{
|
|
1925
|
+
key: "bench",
|
|
1926
|
+
label: "Bench Press",
|
|
1927
|
+
matches: (t) => t.includes("bench")
|
|
1928
|
+
},
|
|
1929
|
+
{
|
|
1930
|
+
key: "overhead",
|
|
1931
|
+
label: "Overhead Press",
|
|
1932
|
+
matches: (t) => t.includes("ohp") || (t.includes("overhead") || t.includes("shoulder") || t.includes("military") || t.includes("strict") || t.includes("push")) && t.includes("press")
|
|
1933
|
+
}
|
|
1934
|
+
];
|
|
1935
|
+
/** The lift family a logged exercise title belongs to, or null if it is not a main lift. */
|
|
1936
|
+
function classifyMainLift(title) {
|
|
1937
|
+
const t = title.toLowerCase();
|
|
1938
|
+
for (const family of MAIN_LIFT_FAMILIES) if (family.matches(t)) return family.key;
|
|
1939
|
+
return null;
|
|
1940
|
+
}
|
|
1941
|
+
const DEFAULT_MONTHS = 12;
|
|
1942
|
+
function pad2(n) {
|
|
1943
|
+
return String(n).padStart(2, "0");
|
|
1944
|
+
}
|
|
1945
|
+
/** A local Date as a YYYY-MM-DD day string (the range endpoint's date format). */
|
|
1946
|
+
function isoDay(d) {
|
|
1947
|
+
return `${d.getFullYear()}-${pad2(d.getMonth() + 1)}-${pad2(d.getDate())}`;
|
|
1948
|
+
}
|
|
1949
|
+
/**
|
|
1950
|
+
* Discover a roster athlete's main lifts from what they actually logged. Reads the athlete's
|
|
1951
|
+
* logged workouts over the last `months` (default 12) — the program-workout range, the reliable
|
|
1952
|
+
* record of performed sets — buckets every performed exercise into a lift family, and for each
|
|
1953
|
+
* family picks the variant logged most often. Returns one entry per family the athlete has logged;
|
|
1954
|
+
* families they never trained are simply absent. (The monthly calendar summary is not used: it
|
|
1955
|
+
* comes back empty for some accounts that have logged sets in the range endpoint.)
|
|
1956
|
+
*/
|
|
1957
|
+
async function resolveAthleteMainLifts(client, athleteId, opts = {}) {
|
|
1958
|
+
const months = opts.months ?? DEFAULT_MONTHS;
|
|
1959
|
+
const now = opts.now ?? /* @__PURE__ */ new Date();
|
|
1960
|
+
const start = new Date(now.getFullYear(), now.getMonth() - (months - 1), 1);
|
|
1961
|
+
const tally = /* @__PURE__ */ new Map();
|
|
1962
|
+
let workouts = [];
|
|
1963
|
+
try {
|
|
1964
|
+
workouts = await fetchCoachAthleteWorkouts(client, athleteId, isoDay(start), isoDay(now));
|
|
1965
|
+
} catch {
|
|
1966
|
+
workouts = [];
|
|
1967
|
+
}
|
|
1968
|
+
for (const view of presentAthleteWorkouts(workouts)) for (const block of view.blocks) for (const ex of block.exercises) {
|
|
1969
|
+
if (ex.performed.length === 0 || ex.exerciseId === null) continue;
|
|
1970
|
+
const family = classifyMainLift(ex.title);
|
|
1971
|
+
if (family === null) continue;
|
|
1972
|
+
const byId = tally.get(family) ?? /* @__PURE__ */ new Map();
|
|
1973
|
+
const prev = byId.get(ex.exerciseId);
|
|
1974
|
+
byId.set(ex.exerciseId, {
|
|
1975
|
+
count: (prev?.count ?? 0) + 1,
|
|
1976
|
+
title: prev?.title ?? ex.title
|
|
1977
|
+
});
|
|
1978
|
+
tally.set(family, byId);
|
|
1979
|
+
}
|
|
1980
|
+
const lifts = [];
|
|
1981
|
+
for (const family of MAIN_LIFT_FAMILIES) {
|
|
1982
|
+
const byId = tally.get(family.key);
|
|
1983
|
+
if (!byId || byId.size === 0) continue;
|
|
1984
|
+
let best = null;
|
|
1985
|
+
for (const [exerciseId, { count, title }] of byId) if (best === null || count > best.count || count === best.count && exerciseId < best.exerciseId) best = {
|
|
1986
|
+
exerciseId,
|
|
1987
|
+
count,
|
|
1988
|
+
title
|
|
1989
|
+
};
|
|
1990
|
+
if (best) lifts.push({
|
|
1991
|
+
family: family.key,
|
|
1992
|
+
label: family.label,
|
|
1993
|
+
exerciseId: best.exerciseId,
|
|
1994
|
+
title: best.title
|
|
1995
|
+
});
|
|
1996
|
+
}
|
|
1997
|
+
return {
|
|
1998
|
+
athleteId,
|
|
1999
|
+
athleteName: null,
|
|
2000
|
+
lifts
|
|
2001
|
+
};
|
|
2002
|
+
}
|
|
2003
|
+
const PR_CONCURRENCY = 5;
|
|
2004
|
+
/** The heaviest PR on an exercise's board (ties broken by more reps). */
|
|
2005
|
+
function bestPr(liftPRs) {
|
|
2006
|
+
let best = null;
|
|
2007
|
+
for (const pr of liftPRs) {
|
|
2008
|
+
const weight = coerceNum(pr.weight);
|
|
2009
|
+
if (weight === null) continue;
|
|
2010
|
+
const reps = coerceInt(pr.reps);
|
|
2011
|
+
if (best === null || weight > best.weight || weight === best.weight && (reps ?? 0) > (best.reps ?? 0)) best = {
|
|
2012
|
+
weight,
|
|
2013
|
+
reps,
|
|
2014
|
+
units: pr.units,
|
|
2015
|
+
date: pr.date
|
|
2016
|
+
};
|
|
2017
|
+
}
|
|
2018
|
+
return best;
|
|
2019
|
+
}
|
|
2020
|
+
/**
|
|
2021
|
+
* A roster athlete's best PR for each main lift. Discovers the lift variants they log
|
|
2022
|
+
* ({@link resolveAthleteMainLifts}), then pulls each variant's PR board and keeps the heaviest set.
|
|
2023
|
+
* The result always carries one entry per family in {@link MAIN_LIFT_FAMILIES} order; a family the
|
|
2024
|
+
* athlete has not logged comes back with null fields (the "no PR yet" case), so a dashboard can
|
|
2025
|
+
* render a stable row of columns.
|
|
2026
|
+
*/
|
|
2027
|
+
async function fetchAthleteMainLiftPRs(client, athleteId, opts = {}) {
|
|
2028
|
+
const { athleteName, lifts } = await resolveAthleteMainLifts(client, athleteId, opts);
|
|
2029
|
+
const byFamily = new Map(lifts.map((l) => [l.family, l]));
|
|
2030
|
+
return {
|
|
2031
|
+
athleteId,
|
|
2032
|
+
athleteName,
|
|
2033
|
+
prs: await mapPool(MAIN_LIFT_FAMILIES, PR_CONCURRENCY, async (family) => {
|
|
2034
|
+
const lift = byFamily.get(family.key);
|
|
2035
|
+
const base = {
|
|
2036
|
+
family: family.key,
|
|
2037
|
+
label: family.label
|
|
2038
|
+
};
|
|
2039
|
+
const empty = {
|
|
2040
|
+
exerciseId: null,
|
|
2041
|
+
title: null,
|
|
2042
|
+
weight: null,
|
|
2043
|
+
reps: null,
|
|
2044
|
+
units: null,
|
|
2045
|
+
date: null
|
|
2046
|
+
};
|
|
2047
|
+
if (!lift) return {
|
|
2048
|
+
...base,
|
|
2049
|
+
...empty
|
|
2050
|
+
};
|
|
2051
|
+
const known = {
|
|
2052
|
+
exerciseId: lift.exerciseId,
|
|
2053
|
+
title: lift.title
|
|
2054
|
+
};
|
|
2055
|
+
try {
|
|
2056
|
+
const best = bestPr(presentExerciseHistory(await fetchExerciseHistoryDetail(client, lift.exerciseId, athleteId)).liftPRs);
|
|
2057
|
+
return {
|
|
2058
|
+
...base,
|
|
2059
|
+
...known,
|
|
2060
|
+
weight: best?.weight ?? null,
|
|
2061
|
+
reps: best?.reps ?? null,
|
|
2062
|
+
units: best?.units ?? null,
|
|
2063
|
+
date: best?.date ?? null
|
|
2064
|
+
};
|
|
2065
|
+
} catch {
|
|
2066
|
+
return {
|
|
2067
|
+
...base,
|
|
2068
|
+
...known,
|
|
2069
|
+
weight: null,
|
|
2070
|
+
reps: null,
|
|
2071
|
+
units: null,
|
|
2072
|
+
date: null
|
|
2073
|
+
};
|
|
2074
|
+
}
|
|
2075
|
+
})
|
|
2076
|
+
};
|
|
2077
|
+
}
|
|
2078
|
+
const ROSTER_CONCURRENCY = 4;
|
|
2079
|
+
/**
|
|
2080
|
+
* Every roster athlete's main-lift PRs in one call: list the roster ({@link fetchCoachRoster}) and
|
|
2081
|
+
* resolve each athlete's board ({@link fetchAthleteMainLiftPRs}), fanned out with a bounded pool.
|
|
2082
|
+
* `athleteIds` restricts to a subset (else the whole roster). Each entry's `athleteName` falls back
|
|
2083
|
+
* to the roster name when the per-athlete read can't supply one. This is the single roster-level
|
|
2084
|
+
* primitive the CLI, the MCP tool, and the warehouse store all build on.
|
|
2085
|
+
*/
|
|
2086
|
+
async function fetchRosterMainLiftPRs(client, opts = {}) {
|
|
2087
|
+
const roster = await fetchCoachRoster(client, opts.athleteIds);
|
|
2088
|
+
const inner = {
|
|
2089
|
+
...opts.months !== void 0 ? { months: opts.months } : {},
|
|
2090
|
+
...opts.now !== void 0 ? { now: opts.now } : {}
|
|
2091
|
+
};
|
|
2092
|
+
return mapPool(roster, opts.concurrency ?? ROSTER_CONCURRENCY, async (athlete) => {
|
|
2093
|
+
const result = await fetchAthleteMainLiftPRs(client, athlete.id, inner);
|
|
2094
|
+
return {
|
|
2095
|
+
athleteId: athlete.id,
|
|
2096
|
+
athleteName: result.athleteName ?? athlete.name,
|
|
2097
|
+
prs: result.prs
|
|
2098
|
+
};
|
|
2099
|
+
});
|
|
2100
|
+
}
|
|
2101
|
+
//#endregion
|
|
1855
2102
|
//#region ../js/src/util.ts
|
|
1856
2103
|
/**
|
|
1857
2104
|
* Drop the keys whose value is `undefined`, so the result can be passed to a function or
|
|
@@ -2514,6 +2761,7 @@ Coach — manage a roster (needs a coach account):
|
|
|
2514
2761
|
coach athlete-workouts --athlete <id> --start Y-M-D --end Y-M-D [--logged-only] [--summary] [--raw|--log-ids] prescribed + logged work over a date range; --logged-only/--summary narrow it to what was actually logged; --log-ids prints just the savedWorkoutSetId + savedWorkoutSetExerciseId per set that log-set needs
|
|
2515
2762
|
coach athlete-training --athlete <id> --year <YYYY> --month <1-12> sessions the athlete LOGGED in one month (empty = nothing logged that month, not an error)
|
|
2516
2763
|
coach athlete-lift-history --athlete <id> --exercise <id> [--since Y-M-D] [--until Y-M-D] [--raw] one exercise's logged history + PRs
|
|
2764
|
+
coach main-lift-prs [--athlete <id>] [--athletes <id,id,...>] [--months <n>] best PRs for the main lifts (squat/bench/deadlift/overhead press/clean & jerk/snatch); auto-discovers the logged variant. With --athlete, one athlete; otherwise the whole roster (or --athletes subset)
|
|
2517
2765
|
|
|
2518
2766
|
log for an athlete (record their reps/weights; real invited athletes only — demo/seeded ones 401):
|
|
2519
2767
|
coach log-set --athlete <id> --date Y-M-D --set <savedWorkoutSetId> <resultsJson>|--file f --yes
|
|
@@ -3077,7 +3325,7 @@ async function cmdInstallSkill() {
|
|
|
3077
3325
|
}
|
|
3078
3326
|
out({ installed });
|
|
3079
3327
|
}
|
|
3080
|
-
const COACH_USAGE = "usage: trainheroic coach <head-coach|athletes|programs|teams|notifications|analytics|program <id>|team <id>|team-codes <id>|roster-activity|team-volume|athlete-training|athlete-lift-history|athlete-workouts|log-set|log-session|prescribe-set|swap-exercise|athlete-invite|athlete-archive|athlete-restore|team-create|team-update|team-delete|team-code-create|team-code-delete|session-copy|session-unpublish|session-save-template|analytics-query|exercise|workout|message>";
|
|
3328
|
+
const COACH_USAGE = "usage: trainheroic coach <head-coach|athletes|programs|teams|notifications|analytics|program <id>|team <id>|team-codes <id>|roster-activity|team-volume|athlete-training|athlete-lift-history|main-lift-prs|athlete-workouts|log-set|log-session|prescribe-set|swap-exercise|athlete-invite|athlete-archive|athlete-restore|team-create|team-update|team-delete|team-code-create|team-code-delete|session-copy|session-unpublish|session-save-template|analytics-query|exercise|workout|message>";
|
|
3081
3329
|
const COACH_LOG_SET_USAGE = "coach log-set --athlete <id> --date Y-M-D --set <savedWorkoutSetId> <resultsJson> --yes";
|
|
3082
3330
|
async function cmdCoachLogSet(client, a) {
|
|
3083
3331
|
const { values, positionals } = parse(a, {
|
|
@@ -3393,6 +3641,20 @@ async function cmdCoachAthleteLiftHistory(client, a) {
|
|
|
3393
3641
|
sessions
|
|
3394
3642
|
});
|
|
3395
3643
|
}
|
|
3644
|
+
async function cmdCoachMainLiftPrs(client, a) {
|
|
3645
|
+
const { values } = parse(a, {
|
|
3646
|
+
athlete: { type: "string" },
|
|
3647
|
+
athletes: { type: "string" },
|
|
3648
|
+
months: { type: "string" }
|
|
3649
|
+
});
|
|
3650
|
+
const opts = values.months !== void 0 ? { months: toInt(values.months, "--months") } : {};
|
|
3651
|
+
if (values.athlete !== void 0) return out(await fetchAthleteMainLiftPRs(client, toInt(values.athlete, "--athlete"), opts));
|
|
3652
|
+
const subset = values.athletes !== void 0 ? values.athletes.split(",").map((s) => s.trim()).filter((s) => s.length > 0).map((s) => toInt(s, "--athletes")) : void 0;
|
|
3653
|
+
return out(await fetchRosterMainLiftPRs(client, {
|
|
3654
|
+
...opts,
|
|
3655
|
+
...subset ? { athleteIds: subset } : {}
|
|
3656
|
+
}));
|
|
3657
|
+
}
|
|
3396
3658
|
async function cmdCoach(client, rest) {
|
|
3397
3659
|
const [sub, ...a] = rest;
|
|
3398
3660
|
switch (sub) {
|
|
@@ -3409,6 +3671,7 @@ async function cmdCoach(client, rest) {
|
|
|
3409
3671
|
case "team-volume": return cmdCoachTeamVolume(client, a);
|
|
3410
3672
|
case "athlete-training": return cmdCoachAthleteTraining(client, a);
|
|
3411
3673
|
case "athlete-lift-history": return cmdCoachAthleteLiftHistory(client, a);
|
|
3674
|
+
case "main-lift-prs": return cmdCoachMainLiftPrs(client, a);
|
|
3412
3675
|
case "athlete-workouts": return cmdCoachAthleteWorkouts(client, a);
|
|
3413
3676
|
case "log-set": return cmdCoachLogSet(client, a);
|
|
3414
3677
|
case "log-session": return cmdCoachLogSession(client, a);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trainheroic-unofficial/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"zod": "^4.4.3",
|
|
24
|
-
"@trainheroic-unofficial/dto": "1.
|
|
25
|
-
"@trainheroic-unofficial/js": "1.
|
|
24
|
+
"@trainheroic-unofficial/dto": "1.3.0",
|
|
25
|
+
"@trainheroic-unofficial/js": "1.3.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/node": "^26.0.0",
|