@trainheroic-unofficial/cli 3.1.0 → 3.2.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 CHANGED
@@ -305,6 +305,24 @@ const programWorkoutResponseSchema = z.looseObject({
305
305
  });
306
306
  /** The calendar edit-view response we read sessions back from. */
307
307
  const programsEditResponseSchema = z.looseObject({ programWorkouts: z.array(programWorkoutResponseSchema).optional() });
308
+ /** A standalone program create response (container id + usable calendar/program id). */
309
+ const programCreateResponseSchema = z.looseObject({
310
+ id: intLike,
311
+ title: z.string(),
312
+ programId: intLike,
313
+ group_program: intLike,
314
+ type: intLike,
315
+ program: z.looseObject({
316
+ id: intLike,
317
+ program_type: intLike
318
+ }).optional()
319
+ });
320
+ const teamPublishPatchSchema = z.object({
321
+ pub_enabled: z.union([z.number(), z.boolean()]).optional(),
322
+ pub_days: z.unknown().optional(),
323
+ pub_time: z.unknown().optional(),
324
+ pub_timezone: z.string().optional()
325
+ }).refine((v) => v.pub_enabled !== void 0 || v.pub_days !== void 0 || v.pub_time !== void 0 || v.pub_timezone !== void 0, { message: "Provide at least one pub_* field" });
308
326
  //#endregion
309
327
  //#region ../dto/src/workout.ts
310
328
  /** A single exercise prescription inside a block. */
@@ -372,6 +390,11 @@ function parseWorkoutDate(s) {
372
390
  parts[2]
373
391
  ];
374
392
  }
393
+ /** Body for `POST /v5/sessions/template` (library create, not save-from-session). */
394
+ const sessionTemplateCreateSchema = z.object({
395
+ title: z.string().min(1),
396
+ instruction: z.string().optional()
397
+ });
375
398
  //#endregion
376
399
  //#region ../js/src/http-error.ts
377
400
  /**
@@ -521,7 +544,7 @@ var TrainHeroicClient = class {
521
544
  session = await this.#ensureSession();
522
545
  res = await this.#send(method, url, session, options.body);
523
546
  }
524
- if (!res.ok) notifyHttpError(this.#onHttpError, method, url, res.status);
547
+ if (!res.ok && !options.expectedStatuses?.includes(res.status)) notifyHttpError(this.#onHttpError, method, url, res.status);
525
548
  const text = await res.text();
526
549
  let data = text;
527
550
  if (text.length > 0) try {
@@ -839,6 +862,15 @@ function fetchWorkingMaxes(client) {
839
862
  function fetchExerciseHistoryList(client) {
840
863
  return getArray$1(client, "/v5/users/exercises/history", "athlete exercise history list");
841
864
  }
865
+ function fetchRecentExercises(client) {
866
+ return getArray$1(client, "/v5/users/exercises/recent", "athlete recent exercises");
867
+ }
868
+ function fetchAthleteCircuits(client, kind = "recent") {
869
+ return getArray$1(client, `/v5/users/circuits/${kind}`, `athlete ${kind} circuits`);
870
+ }
871
+ function fetchAthleteProgrammingPrograms(client) {
872
+ return getArray$1(client, "/1.0/athlete/programming/programs", "athlete programming programs");
873
+ }
842
874
  /** Free-text search over the athlete's logged exercises (FTS replacement via rankSearch). */
843
875
  async function searchExerciseHistory(client, query, limit = 20) {
844
876
  return rankSearch(await fetchExerciseHistoryList(client), query, limit);
@@ -2219,6 +2251,22 @@ function serializeWorkoutHistory(workouts, format, opts = {}) {
2219
2251
  };
2220
2252
  }
2221
2253
  //#endregion
2254
+ //#region ../js/src/util.ts
2255
+ /**
2256
+ * Drop the keys whose value is `undefined`, so the result can be passed to a function or
2257
+ * spread into an object under `exactOptionalPropertyTypes` without the per-key
2258
+ * `...(x !== undefined ? { x } : {})` dance. Required keys stay required in the result type;
2259
+ * optional ones lose `undefined` from their value type.
2260
+ *
2261
+ * Example:
2262
+ * definedProps({ metric, teamId: maybeId, date }) // omits teamId/date if they're undefined
2263
+ */
2264
+ function definedProps(obj) {
2265
+ const result = {};
2266
+ for (const [key, value] of Object.entries(obj)) if (value !== void 0) result[key] = value;
2267
+ return result;
2268
+ }
2269
+ //#endregion
2222
2270
  //#region ../js/src/workout-encode.ts
2223
2271
  const LEADERBOARD_TYPE = {
2224
2272
  completion: 0,
@@ -2572,6 +2620,84 @@ function readExercise(ex) {
2572
2620
  instruction: str(ex.instruction)
2573
2621
  };
2574
2622
  }
2623
+ const PROGRAM_KINDS = ["calendar", "fixed"];
2624
+ /**
2625
+ * Create a standalone ongoing calendar or fixed-length program.
2626
+ *
2627
+ * TrainHeroic returns both a container id and the underlying program id. They are deliberately
2628
+ * named separately here because `/3.0/coach/program/{containerId}` returns 401, while the
2629
+ * `programId` works. This write is not idempotent: callers must not blindly retry an uncertain
2630
+ * result. The live API currently accepts `name` but may generate its own title; `nameApplied`
2631
+ * reports what happened.
2632
+ */
2633
+ async function createProgram(client, args) {
2634
+ if (!PROGRAM_KINDS.includes(args.kind)) throw new Error(`Unknown program kind: ${String(args.kind)}.`);
2635
+ if (typeof args.name !== "string" || args.name.trim() === "") throw new Error("Program name must not be blank.");
2636
+ const requestedName = args.name.trim();
2637
+ const res = await client.request("POST", "/1.0/coach/programs/create", { body: {
2638
+ finite: args.kind === "fixed",
2639
+ name: requestedName
2640
+ } });
2641
+ if (!res.ok) {
2642
+ const detail = typeof res.data === "string" ? res.data : JSON.stringify(res.data);
2643
+ throw new Error(`Program create failed (HTTP ${res.status}): ${detail}`);
2644
+ }
2645
+ checkResponse(programCreateResponseSchema, res.data, "program create");
2646
+ const rec = isRecord(res.data) ? res.data : {};
2647
+ const nested = isRecord(rec.program) ? rec.program : {};
2648
+ const containerId = coerceInt(rec.id);
2649
+ const programId = coerceInt(rec.programId) ?? coerceInt(rec.group_program) ?? coerceInt(nested.id);
2650
+ if (containerId === null || programId === null) throw new Error("Program create response is missing the container id or program id.");
2651
+ if (typeof rec.title !== "string" || rec.title.trim() === "") throw new Error("Program create response is missing the assigned title.");
2652
+ const title = rec.title;
2653
+ return {
2654
+ containerId,
2655
+ programId,
2656
+ title,
2657
+ kind: args.kind,
2658
+ requestedName,
2659
+ nameApplied: title === requestedName
2660
+ };
2661
+ }
2662
+ /**
2663
+ * Delete a standalone program (`DELETE /v5/programs/{programId}`).
2664
+ *
2665
+ * The live API 401s when the path id is a list_programs container id. Pass either id: this
2666
+ * resolves a container to its `group_program` first. Team calendars are not in that list; their
2667
+ * program id is deleted as given. This is not idempotent against an unknown failure.
2668
+ */
2669
+ async function deleteProgram(client, programId) {
2670
+ if (!Number.isInteger(programId) || programId <= 0) throw new Error("Program id must be a positive integer.");
2671
+ const programs = await client.request("GET", "/1.0/coach/programs");
2672
+ if (!programs.ok || !Array.isArray(programs.data)) {
2673
+ const detail = typeof programs.data === "string" ? programs.data : JSON.stringify(programs.data);
2674
+ throw new Error(`GET /1.0/coach/programs failed (HTTP ${programs.status}): ${detail}`);
2675
+ }
2676
+ let targetId = programId;
2677
+ let containerId = null;
2678
+ for (const item of programs.data) {
2679
+ if (!isRecord(item)) continue;
2680
+ const groupProgram = coerceInt(item.group_program);
2681
+ if (coerceInt(item.id) === programId && groupProgram !== null) {
2682
+ containerId = programId;
2683
+ targetId = groupProgram;
2684
+ break;
2685
+ }
2686
+ }
2687
+ const res = await client.request("DELETE", `/v5/programs/${targetId}`, { expectedStatuses: [
2688
+ 401,
2689
+ 403,
2690
+ 404
2691
+ ] });
2692
+ if (!res.ok) {
2693
+ const detail = typeof res.data === "string" ? res.data : JSON.stringify(res.data);
2694
+ throw new Error(`Program delete failed (HTTP ${res.status}): ${detail}`);
2695
+ }
2696
+ return {
2697
+ programId: targetId,
2698
+ containerId
2699
+ };
2700
+ }
2575
2701
  /** Normalize one-or-many emails into a deduped, trimmed list. */
2576
2702
  function emailList(emails) {
2577
2703
  return [...new Set(emails.map((e) => e.trim()).filter((e) => e.length > 0))];
@@ -2669,6 +2795,52 @@ async function updateTeam(client, args) {
2669
2795
  }
2670
2796
  return res.data;
2671
2797
  }
2798
+ /** Collapse the MCP/CLI XOR flags into a single publish target. */
2799
+ function teamPublishTarget(ids) {
2800
+ if (ids.programId !== void 0 && ids.teamId !== void 0) throw new Error("Pass programId or teamId, not both.");
2801
+ if (ids.programId !== void 0) return { programId: ids.programId };
2802
+ if (ids.teamId !== void 0) return { teamId: ids.teamId };
2803
+ throw new Error("Pass programId or teamId.");
2804
+ }
2805
+ async function programIdForTeam(client, teamId) {
2806
+ if (teamId <= 0) throw new Error("teamId must be positive.");
2807
+ const team = await client.request("GET", `/v5/teams/${teamId}`);
2808
+ if (!team.ok || !isRecord(team.data)) {
2809
+ const detail = typeof team.data === "string" ? team.data : JSON.stringify(team.data);
2810
+ throw new Error(`GET /v5/teams/${teamId} failed (HTTP ${team.status}): ${detail}`);
2811
+ }
2812
+ const resolved = coerceInt(team.data.group_program) ?? coerceInt(team.data.programId);
2813
+ if (resolved === null || resolved <= 0) throw new Error(`Team ${teamId} has no group_program.`);
2814
+ return resolved;
2815
+ }
2816
+ async function resolvePublishProgramId(client, target) {
2817
+ if ("programId" in target) return target.programId;
2818
+ return programIdForTeam(client, target.teamId);
2819
+ }
2820
+ /**
2821
+ * Update a team's auto-publish settings (`POST /1.0/coach/team/updatePublishSettings`).
2822
+ * The live API 500s on a partial body; it wants the full program object from
2823
+ * `GET /3.0/coach/program/{programId}` with `pub_*` fields merged on top.
2824
+ */
2825
+ async function updateTeamPublishSettings(client, args) {
2826
+ if (Object.keys(args.patch).length === 0) throw new Error("Provide at least one pub_* field to change.");
2827
+ const programId = await resolvePublishProgramId(client, args);
2828
+ if (programId <= 0) throw new Error("programId must be positive.");
2829
+ const current = await client.request("GET", `/3.0/coach/program/${programId}`);
2830
+ if (!current.ok || !isRecord(current.data)) {
2831
+ const detail = typeof current.data === "string" ? current.data : JSON.stringify(current.data);
2832
+ throw new Error(`GET /3.0/coach/program/${programId} failed (HTTP ${current.status}): ${detail}`);
2833
+ }
2834
+ const res = await client.request("POST", "/1.0/coach/team/updatePublishSettings", { body: {
2835
+ ...current.data,
2836
+ ...args.patch
2837
+ } });
2838
+ if (!res.ok) {
2839
+ const detail = typeof res.data === "string" ? res.data : JSON.stringify(res.data);
2840
+ throw new Error(`updatePublishSettings failed (HTTP ${res.status}): ${detail}`);
2841
+ }
2842
+ return res.data;
2843
+ }
2672
2844
  /**
2673
2845
  * Copy/repeat a session to a target date on a program (`POST /2.0/coach/calendar/copyProgramWorkout`).
2674
2846
  * The API wants the target date as a structured object (with weekday and an isToday flag),
@@ -2920,6 +3092,23 @@ async function teamVolume(client, args) {
2920
3092
  totals
2921
3093
  };
2922
3094
  }
3095
+ /** Create a reusable session template in the coach library (`POST /v5/sessions/template`). */
3096
+ async function createSessionTemplate(client, args) {
3097
+ const title = args.title.trim();
3098
+ if (title === "") throw new Error("Session template title must not be blank.");
3099
+ const res = await client.request("POST", "/v5/sessions/template", { body: definedProps({
3100
+ title,
3101
+ instruction: args.instruction
3102
+ }) });
3103
+ if (!res.ok) {
3104
+ const detail = typeof res.data === "string" ? res.data : JSON.stringify(res.data);
3105
+ throw new Error(`Session template create failed (HTTP ${res.status}): ${detail}`);
3106
+ }
3107
+ if (!isRecord(res.data) || coerceInt(res.data.id) === null) throw new Error("Session template create response is missing an id.");
3108
+ return res.data;
3109
+ }
3110
+ /** First page of the coach session-template library (`GET /1.0/coach/workouts`). */
3111
+ const SESSION_TEMPLATES_LIST_PATH = "/1.0/coach/workouts?page=1&pageSize=50";
2923
3112
  //#endregion
2924
3113
  //#region ../js/src/main-lifts.ts
2925
3114
  /**
@@ -3128,22 +3317,6 @@ async function fetchRosterMainLiftPRs(client, opts = {}) {
3128
3317
  });
3129
3318
  }
3130
3319
  //#endregion
3131
- //#region ../js/src/util.ts
3132
- /**
3133
- * Drop the keys whose value is `undefined`, so the result can be passed to a function or
3134
- * spread into an object under `exactOptionalPropertyTypes` without the per-key
3135
- * `...(x !== undefined ? { x } : {})` dance. Required keys stay required in the result type;
3136
- * optional ones lose `undefined` from their value type.
3137
- *
3138
- * Example:
3139
- * definedProps({ metric, teamId: maybeId, date }) // omits teamId/date if they're undefined
3140
- */
3141
- function definedProps(obj) {
3142
- const result = {};
3143
- for (const [key, value] of Object.entries(obj)) if (value !== void 0) result[key] = value;
3144
- return result;
3145
- }
3146
- //#endregion
3147
3320
  //#region ../js/src/messaging.ts
3148
3321
  const BUCKETS = [
3149
3322
  ["team", "teams"],
@@ -3215,6 +3388,8 @@ var MemoryLibraryCache = class {
3215
3388
  //#region ../js/src/exercise-index.ts
3216
3389
  const LIBRARY_PATH = "/v5/exerciseLibrary/all";
3217
3390
  const CREATE_PATH = "/2.0/coach/exercise/create";
3391
+ const UPDATE_PATH = (id) => `/2.0/coach/exercise/update/${id}`;
3392
+ const DELETE_PATH = (id) => `/v5/exercises/${id}`;
3218
3393
  const TTL_MS$1 = 6048e5;
3219
3394
  function toStored(ex) {
3220
3395
  const id = coerceInt(ex.id);
@@ -3343,12 +3518,18 @@ var ExerciseLibrary = class {
3343
3518
  };
3344
3519
  }
3345
3520
  async create(body) {
3521
+ return this.#writeThrough(CREATE_PATH, body, "create");
3522
+ }
3523
+ async update(id, body) {
3524
+ return this.#writeThrough(UPDATE_PATH(id), body, "update");
3525
+ }
3526
+ async #writeThrough(path, body, label) {
3346
3527
  await this.ensureFresh();
3347
- const res = await this.#client.request("POST", CREATE_PATH, { body });
3348
- if (!res.ok) throw new Error(`Exercise create failed (HTTP ${res.status}).`);
3528
+ const res = await this.#client.request("POST", path, { body });
3529
+ if (!res.ok) throw new Error(`Exercise ${label} failed (HTTP ${res.status}).`);
3349
3530
  const ex = unwrapEnvelope(res.data);
3350
3531
  if (ex && typeof ex === "object") {
3351
- checkResponse(exerciseResponseSchema, ex, "exercise create");
3532
+ checkResponse(exerciseResponseSchema, ex, `exercise ${label}`);
3352
3533
  const s = toStored(ex);
3353
3534
  if (s) {
3354
3535
  this.#byId.set(s.id, s);
@@ -3357,6 +3538,15 @@ var ExerciseLibrary = class {
3357
3538
  }
3358
3539
  return ex;
3359
3540
  }
3541
+ async remove(id) {
3542
+ const res = await this.#client.request("DELETE", DELETE_PATH(id), { expectedStatuses: [
3543
+ 401,
3544
+ 403,
3545
+ 404
3546
+ ] });
3547
+ if (!res.ok) throw new Error(`Exercise delete failed (HTTP ${res.status}).`);
3548
+ await this.recordDelete(id);
3549
+ }
3360
3550
  async recordDelete(id) {
3361
3551
  await this.ensureFresh();
3362
3552
  if (this.#byId.delete(id)) await this.#persist();
@@ -3486,8 +3676,11 @@ Coach — manage a roster (needs a coach account):
3486
3676
  coach athlete-restore --athletes <id,id,...>
3487
3677
 
3488
3678
  teams & join codes:
3679
+ coach program-create --kind calendar|fixed --name "..."
3680
+ coach program-delete --program <id> --yes
3489
3681
  coach team-create --title "..."
3490
3682
  coach team-update --team <id> [--title "..."] [--group-program <id>]
3683
+ coach team-publish-settings (--team <id> | --program <id>) [--pub-enabled 0|1] --yes
3491
3684
  coach team-delete --team <id> --yes
3492
3685
  coach team-code-create --team <id> [--type N]
3493
3686
  coach team-code-delete --code <id> --yes (--code is the id from team-code-create, not the join-code number)
@@ -3496,6 +3689,9 @@ Coach — manage a roster (needs a coach account):
3496
3689
  coach session-copy --to-program <id> --pw <id> --to-date Y-M-D
3497
3690
  coach session-unpublish --pw <id> --yes
3498
3691
  coach session-save-template --workout <id>
3692
+ coach session-templates
3693
+ coach session-template-create --title "..." [--instruction "..."]
3694
+ coach session-template-delete --id <id> --yes
3499
3695
 
3500
3696
  analytics (curated metrics; for team training volume/recency use roster-activity --metric instead):
3501
3697
  coach analytics-query [--metric <key>] [--team <id>] [--users id,id] [--exercise <id>] [--date|--start|--end Y-M-D] [--use-metric]
@@ -3508,6 +3704,8 @@ Coach — manage a roster (needs a coach account):
3508
3704
  coach exercise get <id>
3509
3705
  coach exercise sync [--force]
3510
3706
  coach exercise create <json>|--file f
3707
+ coach exercise update <id> <json>|--file f
3708
+ coach exercise delete <id> --yes
3511
3709
  coach exercise forget <id> --yes
3512
3710
  coach exercise stats
3513
3711
 
@@ -3530,6 +3728,9 @@ Athlete — the logged-in user's own training (a coach account works too):
3530
3728
  athlete workouts --start Y-M-D --end Y-M-D [--raw] [--logged-only] [--limit N] [--summary] [--format json|csv|text] (reads what you did; --format exports history with reps/weight broken out; for the log ids use 'athlete log-targets')
3531
3729
  athlete log-targets --start Y-M-D --end Y-M-D [--program <title>|--program-id <id>|--team <id>] [--raw] (the savedWorkoutSetId + savedWorkoutSetExerciseId log-set needs; --program narrows when several workouts share a date)
3532
3730
  athlete exercises [--q <text>] [--limit N]
3731
+ athlete recent-exercises
3732
+ athlete circuits [--kind recent|history]
3733
+ athlete programs
3533
3734
  athlete history <exerciseId> [--raw]
3534
3735
  athlete prs <exerciseId>
3535
3736
  athlete stats <exerciseId> --date Y-M-D
@@ -3650,6 +3851,20 @@ async function cmdExercise(client, rest) {
3650
3851
  const exercise = validate(exerciseCreateSchema, body, "exercise");
3651
3852
  return out(await lib.create(exercise));
3652
3853
  }
3854
+ case "update": {
3855
+ const { values, positionals } = parse(a, { file: { type: "string" } });
3856
+ const id = toInt(need(positionals[0], "coach exercise update <id> <json>|--file f"), "id");
3857
+ const body = await jsonInput(positionals[1], values.file);
3858
+ const exercise = validate(exerciseCreateSchema, body, "exercise");
3859
+ return out(await lib.update(id, exercise));
3860
+ }
3861
+ case "delete": {
3862
+ const { values, positionals } = parse(a, { yes: { type: "boolean" } });
3863
+ const id = toInt(need(positionals[0], "coach exercise delete <id> --yes"), "id");
3864
+ if (values.yes !== true) fail(`add --yes to delete exercise ${id} from TrainHeroic.`);
3865
+ await lib.remove(id);
3866
+ return out({ deleted: id });
3867
+ }
3653
3868
  case "forget": {
3654
3869
  const { values, positionals } = parse(a, { yes: { type: "boolean" } });
3655
3870
  const id = toInt(need(positionals[0], "coach exercise forget <id> --yes"), "id");
@@ -3658,7 +3873,7 @@ async function cmdExercise(client, rest) {
3658
3873
  return out({ forgotten: id });
3659
3874
  }
3660
3875
  case "stats": return out(await lib.stats());
3661
- default: return fail("usage: trainheroic coach exercise <resolve|search|get|sync|create|forget|stats>");
3876
+ default: return fail("usage: trainheroic coach exercise <resolve|search|get|sync|create|update|delete|forget|stats>");
3662
3877
  }
3663
3878
  }
3664
3879
  async function cmdWorkoutBuild(client, a) {
@@ -4062,6 +4277,14 @@ async function cmdAthlete(client, rest) {
4062
4277
  const q = values.q;
4063
4278
  return out(q !== void 0 ? await searchExerciseHistory(client, q, limit) : await fetchExerciseHistoryList(client));
4064
4279
  }
4280
+ case "recent-exercises": return out(await fetchRecentExercises(client));
4281
+ case "circuits": {
4282
+ const { values } = parse(a, { kind: { type: "string" } });
4283
+ const kind = values.kind ?? "recent";
4284
+ if (kind !== "recent" && kind !== "history") fail("athlete circuits --kind recent|history");
4285
+ return out(await fetchAthleteCircuits(client, kind));
4286
+ }
4287
+ case "programs": return out(await fetchAthleteProgrammingPrograms(client));
4065
4288
  case "history": {
4066
4289
  const { values, positionals } = parse(a, { raw: { type: "boolean" } });
4067
4290
  const detail = await fetchExerciseHistoryDetail(client, toInt(need(positionals[0], "athlete history <exerciseId>"), "exerciseId"), await resolveAthleteUserId(client));
@@ -4095,7 +4318,7 @@ async function cmdAthlete(client, rest) {
4095
4318
  case "log-session": return cmdAthleteLogSession(client, a);
4096
4319
  case "session-remove": return cmdAthleteSessionRemove(client, a);
4097
4320
  case "swap-exercise": return cmdAthleteSwapExercise(client, a);
4098
- default: return fail("usage: trainheroic athlete <whoami|profile|prefs|workouts|log-targets|exercises|history|prs|stats|working-maxes|leaderboard|export|log-set|prescribe-set|log-session|session-remove|swap-exercise>");
4321
+ default: return fail("usage: trainheroic athlete <whoami|profile|prefs|workouts|log-targets|exercises|recent-exercises|circuits|programs|history|prs|stats|working-maxes|leaderboard|export|log-set|prescribe-set|log-session|session-remove|swap-exercise>");
4099
4322
  }
4100
4323
  }
4101
4324
  async function cmdSkill(rest) {
@@ -4139,7 +4362,7 @@ async function cmdInstallSkill() {
4139
4362
  }
4140
4363
  out({ installed });
4141
4364
  }
4142
- 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>";
4365
+ const COACH_USAGE = "usage: trainheroic coach <head-coach|athletes|programs|teams|notifications|notifications-list|subscriptions|prescription-templates|analytics|program <id>|program-create|program-delete|team <id>|team-codes <id>|roster-activity|team-volume|athlete-training|athlete-lift-history|athlete-team-calendar|main-lift-prs|athlete-workouts|log-set|log-session|prescribe-set|swap-exercise|athlete-invite|athlete-archive|athlete-restore|team-create|team-update|team-publish-settings|team-delete|team-code-create|team-code-delete|session-copy|session-unpublish|session-save-template|session-templates|session-template-create|session-template-delete|analytics-query|exercise|workout|message>";
4143
4366
  const COACH_LOG_SET_USAGE = "coach log-set --athlete <id> --date Y-M-D --set <savedWorkoutSetId> <resultsJson> --yes";
4144
4367
  async function cmdCoachLogSet(client, a) {
4145
4368
  const { values, positionals } = parse(a, {
@@ -4327,6 +4550,30 @@ async function cmdCoachTeamCreate(client, a) {
4327
4550
  const { values } = parse(a, { title: { type: "string" } });
4328
4551
  return out(await mutate(client, "POST", "/1.0/coach/team/createWithTitleAndCode", { title: need(values.title, "coach team-create --title \"...\"") }));
4329
4552
  }
4553
+ async function cmdCoachProgramCreate(client, a) {
4554
+ const usage = "coach program-create --kind calendar|fixed --name \"...\"";
4555
+ const { values } = parse(a, {
4556
+ kind: { type: "string" },
4557
+ name: { type: "string" }
4558
+ });
4559
+ const kind = need(values.kind, usage);
4560
+ const name = need(values.name, usage);
4561
+ if (!PROGRAM_KINDS.includes(kind)) fail(usage);
4562
+ return out(await createProgram(client, {
4563
+ kind,
4564
+ name
4565
+ }));
4566
+ }
4567
+ async function cmdCoachProgramDelete(client, a) {
4568
+ const usage = "coach program-delete --program <id> --yes";
4569
+ const { values } = parse(a, {
4570
+ program: { type: "string" },
4571
+ yes: { type: "boolean" }
4572
+ });
4573
+ const programId = toInt(need(values.program, usage), "--program");
4574
+ if (values.yes !== true) fail(`deleting program ${programId} removes the standalone calendar; add --yes.`);
4575
+ return out(await deleteProgram(client, programId));
4576
+ }
4330
4577
  async function cmdCoachTeamUpdate(client, a) {
4331
4578
  const usage = "coach team-update --team <id> [--title \"...\"] [--group-program <id>] (at least one of --title / --group-program)";
4332
4579
  const { values } = parse(a, {
@@ -4401,6 +4648,58 @@ async function cmdCoachSessionSaveTemplate(client, a) {
4401
4648
  const { values } = parse(a, { workout: { type: "string" } });
4402
4649
  return out(await mutate(client, "POST", `/2.0/coach/calendar/programWorkout/saveWorkoutAsTemplate/${toInt(need(values.workout, usage), "--workout")}`));
4403
4650
  }
4651
+ async function cmdCoachSessionTemplateCreate(client, a) {
4652
+ const usage = "coach session-template-create --title \"...\" [--instruction \"...\"]";
4653
+ const { values } = parse(a, {
4654
+ title: { type: "string" },
4655
+ instruction: { type: "string" }
4656
+ });
4657
+ const title = need(values.title, usage);
4658
+ const instruction = values.instruction;
4659
+ return out(await createSessionTemplate(client, validate(sessionTemplateCreateSchema, definedProps({
4660
+ title,
4661
+ instruction
4662
+ }), "session template")));
4663
+ }
4664
+ async function cmdCoachSessionTemplateDelete(client, a) {
4665
+ const usage = "coach session-template-delete --id <id> --yes";
4666
+ const { values } = parse(a, {
4667
+ id: { type: "string" },
4668
+ yes: { type: "boolean" }
4669
+ });
4670
+ const id = toInt(need(values.id, usage), "--id");
4671
+ if (values.yes !== true) fail(`add --yes to delete session template ${id}.`);
4672
+ return out(await mutate(client, "DELETE", `/v5/sessions/template/${id}`));
4673
+ }
4674
+ async function cmdCoachTeamPublishSettings(client, a) {
4675
+ const usage = "coach team-publish-settings (--team <id> | --program <id>) [--pub-enabled 0|1] [--pub-days ...] [--pub-time ...] [--pub-timezone ...] --yes";
4676
+ const { values } = parse(a, {
4677
+ team: { type: "string" },
4678
+ program: { type: "string" },
4679
+ "pub-enabled": { type: "string" },
4680
+ "pub-days": { type: "string" },
4681
+ "pub-time": { type: "string" },
4682
+ "pub-timezone": { type: "string" },
4683
+ yes: { type: "boolean" }
4684
+ });
4685
+ const teamRaw = values.team;
4686
+ const programRaw = values.program;
4687
+ if (teamRaw === void 0 === (programRaw === void 0)) fail(usage);
4688
+ if (values.yes !== true) fail("changing auto-publish is athlete-facing; add --yes.");
4689
+ const patch = validate(teamPublishPatchSchema, definedProps({
4690
+ pub_enabled: values["pub-enabled"] !== void 0 ? toInt(values["pub-enabled"], "--pub-enabled") : void 0,
4691
+ pub_days: values["pub-days"],
4692
+ pub_time: values["pub-time"],
4693
+ pub_timezone: values["pub-timezone"]
4694
+ }), "publish settings");
4695
+ return out(await updateTeamPublishSettings(client, {
4696
+ ...teamPublishTarget(definedProps({
4697
+ teamId: teamRaw !== void 0 ? toInt(teamRaw, "--team") : void 0,
4698
+ programId: programRaw !== void 0 ? toInt(programRaw, "--program") : void 0
4699
+ })),
4700
+ patch
4701
+ }));
4702
+ }
4404
4703
  async function cmdCoachAnalyticsQuery(client, a) {
4405
4704
  const { values } = parse(a, {
4406
4705
  metric: { type: "string" },
@@ -4487,15 +4786,25 @@ async function cmdCoachMainLiftPrs(client, a) {
4487
4786
  ...subset ? { athleteIds: subset } : {}
4488
4787
  }));
4489
4788
  }
4789
+ const COACH_SIMPLE_GETS = {
4790
+ "head-coach": "/v5/headCoach",
4791
+ athletes: "/v5/athletes",
4792
+ programs: "/1.0/coach/programs",
4793
+ teams: "/1.0/coach/teams",
4794
+ notifications: "/v5/notifications/counts",
4795
+ "notifications-list": "/v5/notifications",
4796
+ subscriptions: "/1.0/coach/subscriptions",
4797
+ "prescription-templates": "/2.0/coach/workoutSetExercise/template",
4798
+ analytics: "/v5/analytics",
4799
+ "session-templates": SESSION_TEMPLATES_LIST_PATH
4800
+ };
4490
4801
  async function cmdCoach(client, rest) {
4491
4802
  const [sub, ...a] = rest;
4803
+ if (sub !== void 0) {
4804
+ const path = COACH_SIMPLE_GETS[sub];
4805
+ if (path !== void 0) return out(await get(client, path));
4806
+ }
4492
4807
  switch (sub) {
4493
- case "head-coach": return out(await get(client, "/v5/headCoach"));
4494
- case "athletes": return out(await get(client, "/v5/athletes"));
4495
- case "programs": return out(await get(client, "/1.0/coach/programs"));
4496
- case "teams": return out(await get(client, "/1.0/coach/teams"));
4497
- case "notifications": return out(await get(client, "/v5/notifications/counts"));
4498
- case "analytics": return out(await get(client, "/v5/analytics"));
4499
4808
  case "program": return out(await get(client, `/3.0/coach/program/${encodeURIComponent(need(a[0], "coach program <id>"))}`));
4500
4809
  case "team": return out(await get(client, `/v5/teams/${encodeURIComponent(need(a[0], "coach team <id>"))}`));
4501
4810
  case "team-codes": return out(await get(client, `/v5/teams/${encodeURIComponent(need(a[0], "coach team-codes <id>"))}/teamCodes`));
@@ -4503,6 +4812,10 @@ async function cmdCoach(client, rest) {
4503
4812
  case "team-volume": return cmdCoachTeamVolume(client, a);
4504
4813
  case "athlete-training": return cmdCoachAthleteTraining(client, a);
4505
4814
  case "athlete-lift-history": return cmdCoachAthleteLiftHistory(client, a);
4815
+ case "athlete-team-calendar": {
4816
+ const { values } = parse(a, { athlete: { type: "string" } });
4817
+ return out(await get(client, `/v5/calendars/athletes/${toInt(need(values.athlete, "coach athlete-team-calendar --athlete <id>"), "--athlete")}/coachAthleteTeam`));
4818
+ }
4506
4819
  case "main-lift-prs": return cmdCoachMainLiftPrs(client, a);
4507
4820
  case "athlete-workouts": return cmdCoachAthleteWorkouts(client, a);
4508
4821
  case "log-set": return cmdCoachLogSet(client, a);
@@ -4513,13 +4826,18 @@ async function cmdCoach(client, rest) {
4513
4826
  case "athlete-archive": return cmdCoachAthleteArchive(client, a);
4514
4827
  case "athlete-restore": return cmdCoachAthleteRestore(client, a);
4515
4828
  case "team-create": return cmdCoachTeamCreate(client, a);
4829
+ case "program-create": return cmdCoachProgramCreate(client, a);
4830
+ case "program-delete": return cmdCoachProgramDelete(client, a);
4516
4831
  case "team-update": return cmdCoachTeamUpdate(client, a);
4832
+ case "team-publish-settings": return cmdCoachTeamPublishSettings(client, a);
4517
4833
  case "team-delete": return cmdCoachTeamDelete(client, a);
4518
4834
  case "team-code-create": return cmdCoachTeamCodeCreate(client, a);
4519
4835
  case "team-code-delete": return cmdCoachTeamCodeDelete(client, a);
4520
4836
  case "session-copy": return cmdCoachSessionCopy(client, a);
4521
4837
  case "session-unpublish": return cmdCoachSessionUnpublish(client, a);
4522
4838
  case "session-save-template": return cmdCoachSessionSaveTemplate(client, a);
4839
+ case "session-template-create": return cmdCoachSessionTemplateCreate(client, a);
4840
+ case "session-template-delete": return cmdCoachSessionTemplateDelete(client, a);
4523
4841
  case "analytics-query": return cmdCoachAnalyticsQuery(client, a);
4524
4842
  case "exercise": return cmdExercise(client, a);
4525
4843
  case "workout": return cmdWorkout(client, a);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trainheroic-unofficial/cli",
3
- "version": "3.1.0",
3
+ "version": "3.2.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": "3.1.0",
25
- "@trainheroic-unofficial/js": "3.1.0"
24
+ "@trainheroic-unofficial/dto": "3.2.0",
25
+ "@trainheroic-unofficial/js": "3.2.0"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/node": "^26.2.0",
@@ -105,8 +105,8 @@ startDate?/endDate? }`.
105
105
 
106
106
  ## Still unexplored
107
107
 
108
- - `PUT /1.0/athlete/savedworkout/{id}` (whole-workout sync; not needed for per-set logging,
109
- which uses the two-step path above).
110
- - `GET /v5/users/circuits/{recent,history}` (circuit history; shapes mirror the exercise
111
- history list).
112
- - `GET /1.0/athlete/programming/programs` (subscribed programs; empty for the test account).
108
+ Living status table: `.agents/skills/reverse-engineer-api/coverage.md`.
109
+
110
+ In-scope athlete reads are wrapped (`athlete_circuits`, `athlete_programming_programs`,
111
+ `athlete_recent_exercises`). Closed without a wrap: `PUT /1.0/athlete/savedworkout/{id}`
112
+ (per-set logging is enough); working-max write (read exists; set/update never found).
@@ -86,18 +86,18 @@ response shape, or an area not covered here.
86
86
 
87
87
  ## What you can do
88
88
 
89
- | Area | How |
90
- | ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
91
- | Athletes | `$TH coach athletes`; `coach athlete-invite\|athlete-archive\|athlete-restore` |
92
- | Teams / join codes | `$TH coach teams\|team <id>\|team-codes <id>`; `coach team-create\|team-update\|team-delete\|team-code-create\|team-code-delete` |
93
- | Programs | `$TH coach programs`, `$TH coach program <id>` |
94
- | Exercises | `$TH coach exercise resolve\|search\|get\|sync\|create\|forget\|stats` (below) |
95
- | Sessions / workouts | `$TH coach workout build\|read\|publish\|remove`; `coach session-copy\|session-unpublish\|session-save-template` |
96
- | Roster training | `$TH coach roster-activity\|athlete-training\|athlete-lift-history\|athlete-workouts` (read another athlete's training) |
97
- | Team volume (windowed) | `$TH coach team-volume --team <id>\|--athletes <ids> --start Y-M-D --end Y-M-D` — date-scoped team volume (roster-activity is all-time) |
98
- | Log for an athlete | `$TH coach log-set` (by set id) or `coach log-session` (by exercise) — record a roster athlete's reps/weights (real athletes only; see below) |
99
- | Messaging | `$TH coach message list\|read\|draft\|send\|delete` (below) |
100
- | Analytics | `$TH coach analytics` (category list); `$TH coach analytics-query --metric <key> ...` (the report) |
89
+ | Area | How |
90
+ | ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
91
+ | Athletes | `$TH coach athletes`; `coach athlete-invite\|athlete-archive\|athlete-restore` |
92
+ | Teams / join codes | `$TH coach teams\|team <id>\|team-codes <id>`; `coach team-create\|team-update\|team-delete\|team-code-create\|team-code-delete` |
93
+ | Programs | `$TH coach programs`, `$TH coach program <id>`, `$TH coach program-create --kind calendar\|fixed --name "..."`, `$TH coach program-delete --program <id> --yes` |
94
+ | Exercises | `$TH coach exercise resolve\|search\|get\|sync\|create\|delete\|forget\|stats` (below) |
95
+ | Sessions / workouts | `$TH coach workout build\|read\|publish\|remove`; `coach session-copy\|session-unpublish\|session-save-template\|session-templates` |
96
+ | Roster training | `$TH coach roster-activity\|athlete-training\|athlete-lift-history\|athlete-workouts` (read another athlete's training) |
97
+ | Team volume (windowed) | `$TH coach team-volume --team <id>\|--athletes <ids> --start Y-M-D --end Y-M-D` — date-scoped team volume (roster-activity is all-time) |
98
+ | Log for an athlete | `$TH coach log-set` (by set id) or `coach log-session` (by exercise) — record a roster athlete's reps/weights (real athletes only; see below) |
99
+ | Messaging | `$TH coach message list\|read\|draft\|send\|delete` (below) |
100
+ | Analytics | `$TH coach analytics` (category list); `$TH coach analytics-query --metric <key> ...` (the report) |
101
101
 
102
102
  ## Resolving exercises
103
103
 
@@ -119,7 +119,8 @@ deleting one via the API, drop it from the mirror:
119
119
 
120
120
  ```bash
121
121
  $TH coach exercise create '{"title":"Sandbag Clean","param_1_type":3,"param_2_type":1}'
122
- $TH coach exercise forget 7721170 --yes # cache-only, run after an API delete
122
+ $TH coach exercise delete 7721170 --yes # live DELETE /v5/exercises/{id} + cache
123
+ $TH coach exercise forget 7721170 --yes # cache-only, if you already deleted via the API
123
124
  ```
124
125
 
125
126
  `$TH coach exercise stats` shows the cached row count.
@@ -286,16 +286,18 @@ Deletes an access code. No request body needed.
286
286
 
287
287
  ### Programs
288
288
 
289
- | Method | Endpoint | Description |
290
- | ------ | ------------------------------- | ------------------------------- |
291
- | GET | `/v5/programs` | List programs |
292
- | GET | `/v5/programs/new` | New programs |
293
- | GET | `/v5/programs/free` | Free programs |
294
- | GET | `/v5/programs/fixed` | Fixed programs |
295
- | GET | `/1.0/coach/programs` | Coach programs list |
296
- | GET | `/1.0/coach/programs/edit/{id}` | Program edit data |
297
- | GET | `/3.0/coach/program/{id}` | Program detail (full structure) |
298
- | GET | `/1.0/coach/subscriptions` | Program subscriptions |
289
+ | Method | Endpoint | Description |
290
+ | ------ | ------------------------------- | --------------------------- |
291
+ | GET | `/v5/programs` | List programs |
292
+ | GET | `/v5/programs/new` | New programs |
293
+ | GET | `/v5/programs/free` | Free programs |
294
+ | GET | `/v5/programs/fixed` | Fixed programs |
295
+ | GET | `/1.0/coach/programs` | Coach programs list |
296
+ | POST | `/1.0/coach/programs/create` | Create a standalone program |
297
+ | DELETE | `/v5/programs/{programId}` | Delete a standalone program |
298
+ | GET | `/1.0/coach/programs/edit/{id}` | Program edit data |
299
+ | GET | `/3.0/coach/program/{id}` | Program metadata/detail |
300
+ | GET | `/1.0/coach/subscriptions` | Program subscriptions |
299
301
 
300
302
  #### `GET /3.0/coach/program/{id}` Response
301
303
 
@@ -336,6 +338,22 @@ Deletes an access code. No request body needed.
336
338
  ]
337
339
  ```
338
340
 
341
+ #### `POST /1.0/coach/programs/create`
342
+
343
+ Send `{ "finite": false, "name": "..." }` for an ongoing calendar or `finite: true` for a
344
+ fixed-length program. The endpoint is not idempotent. Its response contains two different ids:
345
+ `id` is the container returned by `GET /1.0/coach/programs`, while `programId` (also
346
+ `group_program`) is the actual program id used by `/3.0/coach/program/{id}` and workout writes.
347
+ The live API may ignore `name` and assign a generated title; use the response's `title` as truth.
348
+
349
+ #### `DELETE /v5/programs/{programId}`
350
+
351
+ Deletes a standalone calendar or fixed program. The path id must be the underlying
352
+ `programId` (`group_program`), not the `list_programs` container `id` — a container id
353
+ returns 401. The SDK/`program_delete` tool resolves either id. Response body is the string
354
+ `Successfully deleted program`. There is no update/rename endpoint; PUT on this path 405s
355
+ (`Supported methods: DELETE`).
356
+
339
357
  ---
340
358
 
341
359
  ### Exercises
@@ -1360,15 +1378,8 @@ Updates the auto-publish settings for a team's program. Takes the full program o
1360
1378
 
1361
1379
  ## Still Unexplored
1362
1380
 
1363
- - Program update (title, description, settings) — PUT/POST patterns return 405/404
1364
- - Athlete remove from specific team (endpoint pattern not found via probing)
1365
- - Working max set/update from coach side for specific athletes
1366
- - Marketplace endpoints (publishing, pricing, purchases)
1367
- - Notification management (mark read, dismiss — 401/404 on tested patterns)
1368
- - `apis.trainheroic.com/user` endpoint (uses `api-token` header, returns full user profile with teams)
1369
- - Circuit creation (vs superset — circuits may use different block type or field)
1370
- - Prescription template CRUD
1371
- - Coach preferences update (PATCH/PUT on `2.0/coach/prefs` returns 403/405)
1372
- - Library settings
1373
- - Session template update (edit existing template)
1374
- - Workout set reorder / move exercises between blocks
1381
+ Living status table (remaining wrap gaps vs closed-without-a-wrap):
1382
+ `.agents/skills/reverse-engineer-api/coverage.md`.
1383
+
1384
+ Still to wrap: none (in-scope). See coverage.md Closed without a wrap for out-of-scope
1385
+ and unreachable paths.