forge-openclaw-plugin 0.2.108 → 0.2.110
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/assets/{activity-page-DWHZ8_sJ.js → activity-page-BdeoV3N4.js} +1 -1
- package/dist/assets/{ai-surface-workspace-DPygfyhc.js → ai-surface-workspace-BCbQUekv.js} +1 -1
- package/dist/assets/{atlas-panel-D261RUQF.js → atlas-panel-DTnRBOZx.js} +1 -1
- package/dist/assets/{calendar-page-BQbJkdPF.js → calendar-page-YDexXy_e.js} +1 -1
- package/dist/assets/{calendar-rules-BoFsuvZ8.js → calendar-rules-B_aOcMi3.js} +1 -1
- package/dist/assets/{calendar-week-toolbar-LetevPI7.js → calendar-week-toolbar-BTbIzq3e.js} +1 -1
- package/dist/assets/{companion-sync-lab-page-Bid-4B8W.js → companion-sync-lab-page-DKouMut9.js} +1 -1
- package/dist/assets/{daily-metrics-dashboard-CqnGJNeI.js → daily-metrics-dashboard-B3UCGG1t.js} +1 -1
- package/dist/assets/{entity-note-count-link-VMURwBMi.js → entity-note-count-link-DUxobQUt.js} +1 -1
- package/dist/assets/{entity-notes-surface-DGXcyNzo.js → entity-notes-surface-BdHBn8rx.js} +1 -1
- package/dist/assets/{execution-board-BGf6zZqJ.js → execution-board-R5-oyf-Z.js} +1 -1
- package/dist/assets/{faceted-token-search-CAsZrhZ4.js → faceted-token-search-DtO6OUwQ.js} +1 -1
- package/dist/assets/{flagship-signal-deck-DJsq3jn2.js → flagship-signal-deck-B9k46sWA.js} +1 -1
- package/dist/assets/{floating-action-menu-B3tQStUN.js → floating-action-menu-DBzfnJOx.js} +1 -1
- package/dist/assets/{goal-detail-page-DBs-9wpk.js → goal-detail-page-Mr_gnZ2l.js} +1 -1
- package/dist/assets/{goals-page-CPmhjsG-.js → goals-page-BG7FuqK1.js} +1 -1
- package/dist/assets/{habits-page-DkW8zT6_.js → habits-page-CGdaOqL3.js} +1 -1
- package/dist/assets/{index-BhkubYaC.js → index-BP9__l6C.js} +2 -2
- package/dist/assets/{insight-flow-dialog-BvgRjkPi.js → insight-flow-dialog-BUv06Vn-.js} +1 -1
- package/dist/assets/{insights-page-Dtij6pm5.js → insights-page-BgD1_1we.js} +1 -1
- package/dist/assets/{kanban-page-R1x5hUU-.js → kanban-page-DvZSN-Bi.js} +1 -1
- package/dist/assets/{knowledge-graph-page-BRBB5Vvz.js → knowledge-graph-page-BXWXtPvo.js} +1 -1
- package/dist/assets/{life-force-page-DGPWKM9I.js → life-force-page-CwjHvpzu.js} +1 -1
- package/dist/assets/{life-force-workspace-DoRIQoU_.js → life-force-workspace-Ct70SsNQ.js} +1 -1
- package/dist/assets/{metric-tile-NJiFcFxW.js → metric-tile-DCxLxNli.js} +1 -1
- package/dist/assets/{movement-page-Dk8aV737.js → movement-page-C06ebiYk.js} +1 -1
- package/dist/assets/{note-markdown-CZHjJDve.js → note-markdown-3wB52NOn.js} +1 -1
- package/dist/assets/{note-tags-input-DFpxZHPg.js → note-tags-input-Blg5Gqz_.js} +1 -1
- package/dist/assets/{notes-page-r3kymlqg.js → notes-page-CSkjizyK.js} +1 -1
- package/dist/assets/{open-in-graph-button-B_XHtHZD.js → open-in-graph-button-CDHxzS8B.js} +1 -1
- package/dist/assets/{orbit-map-C_xy4kYC.js → orbit-map-OV-GcUZl.js} +1 -1
- package/dist/assets/{overview-page-Dwg4uYe9.js → overview-page-Cw3pI34n.js} +1 -1
- package/dist/assets/{page-hero-DzEsy8i5.js → page-hero-DgnhI5es.js} +1 -1
- package/dist/assets/{pill-cluster-DcBUeEMT.js → pill-cluster-DIGkIvKN.js} +1 -1
- package/dist/assets/{preference-entity-handoff-button-BX2n07ob.js → preference-entity-handoff-button-LT_GBuqB.js} +1 -1
- package/dist/assets/{preferences-page-BSnwiWBt.js → preferences-page-Dkvz7nkU.js} +1 -1
- package/dist/assets/{project-collections-BR6YdlCZ.js → project-collections-BsAT8WYE.js} +1 -1
- package/dist/assets/{project-detail-page-DeYshcCb.js → project-detail-page-DsJUWg8k.js} +1 -1
- package/dist/assets/{project-management-hierarchy-page-Bhdt79Ea.js → project-management-hierarchy-page-CIy0wAp8.js} +1 -1
- package/dist/assets/{project-management-section-nav-DnXuWUfe.js → project-management-section-nav-ClB2S1FW.js} +1 -1
- package/dist/assets/{projects-page-BA9W0ZPk.js → projects-page-Da1bZLSH.js} +1 -1
- package/dist/assets/{psyche-behaviors-page-DpTj53GI.js → psyche-behaviors-page-D0uwf78o.js} +1 -1
- package/dist/assets/{psyche-flashcards-page-CV58hAJA.js → psyche-flashcards-page-e_qwwsOf.js} +1 -1
- package/dist/assets/{psyche-goal-map-page-C07CALFg.js → psyche-goal-map-page-BIY028Wx.js} +1 -1
- package/dist/assets/{psyche-graph-CP7mxfMP.js → psyche-graph-Y1UKALEm.js} +1 -1
- package/dist/assets/{psyche-metrics-page-CY8e9R0D.js → psyche-metrics-page-DDkGJzo_.js} +1 -1
- package/dist/assets/{psyche-mode-guide-page-DYt6AmHl.js → psyche-mode-guide-page-C7mD9uiv.js} +1 -1
- package/dist/assets/{psyche-modes-page-Dd77kTtJ.js → psyche-modes-page-RUdaOQWr.js} +1 -1
- package/dist/assets/{psyche-page-DNXZjIKp.js → psyche-page-D3FZy__c.js} +1 -1
- package/dist/assets/{psyche-patterns-page-DxGzpeT5.js → psyche-patterns-page-BSD35F41.js} +1 -1
- package/dist/assets/{psyche-questionnaire-builder-page-5EQctRHO.js → psyche-questionnaire-builder-page-BpgUTMgj.js} +1 -1
- package/dist/assets/{psyche-questionnaire-detail-page-W8nhUGAc.js → psyche-questionnaire-detail-page-DwjyjNhg.js} +1 -1
- package/dist/assets/{psyche-questionnaire-run-detail-page-DVwzSuqg.js → psyche-questionnaire-run-detail-page-mJ-DgeB-.js} +1 -1
- package/dist/assets/{psyche-questionnaire-run-page-BHResQgL.js → psyche-questionnaire-run-page-YuMBkH1G.js} +1 -1
- package/dist/assets/{psyche-questionnaires-page-DFTOXpyp.js → psyche-questionnaires-page-CNglToKh.js} +1 -1
- package/dist/assets/{psyche-report-detail-page-BqDE_tf7.js → psyche-report-detail-page-CV6tbLxz.js} +1 -1
- package/dist/assets/{psyche-reports-page-B75pDz0l.js → psyche-reports-page-BEOe8OPA.js} +1 -1
- package/dist/assets/{psyche-schemas-beliefs-page-BjSO4tYL.js → psyche-schemas-beliefs-page-KIRqmO8C.js} +1 -1
- package/dist/assets/{psyche-screen-time-page-B7lKf1g7.js → psyche-screen-time-page-DvXuwgU1.js} +1 -1
- package/dist/assets/{psyche-self-observation-page-C6RMThwc.js → psyche-self-observation-page-E6yDPBm1.js} +1 -1
- package/dist/assets/{psyche-values-page-1O158mIJ.js → psyche-values-page-CSLG7C6a.js} +1 -1
- package/dist/assets/{report-chain-fields-CyJ_VFY5.js → report-chain-fields-BYEp3tRr.js} +1 -1
- package/dist/assets/{rewards-page-sPlDYuVo.js → rewards-page-pAa_MIte.js} +1 -1
- package/dist/assets/{scheduling-rules-editor-DGgcBs1W.js → scheduling-rules-editor-BmGrjC9q.js} +1 -1
- package/dist/assets/{schema-badge-Do-YvNHm.js → schema-badge-IVJ4SoeC.js} +1 -1
- package/dist/assets/{select-menu-CAM7rMdO.js → select-menu-BE5AIdgO.js} +1 -1
- package/dist/assets/{settings-agents-page-BsZY71kz.js → settings-agents-page-hqI0IaNx.js} +1 -1
- package/dist/assets/{settings-bin-page-kB3jtHo_.js → settings-bin-page-2bPjFtZ3.js} +1 -1
- package/dist/assets/{settings-calendar-page-C-IGNk3_.js → settings-calendar-page-u_TfZJEh.js} +1 -1
- package/dist/assets/{settings-data-page-CFGSL9g3.js → settings-data-page-DSQ14F2i.js} +1 -1
- package/dist/assets/{settings-logs-page-C7e9FIN_.js → settings-logs-page-BU0CJhDM.js} +1 -1
- package/dist/assets/{settings-mobile-page-DzKeZQDM.js → settings-mobile-page-B1fQ61BB.js} +1 -1
- package/dist/assets/{settings-models-page-dFhaOV3E.js → settings-models-page-B0Dis_c_.js} +1 -1
- package/dist/assets/{settings-page-C0fSyYUx.js → settings-page-V4ibXIp9.js} +1 -1
- package/dist/assets/{settings-rewards-page-D-LuZHhv.js → settings-rewards-page-DeCGBNn5.js} +1 -1
- package/dist/assets/{settings-section-nav-kFFQSJEe.js → settings-section-nav-DV5umEkp.js} +1 -1
- package/dist/assets/{settings-users-page-CX797HPB.js → settings-users-page-BB8Dzd_P.js} +1 -1
- package/dist/assets/{settings-wiki-page-CWLAvcsf.js → settings-wiki-page-B0k0KRsU.js} +1 -1
- package/dist/assets/{sleep-page-QgBkKyk_.js → sleep-page-CPwUb-em.js} +1 -1
- package/dist/assets/{sports-page-C8tLMl7V.js → sports-page-Cl4vZVwh.js} +1 -1
- package/dist/assets/{strategies-page-CGgh-KXu.js → strategies-page-DhFXf-g3.js} +1 -1
- package/dist/assets/{strategy-detail-page-CnzqjjoD.js → strategy-detail-page-B2gotRKI.js} +1 -1
- package/dist/assets/{strategy-dialog-C6AThZ9L.js → strategy-dialog-DD1bbrRB.js} +1 -1
- package/dist/assets/{surface-CIDhCEsF.js → surface-98myBzix.js} +1 -1
- package/dist/assets/{task-detail-page-Dp0r_qZP.js → task-detail-page-nx4eQbMW.js} +1 -1
- package/dist/assets/{timebox-planning-dialog-B3uaSsWI.js → timebox-planning-dialog-DoZ9zUra.js} +1 -1
- package/dist/assets/{today-page-CTnMYrPi.js → today-page-7BH7Yne1.js} +1 -1
- package/dist/assets/{training-load-page-D0WB5_Tq.js → training-load-page-E82pNn1-.js} +1 -1
- package/dist/assets/{vitals-page-0vg8nqwj.js → vitals-page-D64WlwVv.js} +1 -1
- package/dist/assets/{weekly-review-page-CSSKlkbH.js → weekly-review-page-BkRxxm7Q.js} +1 -1
- package/dist/assets/weight-loss-page-DPbg7rTC.js +5 -0
- package/dist/assets/{wiki-article-markdown-CBFvfJx_.js → wiki-article-markdown-B0Q6082A.js} +1 -1
- package/dist/assets/{wiki-editor-page-CL1uxpih.js → wiki-editor-page-Tkb50wEA.js} +1 -1
- package/dist/assets/{wiki-ingest-history-page-XX8DeNCC.js → wiki-ingest-history-page-CcQzkZRr.js} +1 -1
- package/dist/assets/{wiki-ingest-modal-j-ftDmzp.js → wiki-ingest-modal-D6yft0Qb.js} +1 -1
- package/dist/assets/{wiki-page-B46TQYpy.js → wiki-page-DEND1jmD.js} +1 -1
- package/dist/assets/{workbench-flow-page-CicEuBKq.js → workbench-flow-page-CkNI03j_.js} +1 -1
- package/dist/assets/{workbench-page-tXezYLh_.js → workbench-page-W3zQpeWr.js} +1 -1
- package/dist/assets/{workout-detail-page-BTO5X0Of.js → workout-detail-page-BVSZv53z.js} +1 -1
- package/dist/index.html +1 -1
- package/dist/server/server/src/app.js +2 -0
- package/dist/server/server/src/discovery-advertiser.js +5 -2
- package/dist/server/server/src/health-weight-loss.js +160 -10
- package/dist/server/server/src/services/devrage-scanner.js +948 -0
- package/dist/server/server/src/services/devrage.js +1 -1
- package/dist/server/src/lib/weight-loss-energy-model.js +64 -0
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/skills/forge-openclaw/SKILL.md +10 -0
- package/skills/forge-openclaw/entity_conversation_playbooks.md +33 -0
- package/skills/forge-openclaw/psyche_entity_playbooks.md +31 -0
- package/dist/assets/weight-loss-page-Dcr4wjjy.js +0 -5
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { scanConversations } from "
|
|
2
|
+
import { scanConversations } from "./devrage-scanner.js";
|
|
3
3
|
import { getDatabase, runInTransaction } from "../db.js";
|
|
4
4
|
import { psycheMetricsViewDataSchema } from "../psyche-types.js";
|
|
5
5
|
const SWEAR_COUNT_KEY = "swear_count";
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export const HALL_NIDDK_LINEAR_WEIGHT_MODEL = {
|
|
2
|
+
id: "hall_niddk_linearized_adult_12w",
|
|
3
|
+
label: "Hall/NIDDK linearized adult model",
|
|
4
|
+
defaultPlanningHorizonDays: 84,
|
|
5
|
+
steadyStateKcalPerKgPerDay: 10 / 0.45359237,
|
|
6
|
+
timeConstantDays: 365,
|
|
7
|
+
staticEnergyDensityKcalPerKg: 7700
|
|
8
|
+
};
|
|
9
|
+
function positiveFinite(value) {
|
|
10
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0
|
|
11
|
+
? value
|
|
12
|
+
: null;
|
|
13
|
+
}
|
|
14
|
+
export function hallNiddkWeightModelParameters(options = {}) {
|
|
15
|
+
const planningHorizonDays = positiveFinite(options.planningHorizonDays) ??
|
|
16
|
+
HALL_NIDDK_LINEAR_WEIGHT_MODEL.defaultPlanningHorizonDays;
|
|
17
|
+
const timeConstantDays = positiveFinite(options.timeConstantDays) ??
|
|
18
|
+
HALL_NIDDK_LINEAR_WEIGHT_MODEL.timeConstantDays;
|
|
19
|
+
const steadyStateKcalPerKgPerDay = positiveFinite(options.steadyStateKcalPerKgPerDay) ??
|
|
20
|
+
HALL_NIDDK_LINEAR_WEIGHT_MODEL.steadyStateKcalPerKgPerDay;
|
|
21
|
+
const responseFraction = 1 - Math.exp(-planningHorizonDays / timeConstantDays);
|
|
22
|
+
return {
|
|
23
|
+
planningHorizonDays,
|
|
24
|
+
timeConstantDays,
|
|
25
|
+
steadyStateKcalPerKgPerDay,
|
|
26
|
+
responseFraction
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export function hallNiddkWeeklyRateKgToDailyEnergyAdjustment(weeklyRateKg, options = {}) {
|
|
30
|
+
if (typeof weeklyRateKg !== "number" || !Number.isFinite(weeklyRateKg)) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
if (weeklyRateKg === 0) {
|
|
34
|
+
return 0;
|
|
35
|
+
}
|
|
36
|
+
const parameters = hallNiddkWeightModelParameters(options);
|
|
37
|
+
if (parameters.responseFraction <= 0) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
const targetChangeKg = weeklyRateKg * (parameters.planningHorizonDays / 7);
|
|
41
|
+
return ((targetChangeKg * parameters.steadyStateKcalPerKgPerDay) /
|
|
42
|
+
parameters.responseFraction);
|
|
43
|
+
}
|
|
44
|
+
export function hallNiddkDailyEnergyAdjustmentToAverageWeeklyRateKg(dailyEnergyAdjustmentKcal, options = {}) {
|
|
45
|
+
if (typeof dailyEnergyAdjustmentKcal !== "number" ||
|
|
46
|
+
!Number.isFinite(dailyEnergyAdjustmentKcal)) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
if (dailyEnergyAdjustmentKcal === 0) {
|
|
50
|
+
return 0;
|
|
51
|
+
}
|
|
52
|
+
const parameters = hallNiddkWeightModelParameters(options);
|
|
53
|
+
const totalChangeKg = (dailyEnergyAdjustmentKcal / parameters.steadyStateKcalPerKgPerDay) *
|
|
54
|
+
parameters.responseFraction;
|
|
55
|
+
return totalChangeKg / (parameters.planningHorizonDays / 7);
|
|
56
|
+
}
|
|
57
|
+
export function staticKgRateToDailyEnergyAdjustment(weeklyRateKg) {
|
|
58
|
+
if (typeof weeklyRateKg !== "number" || !Number.isFinite(weeklyRateKg)) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
return ((weeklyRateKg *
|
|
62
|
+
HALL_NIDDK_LINEAR_WEIGHT_MODEL.staticEnergyDensityKcalPerKg) /
|
|
63
|
+
7);
|
|
64
|
+
}
|
package/openclaw.plugin.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"id": "forge-openclaw-plugin",
|
|
3
3
|
"name": "Forge",
|
|
4
4
|
"description": "Curated OpenClaw adapter for the Forge collaboration API, UI entrypoint, and localhost auto-start runtime.",
|
|
5
|
-
"version": "0.2.
|
|
5
|
+
"version": "0.2.110",
|
|
6
6
|
"activation": {
|
|
7
7
|
"onStartup": true,
|
|
8
8
|
"onCapabilities": [
|
package/package.json
CHANGED
|
@@ -238,6 +238,11 @@ Entity conversation rule:
|
|
|
238
238
|
|
|
239
239
|
- For all entity creation or update flows, first use [`entity_conversation_playbooks.md`](./entity_conversation_playbooks.md) to decide the next best question.
|
|
240
240
|
- Ask only for what is missing or unclear. Do not walk through every schema field.
|
|
241
|
+
- Before asking another question, run the playbook's minimum save-readiness
|
|
242
|
+
checkpoint: if accepted wording, meaningful body, route lane, target object or
|
|
243
|
+
time scope, and any ownership/placement that changes later use are already clear,
|
|
244
|
+
summarize once and write, read, run, or update instead of collecting optional
|
|
245
|
+
fields.
|
|
241
246
|
- Let each question have one job. Know what you are trying to clarify before you ask it.
|
|
242
247
|
- Before you ask, decide the exact missing thing you need and how that answer will help you name, place, or save the record.
|
|
243
248
|
- Prefer a progression of:
|
|
@@ -299,6 +304,11 @@ Psyche interview rule:
|
|
|
299
304
|
- In that first exploratory turn, ask only one question, do not search Forge or mention whether a matching entity exists, and avoid openings like "This sounds like" or "What you're describing is".
|
|
300
305
|
- In that first exploratory turn, prefer exactly two sentences: one brief empathic reflection and one concrete question. Avoid colons because they tend to trigger list-like answers.
|
|
301
306
|
- Follow the preferred opening-question patterns in [`psyche_entity_playbooks.md`](./psyche_entity_playbooks.md) when they fit the entity the user is exploring.
|
|
307
|
+
- After a Psyche formulation lands, use the Psyche save-readiness checkpoint from
|
|
308
|
+
the playbook. If the belief sentence, functional loop, behavior move, part-state,
|
|
309
|
+
trigger episode, value, event type, emotion definition, or flashcard cue/message is
|
|
310
|
+
true enough to save, ask at most one accuracy question and then use shared batch
|
|
311
|
+
CRUD.
|
|
302
312
|
- If the user already offers a usable belief sentence, value phrase, or mode name,
|
|
303
313
|
refine from their wording first instead of replacing it with a cleaner label too
|
|
304
314
|
early.
|
|
@@ -258,6 +258,39 @@ Most good Forge intake flows follow this sequence:
|
|
|
258
258
|
|
|
259
259
|
That sequence is not a script. Skip steps the user already answered.
|
|
260
260
|
|
|
261
|
+
## Minimum save-readiness checkpoint
|
|
262
|
+
|
|
263
|
+
Use this before asking another polished follow-up. The question quality is worse, not
|
|
264
|
+
better, when the agent keeps exploring after the record or route is already clear
|
|
265
|
+
enough to act.
|
|
266
|
+
|
|
267
|
+
- For normal batch entities, save or update when you have the accepted working name
|
|
268
|
+
or distinctive wording, the meaningful body of the record, and owner scope only if
|
|
269
|
+
ownership changes accountability. Do not ask for tags, links, dates, priority,
|
|
270
|
+
assignees, or status just because those fields exist.
|
|
271
|
+
- For strategic and planning records, the minimum is the intended outcome plus the
|
|
272
|
+
hierarchy placement that would change later retrieval or execution. If placement is
|
|
273
|
+
not known but the user asked to capture the idea now, save the provisional record
|
|
274
|
+
with clear wording and leave placement for a later link/update.
|
|
275
|
+
- For operational records, the minimum is the target action plus the time, object, or
|
|
276
|
+
state that makes the action truthful: event time for a calendar event, recurrence
|
|
277
|
+
for a work block, task and slot for a timebox, task id for a task run, or target
|
|
278
|
+
record and signed minutes for a work adjustment. Generate a plain title yourself
|
|
279
|
+
when the title is obvious.
|
|
280
|
+
- For read-model and review surfaces, the minimum is the practical question plus any
|
|
281
|
+
scope that would change the answer. Once you have that, read the overview instead
|
|
282
|
+
of asking for a preferred report shape.
|
|
283
|
+
- For specialized Movement, Life Force, and Workbench writes, the minimum is the
|
|
284
|
+
selected lane plus the target span/object/weekday/flow/run/node and the intended
|
|
285
|
+
correction or effect. Do not ask a reflective question after the dedicated route
|
|
286
|
+
and write shape are already selected.
|
|
287
|
+
- For reflective non-Psyche records, the minimum is what future review should
|
|
288
|
+
remember and the container that preserves it. If a stronger Psyche container clearly
|
|
289
|
+
emerges, route there; otherwise do not keep deepening just to make the note more
|
|
290
|
+
therapeutic.
|
|
291
|
+
- Close the loop in one sentence before acting: "What seems clear now is..." followed
|
|
292
|
+
by the save, update, read, run, or handoff.
|
|
293
|
+
|
|
261
294
|
## Project-management hierarchy playbook
|
|
262
295
|
|
|
263
296
|
When the conversation is about Forge planning or delivery, preserve this
|
|
@@ -236,6 +236,37 @@ of leaving it as warm reflective prose.
|
|
|
236
236
|
- Save through shared batch entity routes only after the user accepts the working
|
|
237
237
|
wording or explicitly asks to save.
|
|
238
238
|
|
|
239
|
+
## Psyche save-readiness checkpoint
|
|
240
|
+
|
|
241
|
+
Use this before asking another deepening question. Psyche work should feel careful,
|
|
242
|
+
but not endless. Once the user recognizes the working formulation, protect momentum and
|
|
243
|
+
save the record instead of reopening the whole story.
|
|
244
|
+
|
|
245
|
+
- For `belief_entry`, the minimum is the accepted sentence or prediction plus whether
|
|
246
|
+
it is mainly about self, others, world/safety, or outcome when that distinction is
|
|
247
|
+
visible.
|
|
248
|
+
- For `behavior_pattern`, the minimum is a concrete cue or situation, the felt
|
|
249
|
+
meaning/body shift, the behavior or urge, and at least one payoff or cost. A
|
|
250
|
+
preferred response is useful, but do not force it before saving a provisional
|
|
251
|
+
functional analysis.
|
|
252
|
+
- For `behavior`, the minimum is the repeated move, the cue or urge that brings it
|
|
253
|
+
online, and whether the move functions as avoidance, committed action, repair, or
|
|
254
|
+
recovery when that is clear.
|
|
255
|
+
- For `mode_profile`, the minimum is the part's voice or posture, what it is trying
|
|
256
|
+
to protect, and what danger or burden it expects.
|
|
257
|
+
- For `mode_guide_session`, the minimum is the present trigger, a brief summary of
|
|
258
|
+
what the active part seems to want, and the answers gathered so far.
|
|
259
|
+
- For `trigger_report`, the minimum is the situation, felt stake, meaning or thought,
|
|
260
|
+
action/urge, and consequence that make it one emotionally meaningful episode.
|
|
261
|
+
- For `psyche_value`, `event_type`, and `emotion_definition`, the minimum is the
|
|
262
|
+
future use: what this value, recurring moment, or lived feeling label will help
|
|
263
|
+
future reports notice consistently.
|
|
264
|
+
- For `flashcard`, the minimum is the cue or urge sentence and one brief message the
|
|
265
|
+
user can recognize while triggered. Link to beliefs, modes, values, or patterns only
|
|
266
|
+
when the link is already clear or will materially improve retrieval.
|
|
267
|
+
- After the minimum is present, ask one accuracy question at most: "Is this true
|
|
268
|
+
enough to save as a first version?" If yes, save through shared batch CRUD.
|
|
269
|
+
|
|
239
270
|
## Psyche Hypothesis Map
|
|
240
271
|
|
|
241
272
|
Use these shapes after at least one concrete example is clear. The hypothesis should
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import{j as a,b4 as De,aG as ta,b3 as na,cm as Aa,dx as Ea,cG as _a,bL as _e,bX as $a,cK as ra,ce as Ta,c7 as sa,dy as Da,dz as Ia,bE as ia,dA as La,dB as Pa,r as F,d8 as Ra,bH as Qe,dC as Wa,bF as Ba,bu as Ha}from"./vendor-Dnkkx2co.js";import{j as qa,i as za,k as q}from"./state-vCcAT5Hq.js";import{P as Oa}from"./page-hero-DzEsy8i5.js";import{C as z,B as K,aq as de,I as k,Z as oa,c as $,Q as je,F as y,j as Ve,T as ve,u as Ua,eW as Qa,eX as Va,eY as Ye,eZ as Ya,e_ as Ja,e$ as Za,f0 as Xa,f1 as Je,f2 as et,f3 as at,f4 as tt,L as nt,E as rt,f5 as st}from"./index-BhkubYaC.js";import{S as D,a as N}from"./surface-CIDhCEsF.js";import{f as $e}from"./date-keys-Cj1G3TOn.js";import"./motion-Lt5B1XuE.js";import"./ui-C1iwpj2-.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";import"./graph-DDUZNRsO.js";function it({view:e,onOpenPlan:t,onOpenFoodSearch:n,onOpenCustomFood:r,onOpenChatGptFood:s,onOpenCheckin:d,onOpenHistory:g}){return a.jsxs(z,{className:"grid gap-4 border-[var(--ui-border-subtle)] bg-[var(--ui-surface-section)] p-5 lg:grid-cols-[minmax(0,1fr)_auto] lg:items-center",children:[a.jsxs("div",{className:"min-w-0",children:[a.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Control center"}),a.jsx("h2",{className:"mt-1 text-xl font-semibold text-[var(--ui-ink-strong)]",children:e.target.bodyGoal?`Goal: ${e.target.bodyGoal}`:"Set the body objective"}),a.jsxs("p",{className:"mt-2 max-w-3xl text-sm leading-6 text-[var(--ui-ink-soft)]",children:["Current target: ",e.target.calorieTarget.toFixed(0)," kcal,"," ",e.target.proteinGramsTarget.toFixed(0),"g protein,"," ",e.target.fiberGramsTarget.toFixed(0),"g fiber. Adjust the plan, add food with exact quantities, or record body signals from guided flows."]})]}),a.jsxs("div",{className:"grid min-w-0 gap-2 sm:grid-cols-2 xl:grid-cols-3",children:[a.jsxs(K,{type:"button",onClick:r,children:[a.jsx(De,{className:"size-4"}),"Custom food"]}),a.jsxs(K,{type:"button",variant:"secondary",onClick:s,children:[a.jsx(ta,{className:"size-4"}),"Ask ChatGPT"]}),a.jsxs(K,{type:"button",variant:"secondary",onClick:n,children:[a.jsx(na,{className:"size-4"}),"Search food"]}),a.jsxs(K,{type:"button",variant:"secondary",onClick:t,children:[a.jsx(Aa,{className:"size-4"}),"Plan settings"]}),a.jsxs(K,{type:"button",variant:"secondary",onClick:d,children:[a.jsx(Ea,{className:"size-4"}),"Add measure"]}),a.jsxs(K,{type:"button",variant:"secondary",onClick:g,children:[a.jsx(_a,{className:"size-4"}),"Food history"]})]})]})}function A(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function ie(e){return typeof e=="string"&&e.trim()?e:null}function i(e,t=0){const n=A(e);return n===null?"n/a":n.toFixed(t)}function W(e,t=0){const n=A(e);return n===null?"n/a":`${n>0?"+":""}${n.toFixed(t)}`}function be(e){const t=A(e);return t===null?"n/a":`${t.toFixed(1)}/10`}function ot(e){return Array.isArray(e)?e.filter(t=>!!t&&typeof t=="object"&&!Array.isArray(t)):[]}function lt(e){switch(e){case"user_override":return"Manual override for today";case"today_healthkit_active_energy":return"HealthKit active energy today";case"today_workout_movement_energy":return"Workout + movement today";case"today_workout_movement_step_energy":return"Workout + movement + steps today";case"today_workout_step_energy":return"Workout + steps today";case"today_movement_step_energy":return"Movement + steps today";case"today_workout_energy":return"Workout energy today";case"today_movement_trip_calories":return"Movement trips today";case"today_step_estimate":return"Step estimate today";default:return"Default daily active calories"}}function ct(e){switch(e){case"user_override":return"Using your manual value for today.";case"today_healthkit_active_energy":return"Using same-day HealthKit active energy instead of the default.";case"today_workout_movement_energy":return"Using today's workout and movement calories instead of the default.";case"today_workout_movement_step_energy":return"Using today's workouts, movement, and steps instead of the default.";case"today_workout_step_energy":return"Using today's workouts and steps instead of the default.";case"today_movement_step_energy":return"Using today's movement and steps instead of the default.";case"today_workout_energy":return"Using today's workout calories instead of the default.";case"today_movement_trip_calories":return"Using today's movement calories instead of the default.";case"today_step_estimate":return"Using today's step estimate because it is above the default.";default:return"No meaningful same-day active evidence yet, so the default active calories are used."}}function dt({view:e,draftValue:t,pending:n,error:r,onDraftChange:s,onSave:d,onReset:g}){const l=e.energyModel,o=e.todayLedger,c=l.todayActiveOverride,w=l.todayActiveCaloriesSource,b=`${o.plannedTargetCalories.toFixed(0)} + (${l.todayActiveCaloriesKcal.toFixed(0)} - ${l.baselineActiveCaloriesKcal.toFixed(0)}) = ${o.targetCalories.toFixed(0)} kcal`;return a.jsxs(z,{className:"grid min-w-0 gap-3 border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[a.jsxs("div",{className:"flex min-w-0 items-start justify-between gap-3",children:[a.jsxs("div",{className:"min-w-0",children:[a.jsxs("div",{className:"flex items-center gap-1 text-[11px] uppercase tracking-[0.14em] text-[var(--ui-ink-faint)]",children:["Active kcal",a.jsx(de,{label:"Explain active calories",content:`Today target = baseline food target + (today active calories - default active calories). ${b}. Same-day HealthKit active energy, workouts, movement, or steps replace the default. A manual edit overrides today only.`})]}),a.jsxs("div",{className:"mt-1 text-2xl font-semibold leading-tight text-[var(--ui-ink-strong)]",children:[l.todayActiveCaloriesKcal.toFixed(0)," kcal"]})]}),a.jsx("div",{className:"rounded-[8px] bg-[var(--ui-info-soft)] p-2 text-[color-mix(in_srgb,var(--info)_78%,var(--ui-ink-strong)_22%)]",children:a.jsx(_e,{className:"size-4"})})]}),a.jsxs("div",{className:"grid gap-1 text-xs leading-5 text-[var(--ui-ink-soft)]",children:[a.jsx("div",{className:"break-words font-medium text-[var(--ui-ink-medium)]",children:ct(w)}),a.jsxs("div",{children:["Default ",l.baselineActiveCaloriesKcal.toFixed(0)," kcal"," · ","observed"," ",l.todayObservedActiveCaloriesKcal!=null?`${l.todayObservedActiveCaloriesKcal.toFixed(0)} kcal`:"n/a"]}),a.jsxs("div",{className:"break-words",children:["Source: ",lt(w)]})]}),a.jsxs("div",{className:"grid min-w-0 grid-cols-[minmax(0,1fr)_auto] gap-2",children:[a.jsx(k,{inputMode:"decimal",value:t,onChange:x=>s(x.target.value),"aria-label":"Today active calories",className:"py-2.5"}),a.jsxs(K,{type:"button",onClick:d,pending:n,pendingLabel:"Applying",children:[a.jsx($a,{className:"size-4"}),"Apply"]})]}),a.jsxs(K,{type:"button",variant:"secondary",onClick:g,disabled:!c||n,children:[a.jsx(ra,{className:"size-4"}),"Use evidence"]}),r?a.jsx("div",{className:"rounded-[8px] border border-[var(--danger)]/20 bg-[var(--ui-danger-soft)] px-3 py-2 text-xs leading-5 text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)]",children:r}):null]})}const ut={default:"bg-[color-mix(in_srgb,var(--primary)_14%,transparent)] text-[var(--primary)]",green:"bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]",amber:"bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_76%,var(--ui-ink-strong)_24%)]",rose:"bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_76%,var(--ui-ink-strong)_24%)]",cyan:"bg-[var(--ui-info-soft)] text-[color-mix(in_srgb,var(--info)_78%,var(--ui-ink-strong)_22%)]"};function Y({label:e,value:t,detail:n,icon:r,tone:s="default",help:d,helpMaxWidthPx:g}){return a.jsxs(z,{className:"grid gap-4 border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-5",children:[a.jsxs("div",{className:"flex items-center justify-between gap-3",children:[a.jsx("div",{className:oa("rounded-2xl p-2.5",ut[s]),children:a.jsx(r,{className:"size-5"})}),a.jsxs("div",{className:"flex items-center justify-end gap-1 text-right text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:[a.jsx("span",{children:e}),d?a.jsx(de,{content:d,label:`Explain ${e}`,maxWidthPx:g}):null]})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-3xl font-semibold text-[var(--ui-ink-strong)]",children:t}),a.jsx("p",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:n})]})]})}function gt({meal:e,onLogAgain:t,onEdit:n,onDelete:r,pending:s=!1}){const d=e.items[0]??null,g=Math.max(0,e.items.length-1),l=d?`${d.name}${g>0?` + ${g} more`:""}`:e.mealLabel??"Meal",o=e.items.slice(0,3).map(c=>{const w=Number.isFinite(c.quantity)&&c.quantity>0?Number.isInteger(c.quantity)?String(c.quantity):c.quantity.toFixed(2).replace(/\.?0+$/,""):null,b=c.unit??"serving",x=c.grams!=null?`${c.grams.toFixed(0)}g`:null;return[w,b,x?`(${x})`:null].filter(Boolean).join(" ")}).filter(Boolean).join(" · ");return a.jsxs(D,{className:"grid min-w-0 gap-3",children:[a.jsxs("div",{className:"flex min-w-0 flex-wrap items-start justify-between gap-3",children:[a.jsxs("div",{className:"min-w-0",children:[a.jsx("div",{className:"break-words text-base font-semibold leading-6 text-[var(--ui-ink-strong)]",children:l}),a.jsx("div",{className:"mt-1 text-xs leading-5 text-[var(--ui-ink-faint)]",children:o||e.notes||"No quantity recorded"})]}),a.jsxs("div",{className:"flex flex-wrap justify-end gap-2",children:[e.mealLabel?a.jsx($,{tone:"meta",children:e.mealLabel}):null,a.jsxs($,{tone:"meta",children:[e.totals.calories.toFixed(0)," kcal"]})]})]}),a.jsxs("div",{className:"grid gap-2 text-xs text-[var(--ui-ink-soft)] sm:grid-cols-3 xl:grid-cols-6",children:[a.jsxs("span",{children:[e.totals.proteinGrams.toFixed(0),"g protein"]}),a.jsxs("span",{children:[e.totals.carbohydrateGrams.toFixed(0),"g carbs"]}),a.jsxs("span",{children:[e.totals.fatGrams.toFixed(0),"g fat"]}),a.jsxs("span",{children:[e.totals.fiberGrams.toFixed(0),"g fiber"]}),a.jsxs("span",{children:[e.totals.sodiumMg.toFixed(0),"mg sodium"]}),a.jsx("span",{children:e.confirmationState})]}),a.jsxs("div",{className:"flex flex-wrap gap-2",children:[n?a.jsxs(K,{type:"button",size:"sm",variant:"secondary",onClick:()=>n(e),children:[a.jsx(Ta,{className:"size-4"}),"Edit"]}):null,r?a.jsxs(K,{type:"button",size:"sm",variant:"ghost",pending:s,onClick:()=>r(e),children:[a.jsx(sa,{className:"size-4"}),"Delete"]}):null,t?a.jsxs(K,{type:"button",size:"sm",variant:"ghost",pending:s,onClick:()=>t(e),children:[a.jsx(ra,{className:"size-4"}),"Log again"]}):null]})]})}function Ie({children:e}){return a.jsx(D,{className:"border-dashed border-[var(--ui-border-strong)] p-5 text-sm text-[var(--ui-ink-soft)]",children:e})}function mt({ledger:e,remainingCalories:t,intakePercent:n,logSavedPending:r,onLogAgain:s,onEditMeal:d,onDeleteMeal:g}){const l=e.totals;return a.jsxs(z,{className:"grid gap-5 border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-5",children:[a.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[a.jsxs("div",{children:[a.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Food log"}),a.jsxs("h2",{className:"mt-1 flex items-center gap-2 text-xl font-semibold text-[var(--ui-ink-strong)]",children:[a.jsx("span",{children:"Calories, macros, and meal evidence"}),a.jsx(de,{label:"Explain food log",content:"The food log is today's editable record of what was eaten. Edit a meal to change quantities, remove items, correct food parameters, or delete the meal entirely."})]})]}),a.jsxs($,{tone:"meta",children:[e.meals.length," meals"]})]}),a.jsxs("div",{children:[a.jsx("div",{className:"h-3 overflow-hidden rounded-full bg-[var(--ui-surface-2)]",children:a.jsx("div",{className:oa("h-full rounded-full",t>=0?"bg-[color-mix(in_srgb,var(--success)_82%,var(--secondary)_18%)]":"bg-[color-mix(in_srgb,var(--danger)_82%,var(--tertiary)_18%)]"),style:{width:`${Math.min(100,n)}%`}})}),a.jsxs("div",{className:"mt-3 grid gap-2 text-sm text-[var(--ui-ink-soft)] sm:grid-cols-4",children:[a.jsxs("span",{children:[l.carbohydrateGrams.toFixed(0),"g carbs"]}),a.jsxs("span",{children:[l.fatGrams.toFixed(0),"g fat"]}),a.jsxs("span",{children:[l.fiberGrams.toFixed(0),"g fiber"]}),a.jsxs("span",{children:[e.unconfirmedCount," unconfirmed"]})]})]}),a.jsx("div",{className:"grid gap-3",children:e.meals.length>0?e.meals.map(o=>a.jsx(gt,{meal:o,pending:r,onLogAgain:s,onEdit:d,onDelete:g},o.id)):a.jsx(Ie,{children:"No meals logged today yet."})})]})}function ht({hypotheses:e}){return a.jsxs(z,{className:"grid gap-4 border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-5",children:[a.jsxs("div",{children:[a.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Hypotheses"}),a.jsx("h2",{className:"mt-1 text-xl font-semibold text-[var(--ui-ink-strong)]",children:"Food and body pattern candidates"})]}),a.jsx("div",{className:"grid gap-3 md:grid-cols-2",children:e.length>0?e.slice(0,6).map((t,n)=>a.jsxs(D,{children:[a.jsxs("div",{className:"flex items-center justify-between gap-3",children:[a.jsx($,{tone:"signal",children:ie(t.metric)??"pattern"}),a.jsx("span",{className:"text-xs text-[var(--ui-ink-faint)]",children:i(t.confidence,2)})]}),a.jsx("div",{className:"mt-3 text-sm font-medium text-[var(--ui-ink-strong)]",children:ie(t.label)??"Candidate pattern"}),a.jsx("p",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:ie(t.description)??"Forge needs more paired meals and check-ins to harden this signal."})]},String(t.key??n))):a.jsx("div",{className:"md:col-span-2",children:a.jsx(Ie,{children:"Log meals plus energy, gut, and look check-ins for a few days to generate pattern candidates."})})})]})}function pt({experiments:e}){return a.jsxs(z,{className:"grid content-start gap-4 border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-5",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"rounded-2xl bg-[var(--ui-info-soft)] p-2.5 text-[color-mix(in_srgb,var(--info)_78%,var(--ui-ink-strong)_22%)]",children:a.jsx(Da,{className:"size-5"})}),a.jsxs("div",{children:[a.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Experiments"}),a.jsx("h2",{className:"text-xl font-semibold text-[var(--ui-ink-strong)]",children:"N-of-1 lab"})]})]}),a.jsxs("div",{className:"grid gap-3",children:[e.slice(0,4).map((t,n)=>a.jsxs(D,{children:[a.jsx("div",{className:"text-sm font-medium text-[var(--ui-ink-strong)]",children:ie(t.title)??"Nutrition experiment"}),a.jsx("p",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:ie(t.hypothesis)??ie(t.intervention)??"No hypothesis recorded."})]},String(t.id??n))),e.length===0?a.jsx(Ie,{children:"Start experiments from OpenClaw or the API: caffeine timing, fiber ramp, low-FODMAP trial, carb timing, sodium/puffiness, or pre-training fueling."}):null]})]})}function xt({view:e}){const t=e.dataQuality,n=e.todayLedger;return a.jsxs(z,{className:"grid gap-4 border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-5",children:[a.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[a.jsxs("div",{children:[a.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Data quality"}),a.jsx("h2",{className:"mt-1 text-xl font-semibold text-[var(--ui-ink-strong)]",children:"Confidence, coverage, and next evidence"})]}),a.jsxs($,{tone:"meta",children:[e.summary.dataQualityScore.toFixed(0),"% coverage"]})]}),a.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[a.jsx(bt,{label:"Source confidence",value:t.sourceConfidence,children:"Food parsing stays candidate-based until accepted; wearable burn is treated as a trend input."}),a.jsxs(D,{children:[a.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Missing check-ins"}),a.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:t.missingHighValueCheckins.length>0?t.missingHighValueCheckins.map(r=>a.jsx($,{tone:"signal",children:r},r)):a.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Core evidence loop is covered."})})]}),a.jsxs(D,{children:[a.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Next best cue"}),a.jsx("p",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:t.notes}),a.jsxs("div",{className:"mt-3 text-xs text-[var(--ui-ink-faint)]",children:[n.unconfirmedCount," unconfirmed candidate",n.unconfirmedCount===1?"":"s"]})]})]})]})}function bt({label:e,value:t,children:n}){return a.jsxs(D,{children:[a.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:e}),a.jsx("div",{className:"mt-2 text-lg font-semibold text-[var(--ui-ink-strong)]",children:t}),a.jsx("p",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:n})]})}function R(e,t,n){return a.jsxs("li",{className:"grid gap-0.5",children:[a.jsx("span",{className:"font-medium text-[var(--ui-ink)]",children:e}),a.jsx("code",{className:"rounded-[6px] bg-[var(--ui-surface-2)] px-1.5 py-0.5 font-mono text-[11px] text-[var(--ui-ink-soft)]",children:t}),n?a.jsx("span",{className:"text-xs text-[var(--ui-ink-faint)]",children:n}):null]})}function la({values:e,label:t="Show calorie and macro formulas"}){const r=((e==null?void 0:e.sex)??"male")==="male"?"+ 5":"- 161",s=(e==null?void 0:e.proteinFactor)!=null?`${e.proteinFactor.toFixed(1)}g/kg`:"1.6-2.0g/kg";return a.jsx(de,{label:t,title:"Weight Loss Formulas",maxWidthPx:520,panelClassName:"text-xs leading-5",content:a.jsxs("div",{className:"grid gap-3",children:[a.jsx("p",{children:"Forge keeps activity independent from the goal. The goal only adds a deficit, surplus, or zero adjustment to resting plus active calories."}),a.jsxs("ol",{className:"grid gap-2",children:[R("Mifflin-St Jeor BMR",`10 x weight kg + 6.25 x height cm - 5 x age ${r}`,`Current formula value: ${i(e==null?void 0:e.bmrKcal)} kcal/day.`),R("Resting calories","HealthKit basal/resting kcal when present, otherwise BMR",`Using: ${i(e==null?void 0:e.restingKcal)} kcal/day${e!=null&&e.restingSource?` (${e.restingSource})`:""}.`),R("Maintenance calories","resting calories + active calories",`${i(e==null?void 0:e.restingKcal)} + ${i(e==null?void 0:e.activeKcal)} = ${i(e==null?void 0:e.maintenanceKcal)} kcal/day.`),R("Objective adjustment","weekly change kg x 7700 kcal/kg / 7",`Weekly rate ${W(e==null?void 0:e.weeklyRateKg,2)} kg/week gives ${W(e==null?void 0:e.dailyAdjustmentKcal)} kcal/day.`),R("Daily calorie target","max(sex floor, maintenance + objective adjustment)",`Floor ${i(e==null?void 0:e.calorieFloor)} kcal; target ${i(e==null?void 0:e.calorieTarget)} kcal/day.`),R("Protein target",`min(reference weight x ${s}, 45% of kcal / 4)`,`Reference ${i(e==null?void 0:e.proteinReferenceWeightKg,1)} kg; target ${i(e==null?void 0:e.proteinGrams)} g/day.`),R("Fat target","saved plan fat when present; otherwise min(remaining kcal after protein, 35% kcal / 9, max(0.6g/kg reference, 25% kcal / 9))",`Target ${i(e==null?void 0:e.fatGrams)} g/day.`),R("Carbohydrate target","(calorie target - protein g x 4 - fat g x 9) / 4",`Target ${i(e==null?void 0:e.carbohydrateGrams)} g/day. The 130g DRI is shown as reference, not forced if it breaks calories.`),R("Fiber target","14g per 1000 kcal; adult sex/age AI shown as reference",`Target ${i(e==null?void 0:e.fiberGrams)} g/day; energy-adjusted ${i(e==null?void 0:e.fiberEnergyAdjustedGrams)} g/day; adult AI reference ${i(e==null?void 0:e.fiberDriGrams)} g/day.`),R("Sport-loss estimate","training hours ~= active kcal / 500; sweat ~= 0.4-0.8 L/h; sodium ~= 500-1000 mg/L","Shown as expected loss ranges, not rigid supplement instructions.")]})]})})}function ca(e,t){var r;if(!e)return null;const n=e.match(new RegExp(`${t}=([^;]+)`));return((r=n==null?void 0:n[1])==null?void 0:r.trim())??null}function ce(e,t){const n=typeof e=="string"?Number(e):A(e);return typeof n=="number"&&Number.isFinite(n)?n:t}function ft(e){return ca(e.target.notes,"sex")==="female"?"female":"male"}function vt(e){return ce(ca(e.target.notes,"age_years"),35)}function p(e,t,n,r,s,d){return{id:e,label:t,target:typeof n=="number"?Te(n):n,unit:r,note:s,source:d}}function Te(e){return Number.isFinite(e)?Math.abs(e)>=100?e.toFixed(0):e.toFixed(1).replace(/\.0$/,""):"n/a"}function se(e,t){return`${Te(e)}-${Te(t)}`}function yt(e,t,n,r){const s=Math.round(n/1e3*14);return r>0?r:s}function jt({calorieTarget:e,currentWeightKg:t,protein:n,savedFat:r}){const s=Math.max(0,(e-n*4)/9),d=Math.max(0,Math.min(s,e*.35/9,Math.max(t*.6,e*.25/9))),g=r??d;return{carbs:Math.max(0,(e-n*4-g*9)/4),fat:g}}function kt(e,t){return e==="male"?t>=51?14:17:t>=51?11:12}function Nt(e,t){const n=t>70,r=t>=51;return[p("vitamin_a","Vitamin A",e==="male"?900:700,"ug RAE","Retinol activity equivalent target.","NASEM DRI"),p("vitamin_c","Vitamin C",e==="male"?90:75,"mg","Adult RDA.","NASEM DRI"),p("vitamin_d","Vitamin D",n?20:15,"ug","Assumes limited sun exposure; older adults need more.","NASEM DRI"),p("vitamin_e","Vitamin E",15,"mg alpha-tocopherol","Adult RDA.","NASEM DRI"),p("vitamin_k","Vitamin K",e==="male"?120:90,"ug","Adult AI.","NASEM DRI"),p("thiamin_b1","Thiamin B1",e==="male"?1.2:1.1,"mg","Adult RDA.","NASEM DRI"),p("riboflavin_b2","Riboflavin B2",e==="male"?1.3:1.1,"mg","Adult RDA.","NASEM DRI"),p("niacin_b3","Niacin B3",e==="male"?16:14,"mg NE","Adult RDA.","NASEM DRI"),p("vitamin_b6","Vitamin B6",r?e==="male"?1.7:1.5:1.3,"mg","RDA rises after 50.","NASEM DRI"),p("folate","Folate",400,"ug DFE","Adult RDA.","NASEM DRI"),p("vitamin_b12","Vitamin B12",2.4,"ug","Adult RDA.","NASEM DRI"),p("pantothenic_acid","Pantothenic acid",5,"mg","Adult AI.","NASEM DRI"),p("biotin","Biotin",30,"ug","Adult AI.","NASEM DRI"),p("choline","Choline",e==="male"?550:425,"mg","Adult AI.","NASEM DRI")]}function wt(e,t){const n=t>70||e==="female"&&t>=51?1200:1e3,r=e==="male"?t>=31?420:400:t>=31?320:310,s=e==="male"?t>=51?30:35:t>=51?20:25,d=t>=71?1800:t>=51?2e3:2300;return[p("calcium","Calcium",n,"mg","Bone and muscle target; higher for older adults and women 51+.","NASEM DRI"),p("iron","Iron",e==="female"&&t<=50?18:8,"mg","Menstruating-age female target is higher.","NASEM DRI"),p("magnesium","Magnesium",r,"mg","Adult RDA.","NASEM DRI"),p("phosphorus","Phosphorus",700,"mg","Adult RDA.","NASEM DRI"),p("zinc","Zinc",e==="male"?11:8,"mg","Adult RDA.","NASEM DRI"),p("iodine","Iodine",150,"ug","Adult RDA.","NASEM DRI"),p("selenium","Selenium",55,"ug","Adult RDA.","NASEM DRI"),p("copper","Copper",.9,"mg","Adult RDA.","NASEM DRI"),p("manganese","Manganese",e==="male"?2.3:1.8,"mg","Adult AI.","NASEM DRI"),p("chromium","Chromium",s,"ug","Adult AI.","NASEM DRI"),p("molybdenum","Molybdenum",45,"ug","Adult RDA.","NASEM DRI"),p("fluoride","Fluoride",e==="male"?4:3,"mg","Adult AI.","NASEM DRI"),p("chloride","Chloride",d,"mg","Adult AI.","NASEM DRI"),p("potassium","Potassium",e==="male"?3400:2600,"mg","Current adult AI for non-pregnant adults.","NASEM DRI"),p("sodium_limit","Sodium ceiling",2300,"mg max","Default daily ceiling unless medically individualized.","U.S. Dietary Guidelines")]}function Ct(e){const t=ft(e),n=vt(e),r=ce(e.weightTrend.latestWeightKg,80),s=Math.max(1,ce(e.target.calorieTarget,2200)),d=ce(e.target.proteinGramsTarget,r*1.8),{carbs:g,fat:l}=jt({calorieTarget:s,currentWeightKg:r,protein:d,savedFat:A(e.target.fatGramsTarget)}),o=yt(t,n,s,ce(e.target.fiberGramsTarget,0)),c=A(e.energyModel.activeBurnKcal)??A(e.energyModel.activeEnergyCalories)??null,w=A(e.energyModel.movementCaloriesKcal),b=A(e.energyModel.restingEnergyCalories);return da({sex:t,ageYears:n,currentWeightKg:r,calorieTarget:s,proteinGramsTarget:d,carbohydrateGramsTarget:g,fatGramsTarget:l,fiberGramsTarget:o,activeBurnKcal:c,movementCaloriesKcal:w,restingEnergyKcal:b})}function da(e){const{sex:t,ageYears:n,currentWeightKg:r,calorieTarget:s,proteinGramsTarget:d,carbohydrateGramsTarget:g,fatGramsTarget:l,fiberGramsTarget:o,activeBurnKcal:c,movementCaloriesKcal:w,restingEnergyKcal:b}=e,x=c!=null?Math.min(4,Math.max(.1,c/500)):null,m=x!=null?x*.4:null,S=x!=null?x*.8:null,E=m!=null?m*500:null,M=S!=null?S*1e3:null,_=m!=null?m*78:null,T=S!=null?S*312:null,L=c!=null?c*7/7700:null;return{profile:{sex:t,ageYears:n,currentWeightKg:r,calorieTarget:s,activeBurnKcal:c,movementCaloriesKcal:w,restingEnergyKcal:b},macros:[p("calories","Calories",s,"kcal","Plan target from BMR, active burn, and chosen weekly rate.","Forge plan"),p("protein","Protein",d,"g","Higher than the population RDA to preserve lean mass during weight change.","ISSN + Forge plan"),p("carbohydrate","Carbohydrate",g,"g","Remaining fuel after protein and fat. It may sit below the 130g/day adult DRI reference when needed to preserve the calorie target.","NASEM DRI + Forge plan"),p("fat","Total fat",l,"g","Uses the saved plan fat target when present; generated defaults aim for a practical floor around 0.6g/kg or 20-35% of calories when possible.","NASEM AMDR + Forge plan"),p("fiber","Fiber",o,"g","Uses 14g per 1000 kcal as the plan target; the sex/age adult AI remains a reference or stretch value when calories are low.","NASEM DRI"),p("saturated_fat","Saturated fat",s*.1/9,"g max","Keep below 10% of energy.","U.S. Dietary Guidelines"),p("added_sugar","Added sugar",s*.1/4,"g max","Keep below 10% of energy; lower is better when feasible.","U.S. Dietary Guidelines"),p("linoleic_acid","Linoleic acid",kt(t,n),"g","Essential n-6 fatty acid AI.","NASEM DRI"),p("ala","ALA omega-3",t==="male"?1.6:1.1,"g","Essential n-3 fatty acid AI.","NASEM DRI"),p("water","Total water",t==="male"?3.7:2.7,"L","All beverages and food water before extra training replacement.","NASEM DRI")],vitamins:Nt(t,n),minerals:wt(t,n),sportLosses:[p("training_time","Estimated training time",x??"n/a","h/day","Derived from active burn at roughly 500 kcal/h.","Forge sport-loss model"),p("sweat_fluid","Expected sweat fluid",m!=null&&S!=null?se(m,S):"n/a","L/day","Planning range uses 0.4-0.8 L/h; measure body mass change to calibrate.","ACSM"),p("sweat_sodium","Expected sweat sodium",E!=null&&M!=null?se(E,M):"n/a","mg/day","Sodium varies widely; this uses a conservative range around common sweat sodium values.","ACSM + Sports Medicine review"),p("sweat_potassium","Expected sweat potassium",_!=null&&T!=null?se(_,T):"n/a","mg/day","Potassium is usually much smaller than sodium but useful for long/hot sessions.","Sports Medicine review"),p("gross_sport_equivalent","Gross sport burn equivalent",L??"n/a","kg/week","Energy equivalent if the active burn were not eaten back; the plan may already include it.","7700 kcal/kg model")],sportSummary:{trainingHours:x,fluidLossLiters:m!=null&&S!=null?se(m,S):"n/a",sodiumLossMg:E!=null&&M!=null?se(E,M):"n/a",potassiumLossMg:_!=null&&T!=null?se(_,T):"n/a",grossSportWeightEquivalentKgPerWeek:L}}}function Ae({rows:e,compact:t=!1}){return a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"grid gap-2 md:hidden",children:e.map(n=>a.jsxs("div",{className:"grid min-w-0 gap-2 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-3",children:[a.jsxs("div",{className:"flex min-w-0 items-start justify-between gap-3",children:[a.jsx("div",{className:"min-w-0 break-words text-sm font-semibold text-[var(--ui-ink)]",children:n.label}),a.jsxs("div",{className:"shrink-0 text-right text-sm font-semibold text-[var(--ui-ink)]",children:[n.target,a.jsx("div",{className:"text-xs font-normal text-[var(--ui-ink-faint)]",children:n.unit})]})]}),a.jsx("p",{className:"min-w-0 break-words text-xs leading-5 text-[var(--ui-ink-muted)]",children:n.note}),t?null:a.jsx($,{tone:"meta",wrap:!0,className:"justify-self-start",children:n.source})]},n.id))}),a.jsx("div",{className:"hidden overflow-hidden rounded-[20px] border border-[var(--ui-border-subtle)] md:block",children:a.jsx("div",{className:"max-h-[460px] overflow-auto",children:a.jsxs("table",{className:"w-full min-w-[620px] border-collapse text-left text-sm",children:[a.jsx("thead",{className:"sticky top-0 bg-[var(--ui-surface-2)] text-xs uppercase text-[var(--ui-ink-faint)]",children:a.jsxs("tr",{children:[a.jsx("th",{className:"px-4 py-3 font-semibold",children:"Target"}),a.jsx("th",{className:"px-4 py-3 font-semibold",children:"Amount"}),a.jsx("th",{className:"px-4 py-3 font-semibold",children:"Rationale"}),t?null:a.jsx("th",{className:"px-4 py-3 font-semibold",children:"Source"})]})}),a.jsx("tbody",{className:"divide-y divide-[var(--ui-border-subtle)]",children:e.map(n=>a.jsxs("tr",{className:"bg-[var(--ui-surface-1)]",children:[a.jsx("td",{className:"px-4 py-3 font-medium text-[var(--ui-ink)]",children:n.label}),a.jsxs("td",{className:"px-4 py-3 text-[var(--ui-ink)]",children:[a.jsx("span",{className:"font-semibold",children:n.target})," ",a.jsx("span",{className:"text-[var(--ui-ink-faint)]",children:n.unit})]}),a.jsx("td",{className:"px-4 py-3 text-[var(--ui-ink-muted)]",children:n.note}),t?null:a.jsx("td",{className:"px-4 py-3",children:a.jsx($,{tone:"meta",children:n.source})})]},n.id))})]})})})]})}function le({title:e,description:t,children:n}){return a.jsxs(D,{children:[a.jsxs("div",{className:"mb-4",children:[a.jsx("h3",{className:"text-sm font-semibold text-[var(--ui-ink)]",children:e}),a.jsx("p",{className:"mt-1 text-sm text-[var(--ui-ink-muted)]",children:t})]}),n]})}function Ft({view:e}){const t=Ct(e),n=e.target.weeklyRateGoalKg??null,r=n!=null&&Number.isFinite(n)?n*7700/7:null,s=t.profile.restingEnergyKcal,d=t.profile.activeBurnKcal,g=s!=null&&d!=null?s+d:null,l=e.target.bodyGoal??"maintain",o=l.includes("lose")?2:l.includes("gain")?1.8:1.6,c=m=>{var M;const S=(M=t.macros.find(_=>_.id===m))==null?void 0:M.target,E=Number(S);return Number.isFinite(E)?E:null},w=t.profile.sex==="male"?t.profile.ageYears>=51?30:38:t.profile.ageYears>=51?21:25,b=Math.round(t.profile.calorieTarget/1e3*14),x=t.sportSummary.grossSportWeightEquivalentKgPerWeek!=null?`${t.sportSummary.grossSportWeightEquivalentKgPerWeek.toFixed(2)} kg/week`:"n/a";return a.jsx("section",{className:"grid gap-4",children:a.jsxs(z,{className:"p-5",children:[a.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-[var(--ui-ink)]",children:[a.jsx(Ia,{className:"size-4 text-[var(--ui-accent)]"}),"Macro And Micronutrient Targets",a.jsx(la,{values:{sex:t.profile.sex,ageYears:t.profile.ageYears,currentWeightKg:t.profile.currentWeightKg,bmrKcal:null,restingKcal:s,restingSource:s!=null?"saved HealthKit basal/resting or plan value":null,activeKcal:d,maintenanceKcal:g,weeklyRateKg:n,dailyAdjustmentKcal:r,calorieTarget:t.profile.calorieTarget,calorieFloor:t.profile.sex==="male"?1500:1200,proteinReferenceWeightKg:null,proteinFactor:o,proteinGrams:c("protein"),fatGrams:c("fat"),carbohydrateGrams:c("carbohydrate"),fiberGrams:c("fiber"),fiberEnergyAdjustedGrams:b,fiberDriGrams:w}})]}),a.jsx("p",{className:"mt-1 max-w-3xl text-sm text-[var(--ui-ink-muted)]",children:"Daily targets use Forge plan values first, then adult DRI/Dietary Guidelines defaults for nutrients the food log can score as catalog detail improves."})]}),a.jsxs("div",{className:"flex flex-wrap gap-2",children:[a.jsxs($,{tone:"signal",children:[t.profile.calorieTarget.toFixed(0)," kcal"]}),a.jsxs($,{tone:"meta",children:[t.profile.sex,", ",t.profile.ageYears.toFixed(0),"y"]})]})]}),a.jsxs("div",{className:"mt-5 grid gap-4 2xl:grid-cols-[minmax(0,1fr)_minmax(320px,0.58fr)]",children:[a.jsxs("div",{className:"grid gap-4",children:[a.jsx(le,{title:"All macro targets",description:"Calories, protein, carbs, fat, fiber, sugar ceiling, saturated fat ceiling, essential fats, and water.",children:a.jsx(Ae,{rows:t.macros,compact:!0})}),a.jsx(le,{title:"Vitamins",description:"Adult daily vitamin targets from DRI values, adjusted for sex and age where the reference differs.",children:a.jsx(Ae,{rows:t.vitamins})})]}),a.jsxs("div",{className:"grid content-start gap-4",children:[a.jsxs(le,{title:"Expected sport losses",description:"Planning range from active burn. Calibrate with pre/post workout weight when possible.",children:[a.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[a.jsx(N,{label:"Active burn",value:t.profile.activeBurnKcal!=null?`${t.profile.activeBurnKcal.toFixed(0)} kcal`:"n/a"}),a.jsx(N,{label:"Sport equivalent",value:x}),a.jsx(N,{label:"Sweat fluid",value:`${t.sportSummary.fluidLossLiters} L`}),a.jsx(N,{label:"Sodium loss",value:`${t.sportSummary.sodiumLossMg} mg`})]}),a.jsxs("div",{className:"mt-4 flex items-start gap-3 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-3 text-sm text-[var(--ui-ink-muted)]",children:[a.jsx(ia,{className:"mt-0.5 size-4 shrink-0 text-[var(--ui-accent)]"}),a.jsx("span",{children:"Sport burn is shown as gross energy equivalent, not a promise of scale loss. The calorie plan may already include active burn, and replacement depends on appetite, heat, sodium loss, and actual intake."})]})]}),a.jsx(le,{title:"Minerals & oligoelements",description:"Daily mineral and trace-element targets including sodium ceiling and potassium AI.",children:a.jsx(Ae,{rows:t.minerals,compact:!0})}),a.jsx(le,{title:"Sport electrolyte model",description:"Use these as expected losses, not rigid supplement prescriptions.",children:a.jsx("div",{className:"grid gap-3",children:t.sportLosses.map(m=>a.jsxs("div",{className:"flex items-start justify-between gap-3 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-3",children:[a.jsxs("div",{className:"min-w-0",children:[a.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-[var(--ui-ink)]",children:[m.id==="sweat_fluid"?a.jsx(La,{className:"size-4 text-[var(--ui-accent)]"}):a.jsx(Pa,{className:"size-4 text-[var(--ui-accent)]"}),m.label]}),a.jsx("p",{className:"mt-1 text-xs text-[var(--ui-ink-faint)]",children:m.note})]}),a.jsxs("div",{className:"shrink-0 text-right text-sm font-semibold text-[var(--ui-ink)]",children:[m.target,a.jsx("div",{className:"text-xs font-normal text-[var(--ui-ink-faint)]",children:m.unit})]})]},m.id))})})]})]})]})})}function ee(e,t){var r;if(!e)return null;const n=e.match(new RegExp(`${t}=([^;]+)`));return((r=n==null?void 0:n[1])==null?void 0:r.trim())??null}function ae(e){const t=typeof e=="number"?e:Number(e);return Number.isFinite(t)&&t>0?t:null}function ua(e,t){if(t==="maintain")return 0;const n=t==="gain"?.0025:.005,r=t==="gain"?.1:.2,s=t==="gain"?.35:Math.max(.5,e*.01);return Math.min(s,Math.max(r,e*n))}function ga(e,t){return t==="gain"?e*1.03:t==="maintain"?e:e*.95}function ma(e){return e.toFixed(1)}function Mt(e,t){return e==="male"?t>=51?30:38:t>=51?21:25}function Ze(e,t){const n=e/100;return n>0?t*n*n:null}function Gt(e){const t=e.goalMode==="lose"&&e.goalWeightKg!=null?Math.min(e.currentWeightKg,e.goalWeightKg):e.currentWeightKg,n=Ze(e.heightCm,30),r=Ze(e.heightCm,25);if(n!=null&&r!=null&&e.currentWeightKg>n){const s=r+(e.currentWeightKg-r)*.25;return Math.min(t,s)}return t}function St(e,t){const n=ae(e.currentWeightKg)??80;return{...e,goalMode:t,goalWeightKg:ma(ga(n,t)),weeklyRateKg:ua(n,t).toFixed(2)}}function Ee(e){const t=A(e.weightTrend.latestWeightKg),n=e.target,r=ee(n.notes,"sex"),s=ee(n.notes,"age_years"),d=ee(n.notes,"height_cm"),g=A(e.energyModel.activeBurnKcal)??A(e.energyModel.activeEnergyCalories)??A(e.energyModel.movementCaloriesKcal)??A(ee(n.notes,"activity_kcal"))??0,l=A(e.energyModel.restingEnergyCalories)??A(ee(n.notes,"resting_kcal"))??null,o=n.bodyGoal??"",c=o.includes("gain")?"gain":o.includes("maintain")?"maintain":"lose",w=n.weightGoalKg??n.goalBodyWeightKg??null,b=t??80;return{goalMode:c,sex:r==="female"?"female":"male",ageYears:ae(s)?String(s):"",heightCm:ae(d)?String(d):"",currentWeightKg:t?t.toFixed(1):"",goalWeightKg:w?String(w):ma(ga(b,c)),weeklyRateKg:n.weeklyRateGoalKg!==null&&n.weeklyRateGoalKg!==void 0?String(Math.abs(n.weeklyRateGoalKg)):ua(b,c).toFixed(2),activeCaloriesKcal:g.toFixed(0),restingCaloriesKcal:l!=null?l.toFixed(0):"",dietStyle:n.dietStyle??""}}function Kt(e){const t=ae(ee(e.target.notes,"age_years"))!=null,n=ae(ee(e.target.notes,"height_cm"))!=null,r=A(e.weightTrend.latestWeightKg)!=null,s=typeof e.target.bodyGoal=="string"&&e.target.bodyGoal.trim().length>0&&e.target.calorieTarget>0&&e.target.proteinGramsTarget>0;return t&&n&&r&&s}function At(e){const t=e.energyModel;return`This is the default active allowance used when today has no same-day workout, movement, step, or active-energy evidence. ${t.energySourceConfidence==="healthkit_daily_active_energy"?"HealthKit daily active energy is the active-burn source; workout and movement values are only visible evidence and are not added again.":t.energySourceConfidence==="workout_movement_fallback"?"HealthKit daily active energy is missing, so active burn already equals workout average plus movement-trip average.":"No measured active-burn stream is available, so Forge is using the plan/default estimate."} Current evidence: active burn ${i(t.activeBurnKcal)} kcal/day, workout average ${i(t.workoutEnergyKcal)} kcal/day, movement average ${i(t.movementCaloriesKcal)} kcal/day, today's workout ${i(t.todayWorkoutEnergyKcal)} kcal, today's movement ${i(t.todayMovementCaloriesKcal)} kcal.`}function ha(e){const t=Number(e.currentWeightKg)||80,n=Number(e.heightCm)||178,r=Number(e.ageYears)||35,s=ae(e.goalWeightKg),d=Math.max(0,Number(e.activeCaloriesKcal)||0),g=ae(e.restingCaloriesKcal),l=e.sex==="male"?5:-161,o=10*t+6.25*n-5*r+l,c=g??o,w=c+d,b=Math.abs(Number(e.weeklyRateKg)||0),x=e.goalMode==="lose"?-b:e.goalMode==="gain"?b:0,m=x*7700/7,S=e.sex==="male"?1500:1200,E=Math.round(w+m),M=Math.max(S,E),_=Gt({currentWeightKg:t,goalWeightKg:s,heightCm:n,goalMode:e.goalMode}),T=e.goalMode==="lose"?2:e.goalMode==="gain"?1.8:1.6,L=Math.round(_*T),B=Math.floor(M*.45/4),P=Math.max(1,Math.min(L,B)),H=_*.6,te=M*.25/9,J=Math.max(0,(M-P*4)/9),O=Math.max(0,Math.floor(Math.min(J,M*.35/9,Math.max(H,te)))),U=Math.max(0,Math.floor((M-P*4-O*9)/4)),ne=Math.round(M/1e3*14),re=Mt(e.sex,r),oe=ne,Z=Math.round(M*.1/9),Q=Math.round(M*.1/4);return{bmr:Math.round(o),restingCalories:Math.round(c),restingSource:g!=null?"HealthKit basal/resting":"Mifflin-St Jeor",activeCalories:Math.round(d),maintenanceCalories:Math.round(w),plannedCalorieTarget:E,minimumCalorieFloor:S,weeklyRateGoalKg:x,dailyEnergyAdjustment:Math.round(m),calorieTarget:M,proteinReferenceWeight:Math.round(_*10)/10,proteinGramsTarget:P,carbohydrateGramsTarget:U,fatGramsTarget:O,fiberGramsTarget:oe,fiberEnergyAdjustedGrams:ne,fiberDriGrams:re,saturatedFatLimitGrams:Z,addedSugarLimitGrams:Q}}function Et(e){const t=[],n=Number(e.ageYears),r=Number(e.heightCm),s=Number(e.currentWeightKg),d=Number(e.goalWeightKg),g=Number(e.weeklyRateKg),l=e.activeCaloriesKcal.trim()?Number(e.activeCaloriesKcal):Number.NaN,o=e.restingCaloriesKcal.trim()?Number(e.restingCaloriesKcal):null;return(!Number.isFinite(n)||n<13||n>100)&&t.push("- Enter the user's real age. Forge uses it in Mifflin-St Jeor resting metabolism."),(!Number.isFinite(r)||r<120||r>230)&&t.push("- Enter height in cm. Height changes BMR and protein reference weight."),(!Number.isFinite(s)||s<30||s>300)&&t.push("- Enter current weight in kg. Use the latest known body measure as the starting state."),e.goalMode!=="maintain"&&(!Number.isFinite(d)||d<30||d>300)&&t.push("- Enter a target weight for the selected loss or gain objective."),(!Number.isFinite(g)||g<0)&&t.push("- Enter a non-negative weekly change rate in kg/week."),Number.isFinite(g)&&g>Math.max(1.5,s*.02)&&t.push("- The weekly rate is very aggressive. Choose a slower default unless this is a supervised plan."),(!Number.isFinite(l)||l<0||l>3e3)&&t.push("- Enter average active calories per day. Zero is valid only when Forge has no activity evidence."),o!=null&&(!Number.isFinite(o)||o<900||o>3500)&&t.push("- Resting calories should be blank for formula mode or a plausible HealthKit basal/resting value."),t.length>0?t.join(`
|
|
2
|
-
`):null}function _t(e){const t=ha(e),n=Number(e.goalWeightKg);return{calorieTarget:t.calorieTarget,proteinGramsTarget:t.proteinGramsTarget,fiberGramsTarget:t.fiberGramsTarget,carbohydrateGramsTarget:t.carbohydrateGramsTarget,fatGramsTarget:t.fatGramsTarget,weightGoalKg:Number.isFinite(n)?n:null,weeklyRateGoalKg:t.weeklyRateGoalKg,dietStyle:e.dietStyle,bodyGoal:e.goalMode,notes:["Forge science plan",`height_cm=${Number(e.heightCm)||"unknown"}`,`age_years=${Number(e.ageYears)||"unknown"}`,`sex=${e.sex}`,"bmr_formula=Mifflin-St Jeor",`resting_kcal=${t.restingCalories}`,`activity_kcal=${t.activeCalories}`,`maintenance_kcal=${t.maintenanceCalories}`,"rate_model=7700 kcal/kg"].join("; ")}}function $t({open:e,onOpenChange:t,view:n,value:r,onChange:s,onSubmit:d,pending:g,error:l}){const o=F.useMemo(()=>ha(r),[r]),c=F.useMemo(()=>da({sex:r.sex,ageYears:Number(r.ageYears)||35,currentWeightKg:Number(r.currentWeightKg)||80,calorieTarget:o.calorieTarget,proteinGramsTarget:o.proteinGramsTarget,carbohydrateGramsTarget:o.carbohydrateGramsTarget,fatGramsTarget:o.fatGramsTarget,fiberGramsTarget:o.fiberGramsTarget,activeBurnKcal:o.activeCalories,movementCaloriesKcal:A(n.energyModel.movementCaloriesKcal),restingEnergyKcal:o.restingCalories}),[o,r,n.energyModel.movementCaloriesKcal]),w=[{id:"profile",eyebrow:"Current state",title:"Confirm the body data Forge knows",description:"These fields drive resting metabolism. Saved values are reused when Forge has them.",render:(b,x)=>a.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[a.jsx(y,{label:"Sex",children:a.jsx(Ve,{value:b.sex,onChange:m=>x({sex:m}),options:[{value:"male",label:"Male"},{value:"female",label:"Female"}]})}),a.jsx(y,{label:"Age",children:a.jsx(k,{inputMode:"numeric",value:b.ageYears,onChange:m=>x({ageYears:m.target.value}),placeholder:"35"})}),a.jsx(y,{label:"Height cm",children:a.jsx(k,{inputMode:"decimal",value:b.heightCm,onChange:m=>x({heightCm:m.target.value}),placeholder:"178"})}),a.jsx(y,{label:"Current weight kg",children:a.jsx(k,{inputMode:"decimal",value:b.currentWeightKg,onChange:m=>x({currentWeightKg:m.target.value}),placeholder:"80.0"})})]})},{id:"objective",eyebrow:"Goal",title:"Choose what should happen next",description:"Forge proposes a default target and weekly rate from current weight; you can change both.",render:(b,x)=>a.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[a.jsx("div",{className:"md:col-span-2",children:a.jsx(Ve,{columns:3,value:b.goalMode,onChange:m=>x(St(b,m)),options:[{value:"lose",label:"Lose fat",description:"Default: about 0.5% body weight per week."},{value:"gain",label:"Gain mass",description:"Default: small surplus around 0.25% per week."},{value:"maintain",label:"Maintain",description:"Hold weight while optimizing signals."}]})}),a.jsx(y,{label:"Target weight kg",hint:"Filled from the objective; change it anytime.",children:a.jsx(k,{inputMode:"decimal",value:b.goalWeightKg,onChange:m=>x({goalWeightKg:m.target.value}),placeholder:"75.0"})}),a.jsx(y,{label:"Weekly change kg",hint:"Loss/gain rate is converted to kcal/day with the 7700 kcal/kg planning model.",children:a.jsx(k,{inputMode:"decimal",value:b.weeklyRateKg,onChange:m=>x({weeklyRateKg:m.target.value}),placeholder:"0.35"})})]})},{id:"activity",eyebrow:"Activity",title:"Add active burn to resting burn",description:"Active calories are independent evidence from HealthKit, workouts, and movement. The objective only changes the deficit or surplus.",render:(b,x)=>a.jsxs("div",{className:"grid gap-4",children:[a.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[a.jsx(y,{label:"Resting calories/day",hint:`Forge uses HealthKit basal energy when present, otherwise Mifflin-St Jeor BMR. Current formula value: ${o.bmr} kcal.`,children:a.jsx(k,{inputMode:"decimal",value:b.restingCaloriesKcal,onChange:m=>x({restingCaloriesKcal:m.target.value}),placeholder:String(o.bmr)})}),a.jsx(y,{label:"Average active calories/day",hint:At(n),children:a.jsx(k,{inputMode:"decimal",value:b.activeCaloriesKcal,onChange:m=>x({activeCaloriesKcal:m.target.value}),placeholder:"350"})})]}),a.jsxs("div",{className:"grid gap-3 rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4 md:grid-cols-3",children:[a.jsx(N,{label:o.restingSource,value:`${o.restingCalories} kcal`}),a.jsx(N,{label:"Maintenance",value:`${o.maintenanceCalories} kcal`}),a.jsx(N,{label:"Daily adjustment",value:`${o.dailyEnergyAdjustment>0?"+":""}${o.dailyEnergyAdjustment} kcal`})]})]})},{id:"macros",eyebrow:"Macros",title:"Validate calories, macros, and limits",description:"Target intake equals resting burn plus active burn plus the objective adjustment. Macros are generated from protein-per-kg, a practical fat floor, remaining carbohydrates, fiber density, and dietary limits.",render:(b,x)=>a.jsxs("div",{className:"grid gap-4",children:[a.jsxs("div",{className:"flex items-start justify-between gap-3 rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3",children:[a.jsx("div",{className:"min-w-0 text-sm leading-6 text-[var(--ui-ink-muted)]",children:"Inspect the exact math behind the current calories, macro targets, and sport-loss preview."}),a.jsx(la,{values:{sex:b.sex,ageYears:Number(b.ageYears)||null,currentWeightKg:Number(b.currentWeightKg)||null,heightCm:Number(b.heightCm)||null,bmrKcal:o.bmr,restingKcal:o.restingCalories,restingSource:o.restingSource,activeKcal:o.activeCalories,maintenanceKcal:o.maintenanceCalories,weeklyRateKg:o.weeklyRateGoalKg,dailyAdjustmentKcal:o.dailyEnergyAdjustment,calorieTarget:o.calorieTarget,calorieFloor:o.minimumCalorieFloor,proteinReferenceWeightKg:o.proteinReferenceWeight,proteinFactor:b.goalMode==="lose"?2:b.goalMode==="gain"?1.8:1.6,proteinGrams:o.proteinGramsTarget,fatGrams:o.fatGramsTarget,carbohydrateGrams:o.carbohydrateGramsTarget,fiberGrams:o.fiberGramsTarget,fiberEnergyAdjustedGrams:o.fiberEnergyAdjustedGrams,fiberDriGrams:o.fiberDriGrams}})]}),a.jsxs("div",{className:"grid gap-3 md:grid-cols-4 xl:grid-cols-7",children:[a.jsx(N,{label:"Calories",value:`${o.calorieTarget}`}),a.jsx(N,{label:"Protein",value:`${o.proteinGramsTarget}g`}),a.jsx(N,{label:"Carbs",value:`${o.carbohydrateGramsTarget}g`}),a.jsx(N,{label:"Fat",value:`${o.fatGramsTarget}g`}),a.jsx(N,{label:"Fiber",value:`${o.fiberGramsTarget}g`}),a.jsx(N,{label:"Sat fat max",value:`${o.saturatedFatLimitGrams}g`}),a.jsx(N,{label:"Added sugar max",value:`${o.addedSugarLimitGrams}g`})]}),a.jsxs("div",{className:"grid gap-4 rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[a.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[a.jsxs("div",{children:[a.jsx("div",{className:"text-sm font-semibold text-[var(--ui-ink)]",children:"Micronutrient and sport-loss preview"}),a.jsx("div",{className:"mt-1 text-sm leading-6 text-[var(--ui-ink-muted)]",children:"The dashboard will track vitamin, mineral, trace-element, water, sodium-ceiling, essential-fat, and sport-loss targets from this plan."})]}),a.jsxs("div",{className:"flex flex-wrap gap-2",children:[a.jsxs($,{tone:"meta",children:[c.vitamins.length," vitamins"]}),a.jsxs($,{tone:"meta",children:[c.minerals.length," minerals"]}),a.jsxs($,{tone:"signal",children:[c.sportSummary.fluidLossLiters," L sweat"]})]})]}),a.jsxs("div",{className:"grid gap-3 md:grid-cols-4",children:[a.jsx(N,{label:"Sport sodium loss",value:`${c.sportSummary.sodiumLossMg} mg`}),a.jsx(N,{label:"Sport potassium loss",value:`${c.sportSummary.potassiumLossMg} mg`}),a.jsx(N,{label:"Water baseline",value:r.sex==="male"?"3.7 L":"2.7 L"}),a.jsx(N,{label:"Essential fats",value:r.sex==="male"?"17g LA / 1.6g ALA":"12g LA / 1.1g ALA"})]})]}),a.jsx(y,{label:"Diet style or constraints",children:a.jsx(ve,{value:b.dietStyle,onChange:m=>x({dietStyle:m.target.value}),placeholder:"Mediterranean, high protein, no lactose, low FODMAP trial..."})})]})}];return a.jsx(je,{open:e,onOpenChange:t,eyebrow:"Weight plan",title:"Set weight objective",description:"Build an editable calorie and macro plan.",value:r,onChange:s,steps:w,onSubmit:d,submitLabel:"Save plan",pending:g,pendingLabel:"Saving plan",error:l,draftPersistenceKey:"weight-loss-plan"})}const Tt={tsp:5,tbsp:15,cup:240};function fe(){return{mealLabel:"Meal",notes:"",source:"search",selectedItems:[]}}function G(e,t,n){return typeof e!="number"||!Number.isFinite(e)?null:xa(n)==="grams"?e:t>0?Math.round(e/t*10)/10:e}function Dt(e){const t=Number.isFinite(e.quantity)&&e.quantity>0?e.quantity:1,n=e.unit??"serving",r=n==="grams"?e.grams??t:e.grams!=null&&t>0?e.grams/t:e.grams;return{id:e.foodId??e.id,source:"saved_meal",sourceId:e.foodId??e.id,name:e.name,brand:e.brand??null,barcode:null,servingLabel:n,servingGrams:r??null,calories:G(e.calories,t,n),proteinGrams:G(e.proteinGrams,t,n),carbohydrateGrams:G(e.carbohydrateGrams,t,n),fatGrams:G(e.fatGrams,t,n),fiberGrams:G(e.fiberGrams,t,n),sugarGrams:G(e.sugarGrams,t,n),sodiumMg:G(e.sodiumMg,t,n),potassiumMg:G(e.potassiumMg,t,n),caffeineMg:G(e.caffeineMg,t,n),alcoholGrams:G(e.alcoholGrams,t,n),glycemicIndex:e.glycemicIndex??null,novaGroup:e.novaGroup??null,tags:e.tags??[],confidence:e.confidence??null}}function It(e,t,n){const r=Number.isFinite(e.quantity)&&e.quantity>0?e.quantity:1,s=e.unit??"serving",d=s==="grams"||s==="g"?e.grams??r:e.grams!=null&&r>0?e.grams/r:e.grams;return{id:e.foodId??`${n}_${t}_${Date.now()}`,source:n,sourceId:e.foodId??null,name:e.name,brand:e.brand??null,barcode:null,servingLabel:s,servingGrams:d??null,calories:G(e.calories,r,s),proteinGrams:G(e.proteinGrams,r,s),carbohydrateGrams:G(e.carbohydrateGrams,r,s),fatGrams:G(e.fatGrams,r,s),fiberGrams:G(e.fiberGrams,r,s),sugarGrams:G(e.sugarGrams,r,s),sodiumMg:G(e.sodiumMg,r,s),potassiumMg:G(e.potassiumMg,r,s),caffeineMg:G(e.caffeineMg,r,s),alcoholGrams:G(e.alcoholGrams,r,s),glycemicIndex:e.glycemicIndex??null,novaGroup:e.novaGroup??null,tags:e.tags??[],confidence:e.confidence??null}}function Lt(e){if(!e)return null;const n=e.toLowerCase().replace(",",".").match(/(\d+(?:\.\d+)?)\s*(kg|g|gram|grams|ml|l)\b/);if(!n)return null;const r=Number(n[1]);if(!Number.isFinite(r)||r<=0)return null;const s=n[2];return s==="kg"||s==="l"?r*1e3:r}function ue(e){return typeof e.servingGrams=="number"&&Number.isFinite(e.servingGrams)&&e.servingGrams>0?e.servingGrams:Lt(e.servingLabel)}function Pt(e){const t=ue(e);return t!=null?`${i(t)} g`:e.servingLabel??"serving"}function pa(e){const t=Number(e.amount)||0;if(t<=0)return null;const n=ue(e.food);return e.unit==="grams"?t:e.unit==="tsp"||e.unit==="tbsp"||e.unit==="cup"?t*Tt[e.unit]:n!=null?t*n:null}function Xe(e){return!(e.unit==="grams"||e.unit==="tsp"||e.unit==="tbsp"||e.unit==="cup")||ue(e.food)!=null?null:"Add base grams before using grams or household measures. Without a denominator, Forge will not guess a ratio."}function xa(e){const t=e==null?void 0:e.trim().toLowerCase();return t==="g"||t==="gram"||t==="grams"?"grams":t==="tsp"||t==="teaspoon"?"tsp":t==="tbsp"||t==="tablespoon"?"tbsp":t==="cup"?"cup":t==="serving"||t==="servings"?"serving":"unit"}function Rt(e){switch(e){case"manual":case"search":case"barcode":case"chatgpt":case"photo":case"saved_meal":return e;default:return"manual"}}function Wt(e){return{mealLabel:e.mealLabel??"Meal",notes:e.notes??"",loggedAt:e.loggedAt,dayKey:e.dayKey,source:Rt(e.source),selectedItems:e.items.map(t=>({localId:t.id,food:Dt(t),amount:String(t.quantity||1),unit:t.unit??"serving"}))}}function Bt(e,t=e.source??"manual"){return{mealLabel:e.mealLabel??"Meal",notes:e.notes??"",loggedAt:e.loggedAt,dayKey:e.dayKey,source:e.source??"manual",selectedItems:e.items.map((n,r)=>({localId:`${t}-${r}-${Date.now()}`,food:It(n,r,t),amount:String(n.quantity||1),unit:xa(n.unit)}))}}function ba(){return{id:`custom_food_${Date.now()}`,source:"manual",sourceId:null,name:"Custom food",brand:null,barcode:null,servingLabel:"100 g",servingGrams:100,calories:null,proteinGrams:null,carbohydrateGrams:null,fatGrams:null,fiberGrams:null,sugarGrams:null,sodiumMg:null,potassiumMg:null,caffeineMg:null,alcoholGrams:null,glycemicIndex:null,novaGroup:null,tags:["custom"],confidence:1}}function Ht(){return{mealLabel:"Meal",notes:"",source:"manual",selectedItems:[{localId:`custom-${Date.now()}`,food:ba(),amount:"100",unit:"grams"}]}}function qt({open:e,onOpenChange:t,value:n,onChange:r,foodResults:s,searchPending:d,chatGptPending:g=!1,chatGptError:l=null,logPending:o,onSearch:c,onParseWithChatGpt:w,onSubmit:b,mode:x="create",intent:m="search",initialStepId:S}){const[E,M]=F.useState(""),[_,T]=F.useState(""),[L,B]=F.useState(null),P=F.useMemo(()=>Yt(n.selectedItems),[n.selectedItems]),H=f=>r({...n,...f}),te=f=>{H({selectedItems:[...n.selectedItems,{localId:`${f.id}-${Date.now()}`,food:f,amount:"1",unit:"serving"}]}),B(null)},J=()=>{te(ba())},O=async()=>{const f=_.trim();!f||!w||(await w(f),T(""))},U=(f,v)=>{H({selectedItems:n.selectedItems.map(j=>j.localId===f?{...j,...v}:j)})},ne=(f,v)=>{H({selectedItems:n.selectedItems.map(j=>j.localId===f?{...j,food:{...j.food,...v}}:j)})},re=f=>{H({selectedItems:n.selectedItems.filter(v=>v.localId!==f)})},oe=async()=>{n.selectedItems.length!==0&&await b()},Z=a.jsxs(D,{className:"grid gap-3",children:[a.jsx(y,{label:"Ask ChatGPT",labelHelp:"Uses the connected OpenAI Codex OAuth / ChatGPT subscription model to create a reviewable candidate meal draft. It does not use the metered OpenAI Platform API.",children:a.jsx(ve,{value:_,onChange:f=>T(f.target.value),placeholder:"Example: 2 eggs, 150g Greek yogurt, one banana, and a cappuccino..."})}),l?a.jsx("div",{className:"rounded-[18px] border border-[var(--ui-danger-soft)] bg-[var(--ui-danger-soft)] px-3 py-2 text-xs leading-5 text-[var(--ui-ink)]",children:l}):null,a.jsxs(K,{type:"button",variant:m==="chatgpt"?"primary":"secondary",pending:g,pendingLabel:"Parsing",disabled:!_.trim()||!w,onClick:()=>void O(),children:[a.jsx(ta,{className:"size-4"}),"Parse with ChatGPT"]})]}),Q=a.jsx(D,{className:"grid gap-3",children:a.jsxs("div",{className:"flex items-start justify-between gap-3",children:[a.jsxs("div",{className:"min-w-0",children:[a.jsx("div",{className:"text-sm font-semibold text-[var(--ui-ink-strong)]",children:"Create custom food"}),a.jsx("div",{className:"mt-1 text-xs leading-5 text-[var(--ui-ink-soft)]",children:"Start from a blank food, then define base grams, calories, macros, sodium, and exact quantity in the next step."})]}),a.jsxs(K,{type:"button",size:"sm",onClick:J,children:[a.jsx(De,{className:"size-4"}),"Add custom"]})]})}),V=m==="chatgpt"?[Z,Q]:[Q,Z],ge=[{id:"search",eyebrow:m==="chatgpt"?"ChatGPT food parser":"Food",title:m==="chatgpt"?"Describe the meal, then review every item":"Search, create, or ask ChatGPT",description:m==="chatgpt"?"ChatGPT creates a candidate meal through the subscription-backed connection; you still review quantities and nutrients before saving.":"Search the catalog, create a custom food, or use ChatGPT to turn rough meal text into editable items.",render:()=>a.jsxs("div",{className:"grid gap-4",children:[a.jsxs("div",{className:"grid gap-3 md:grid-cols-[minmax(0,1fr)_auto]",children:[a.jsx(y,{label:"Food search",labelHelp:"Search returns food candidates with per-serving nutrition. Click a result to inspect macros before adding it to the meal draft.",children:a.jsx(k,{value:E,onChange:f=>M(f.target.value),placeholder:"Search eggs, yogurt, sourdough..."})}),a.jsxs(K,{type:"button",variant:"secondary",pending:d,disabled:!E.trim(),onClick:()=>c(E),children:[a.jsx(na,{className:"size-4"}),"Search"]})]}),a.jsx("div",{className:"grid gap-3 md:grid-cols-2",children:V.map((f,v)=>a.jsx("div",{children:f},`${m}-assistant-panel-${v}`))}),L?a.jsx(Vt,{food:L,onAdd:()=>te(L)}):null,a.jsx("div",{className:"grid gap-3",children:s.map(f=>a.jsx(D,{interactive:!0,className:"p-0",children:a.jsx("button",{type:"button",className:"block w-full rounded-[22px] p-4 text-left",onClick:()=>B(f),children:a.jsxs("div",{className:"flex items-start justify-between gap-3",children:[a.jsxs("div",{className:"min-w-0",children:[a.jsx("div",{className:"truncate text-sm font-semibold text-[var(--ui-ink-strong)]",children:f.name}),a.jsx("div",{className:"mt-1 truncate text-xs text-[var(--ui-ink-faint)]",children:[f.brand,f.servingLabel,f.source].filter(Boolean).join(" · ")})]}),a.jsxs($,{tone:"meta",children:[i(f.calories)," kcal"]})]})})},f.id))})]})},{id:"amounts",eyebrow:m==="custom"?"Custom food":"Quantity",title:m==="custom"?"Define the food and exact dose":"Set exactly how much you ate",description:"Scale by grams, servings, household measures, or units before saving the meal.",render:f=>a.jsxs("div",{className:"grid gap-4",children:[f.selectedItems.length===0?a.jsx("div",{className:"rounded-[22px] border border-dashed border-[var(--ui-border-strong)] bg-[var(--ui-surface-1)] p-5 text-sm text-[var(--ui-ink-soft)]",children:"Add at least one food from the search step."}):null,f.selectedItems.map(v=>a.jsxs(D,{className:"grid gap-3",children:[a.jsxs("div",{className:"flex items-start justify-between gap-3",children:[a.jsxs("div",{children:[a.jsx("div",{className:"text-sm font-semibold text-[var(--ui-ink-strong)]",children:v.food.name}),a.jsxs("div",{className:"text-xs text-[var(--ui-ink-faint)]",children:["Base: ",i(v.food.calories)," kcal per"," ",Pt(v.food)]})]}),a.jsxs(K,{type:"button",size:"sm",variant:"ghost",onClick:()=>re(v.localId),children:[a.jsx(sa,{className:"size-4"}),"Remove"]})]}),a.jsxs("div",{className:"grid gap-3 md:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_auto]",children:[a.jsx(y,{label:"Quantity",labelHelp:"This is the amount actually eaten. Forge converts the selected unit to an eaten gram equivalent when base grams are known, then scales every nutrient by eaten grams divided by base grams.",children:a.jsx(k,{inputMode:"decimal",value:v.amount,onChange:j=>U(v.localId,{amount:j.target.value}),placeholder:"1"})}),a.jsx(y,{label:"Unit",labelHelp:"Servings multiply the base serving. Grams, teaspoons, tablespoons, and cups use a gram conversion table and require base grams.",children:a.jsxs("select",{className:"interactive-tap w-full rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3 text-[15px] text-[var(--ui-ink-strong)] outline-none",value:v.unit,onChange:j=>U(v.localId,{unit:j.target.value}),children:[a.jsx("option",{value:"serving",children:"serving"}),a.jsx("option",{value:"grams",children:"grams"}),a.jsx("option",{value:"unit",children:"unit"}),a.jsx("option",{value:"tsp",children:"teaspoon"}),a.jsx("option",{value:"tbsp",children:"tablespoon"}),a.jsx("option",{value:"cup",children:"cup"})]})}),a.jsxs($,{tone:"signal",children:[i(ye(v).calories)," kcal"]})]}),Xe(v)?a.jsx("div",{className:"rounded-[18px] border border-[var(--ui-warning-soft)] bg-[var(--ui-warning-soft)] px-3 py-2 text-xs leading-5 text-[var(--ui-ink)]",children:Xe(v)}):a.jsxs("div",{className:"text-xs text-[var(--ui-ink-faint)]",children:[i(Number(v.amount)||0)," ",v.unit," ="," ",i(pa(v))," g eaten; ratio ="," ",i(ye(v).scale),"x the base nutrition."]}),a.jsx(Qt,{item:v,onChange:j=>ne(v.localId,j)})]},v.localId)),a.jsxs("div",{className:"grid gap-3 rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4 md:grid-cols-4",children:[a.jsx(N,{label:"Calories",value:i(P.calories)}),a.jsx(N,{label:"Protein",value:`${i(P.proteinGrams)}g`}),a.jsx(N,{label:"Carbs",value:`${i(P.carbohydrateGrams)}g`}),a.jsx(N,{label:"Fat",value:`${i(P.fatGrams)}g`})]})]})},{id:"context",eyebrow:"Context",title:"Meal label and notes",description:"Add how it felt, where it happened, or anything relevant to future pattern detection.",render:(f,v)=>a.jsxs("div",{className:"grid gap-4",children:[a.jsx(y,{label:"Meal label",labelHelp:"The label groups the edited items as breakfast, lunch, snack, dinner, or any personal meal name.",children:a.jsx(k,{value:f.mealLabel,onChange:j=>v({mealLabel:j.target.value}),placeholder:"Breakfast"})}),a.jsx(y,{label:"Notes",labelHelp:"Use notes for context the numbers do not capture: hunger, cravings, gut comfort, energy, timing, place, or workout relationship.",children:a.jsx(ve,{value:f.notes,onChange:j=>v({notes:j.target.value}),placeholder:"Energy, cravings, gut comfort, training effect..."})})]})}];return a.jsx(je,{open:e,onOpenChange:t,eyebrow:"Food log",title:x==="edit"?"Edit food":"Add food",description:"Search, inspect, scale, edit nutrition parameters, and save meal items.",value:n,onChange:r,steps:ge,initialStepId:S,onSubmit:oe,submitLabel:x==="edit"?"Update meal":"Save meal",pending:o,pendingLabel:"Saving meal",resolveError:f=>f!=="search"&&n.selectedItems.length===0?"Select at least one food before saving.":null,draftPersistenceKey:`weight-loss-food-log.${x}.${m}`})}function fa(e){return{loggedAt:e.loggedAt,dayKey:e.dayKey??$e(),mealLabel:ea(e.mealLabel,"Meal"),source:e.source??"search",confirmationState:"confirmed",notes:ea(e.notes),items:e.selectedItems.map(t=>{const n=ye(t);return{foodId:zt(t),name:t.food.name,brand:t.food.brand,quantity:Number(t.amount)||1,unit:t.unit,grams:n.grams,calories:n.calories,proteinGrams:n.proteinGrams,carbohydrateGrams:n.carbohydrateGrams,fatGrams:n.fatGrams,fiberGrams:n.fiberGrams,sugarGrams:n.sugarGrams,sodiumMg:n.sodiumMg,potassiumMg:n.potassiumMg,caffeineMg:n.caffeineMg,alcoholGrams:n.alcoholGrams,novaGroup:t.food.novaGroup,tags:t.food.tags,confidence:.9}})}}function ea(e,t=""){return typeof e=="string"?e:t}function zt(e){return e.food.source==="manual"||e.food.source==="chatgpt"||e.food.id.startsWith("custom_food_")||e.food.id.startsWith("chatgpt_")?null:e.food.id}function Ot(e){return fa(e)}function Ut(e){const t=Number(e);return Number.isFinite(t)?t:null}function Qt({item:e,onChange:t}){const n=e.food,r=(s,d)=>t({[s]:Ut(d)});return a.jsxs("div",{className:"grid gap-3 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-3",children:[a.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-[var(--ui-ink-strong)]",children:["Food parameters",a.jsx(de,{label:`Explain editable food parameters for ${n.name}`,content:"These are the nutrient values for the base serving shown above. Changing them recalculates the eaten quantity and stores the corrected values in Forge."})]}),a.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[a.jsx(y,{label:"Base label",labelHelp:"Human-readable denominator shown for the nutrition values, such as 100 g, 220 g, one burger, or one scoop.",children:a.jsx(k,{value:n.servingLabel??"",onChange:s=>t({servingLabel:s.target.value||null}),placeholder:"100 g"})}),a.jsx(y,{label:"Base grams",labelHelp:"Gram denominator for the base nutrition values. If kcal is per 220 g, enter 220. If kcal is per 100 g, enter 100.",children:a.jsx(k,{inputMode:"decimal",value:n.servingGrams??"",onChange:s=>r("servingGrams",s.target.value),placeholder:"100"})}),a.jsx(y,{label:"Food name",labelHelp:"Rename the item when the database result is too generic or wrong.",children:a.jsx(k,{value:n.name,onChange:s=>t({name:s.target.value})})}),a.jsx(y,{label:"Brand",labelHelp:"Optional brand or preparation source, useful when the same food has different nutrition.",children:a.jsx(k,{value:n.brand??"",onChange:s=>t({brand:s.target.value||null})})})]}),a.jsxs("div",{className:"grid gap-3 md:grid-cols-4",children:[a.jsx(y,{label:"kcal",labelHelp:"Kilocalories for the base amount above. Forge multiplies this by eaten grams divided by base grams, so 2 g of a 220 g base is not treated as 2 servings.",children:a.jsx(k,{inputMode:"decimal",value:n.calories??"",onChange:s=>r("calories",s.target.value)})}),a.jsx(y,{label:"Protein g",labelHelp:"Protein grams for the base amount above. This is scaled by the same gram ratio as calories.",children:a.jsx(k,{inputMode:"decimal",value:n.proteinGrams??"",onChange:s=>r("proteinGrams",s.target.value)})}),a.jsx(y,{label:"Carbs g",labelHelp:"Carbohydrate grams for the base amount above. Carbs are training fuel after protein and fat are allocated.",children:a.jsx(k,{inputMode:"decimal",value:n.carbohydrateGrams??"",onChange:s=>r("carbohydrateGrams",s.target.value)})}),a.jsx(y,{label:"Fat g",labelHelp:"Fat grams for the base amount above. Fat supports the practical floor and AMDR context in the plan.",children:a.jsx(k,{inputMode:"decimal",value:n.fatGrams??"",onChange:s=>r("fatGrams",s.target.value)})}),a.jsx(y,{label:"Fiber g",labelHelp:"Fiber grams for the base amount above. Forge compares this to the 14g per 1000 kcal planning target.",children:a.jsx(k,{inputMode:"decimal",value:n.fiberGrams??"",onChange:s=>r("fiberGrams",s.target.value)})}),a.jsx(y,{label:"Sugar g",labelHelp:"Sugar grams for the base amount above. Added sugar is tracked as a ceiling, not a goal.",children:a.jsx(k,{inputMode:"decimal",value:n.sugarGrams??"",onChange:s=>r("sugarGrams",s.target.value)})}),a.jsx(y,{label:"Sodium mg",labelHelp:"Sodium milligrams for the base amount above. Sodium affects daily ceiling, sport loss replacement, and water retention hypotheses.",children:a.jsx(k,{inputMode:"decimal",value:n.sodiumMg??"",onChange:s=>r("sodiumMg",s.target.value)})})]})]})}function Vt({food:e,onAdd:t}){return a.jsxs(z,{className:"grid gap-4 border-[var(--primary)]/20 bg-[var(--ui-accent-soft)] p-4",children:[a.jsxs("div",{className:"flex items-start justify-between gap-3",children:[a.jsxs("div",{children:[a.jsx("div",{className:"text-lg font-semibold text-[var(--ui-ink-strong)]",children:e.name}),a.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-soft)]",children:[e.brand,e.servingLabel,e.source].filter(Boolean).join(" · ")})]}),a.jsxs(K,{type:"button",onClick:t,children:[a.jsx(De,{className:"size-4"}),"Add"]})]}),a.jsxs("div",{className:"grid gap-3 md:grid-cols-4",children:[a.jsx(N,{label:"Calories",value:i(e.calories)}),a.jsx(N,{label:"Protein",value:`${i(e.proteinGrams)}g`}),a.jsx(N,{label:"Carbs",value:`${i(e.carbohydrateGrams)}g`}),a.jsx(N,{label:"Fat",value:`${i(e.fatGrams)}g`}),a.jsx(N,{label:"Fiber",value:`${i(e.fiberGrams)}g`}),a.jsx(N,{label:"Sugar",value:`${i(e.sugarGrams)}g`}),a.jsx(N,{label:"Sodium",value:`${i(e.sodiumMg)}mg`}),a.jsx(N,{label:"NOVA",value:e.novaGroup?String(e.novaGroup):"n/a"})]}),a.jsxs("div",{className:"flex items-center gap-2 text-xs text-[var(--ui-ink-soft)]",children:[a.jsx(Ra,{className:"size-4"}),"Base grams: ",i(ue(e)),". Adjust exact intake in the next step."]})]})}function ye(e){const t=Number(e.amount)||0,n=ue(e.food),r=pa(e),s=e.unit==="serving"||e.unit==="unit",d=t<=0?0:n!=null&&r!=null?r/n:s?t:null,g=l=>d!=null&&typeof l=="number"&&Number.isFinite(l)?Math.round(l*d*10)/10:null;return{grams:r,scale:d,calories:g(e.food.calories),proteinGrams:g(e.food.proteinGrams),carbohydrateGrams:g(e.food.carbohydrateGrams),fatGrams:g(e.food.fatGrams),fiberGrams:g(e.food.fiberGrams),sugarGrams:g(e.food.sugarGrams),sodiumMg:g(e.food.sodiumMg),potassiumMg:g(e.food.potassiumMg),caffeineMg:g(e.food.caffeineMg),alcoholGrams:g(e.food.alcoholGrams)}}function Yt(e){return e.reduce((t,n)=>{const r=ye(n);return{calories:t.calories+(r.calories??0),proteinGrams:t.proteinGrams+(r.proteinGrams??0),carbohydrateGrams:t.carbohydrateGrams+(r.carbohydrateGrams??0),fatGrams:t.fatGrams+(r.fatGrams??0)}},{calories:0,proteinGrams:0,carbohydrateGrams:0,fatGrams:0})}function aa(){return{weightKg:"",waistCm:"",bodyFatPercent:"",energy:"",hunger:"",cravings:"",bloating:"",facePuffiness:"",leanness:"",notes:""}}function Jt({open:e,onOpenChange:t,value:n,onChange:r,onSubmit:s,pending:d}){const g=[{id:"body",eyebrow:"Body",title:"Measurements",description:"Add weight and body measures when you have them. Empty fields are ignored.",render:(l,o)=>a.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[a.jsx(y,{label:"Weight kg",children:a.jsx(k,{inputMode:"decimal",value:l.weightKg,onChange:c=>o({weightKg:c.target.value})})}),a.jsx(y,{label:"Waist cm",children:a.jsx(k,{inputMode:"decimal",value:l.waistCm,onChange:c=>o({waistCm:c.target.value})})}),a.jsx(y,{label:"Body fat %",children:a.jsx(k,{inputMode:"decimal",value:l.bodyFatPercent,onChange:c=>o({bodyFatPercent:c.target.value})})})]})},{id:"state",eyebrow:"State",title:"Energy, appetite, and gut",description:"These subjective signals are what make the view more useful than a calorie ledger.",render:(l,o)=>a.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[a.jsx(y,{label:"Energy 0-10",children:a.jsx(k,{inputMode:"decimal",value:l.energy,onChange:c=>o({energy:c.target.value})})}),a.jsx(y,{label:"Hunger 0-10",children:a.jsx(k,{inputMode:"decimal",value:l.hunger,onChange:c=>o({hunger:c.target.value})})}),a.jsx(y,{label:"Cravings 0-10",children:a.jsx(k,{inputMode:"decimal",value:l.cravings,onChange:c=>o({cravings:c.target.value})})}),a.jsx(y,{label:"Bloating 0-10",children:a.jsx(k,{inputMode:"decimal",value:l.bloating,onChange:c=>o({bloating:c.target.value})})}),a.jsx(y,{label:"Face puffiness 0-10",children:a.jsx(k,{inputMode:"decimal",value:l.facePuffiness,onChange:c=>o({facePuffiness:c.target.value})})}),a.jsx(y,{label:"Leanness 0-10",children:a.jsx(k,{inputMode:"decimal",value:l.leanness,onChange:c=>o({leanness:c.target.value})})})]})},{id:"notes",eyebrow:"Context",title:"Notes",description:"Capture anything that explains the signal.",render:(l,o)=>a.jsx(y,{label:"Notes",children:a.jsx(ve,{value:l.notes,onChange:c=>o({notes:c.target.value}),placeholder:"Sleep, sodium, workout soreness, stressful day..."})})}];return a.jsx(je,{open:e,onOpenChange:t,eyebrow:"Check-in",title:"Add body signal",description:"Add measurements, energy, gut, and appearance signals.",value:n,onChange:r,steps:g,onSubmit:s,submitLabel:"Save check-in",pending:d,pendingLabel:"Saving check-in",draftPersistenceKey:"weight-loss-checkin"})}function Zt(e){const t=n=>{const r=Number(n);return Number.isFinite(r)?r:null};return{body:{weightKg:t(e.weightKg),waistCm:t(e.waistCm),bodyFatPercent:t(e.bodyFatPercent),notes:e.notes},subjective:{energy:t(e.energy),hunger:t(e.hunger),cravings:t(e.cravings),timeRelation:"unspecified",notes:e.notes},gut:{bloating:t(e.bloating),notes:e.notes},appearance:{facePuffiness:t(e.facePuffiness),leanness:t(e.leanness),notes:e.notes}}}function Xt(e){const t=e.items[0]??null,n=Math.max(0,e.items.length-1);return t?`${t.name}${n>0?` + ${n} more`:""}`:e.mealLabel??"Meal"}function en(e){return e.items.slice(0,3).map(t=>{const n=Number.isFinite(t.quantity)&&t.quantity>0?Number.isInteger(t.quantity)?String(t.quantity):t.quantity.toFixed(2).replace(/\.?0+$/,""):null,r=t.unit??"serving",s=t.grams!=null?`${t.grams.toFixed(0)}g`:null;return[n,r,s?`(${s})`:null].filter(Boolean).join(" ")}).filter(Boolean).join(" · ")}function an({open:e,onOpenChange:t,meals:n,onLogAgain:r,onEdit:s,onDelete:d,pending:g}){return a.jsx(je,{open:e,onOpenChange:t,eyebrow:"History",title:"Food history",description:"Review recent foods and quickly log a previous meal again.",value:{},onChange:()=>{},steps:[{id:"history",title:"Recent meal history",render:()=>a.jsx("div",{className:"grid gap-3",children:n.map(l=>a.jsxs(D,{className:"grid gap-3",children:[a.jsxs("div",{className:"flex items-start justify-between gap-3",children:[a.jsxs("div",{children:[a.jsx("div",{className:"text-sm font-semibold text-[var(--ui-ink-strong)]",children:Xt(l)}),a.jsxs("div",{className:"mt-1 text-xs text-[var(--ui-ink-faint)]",children:[l.loggedAt.slice(0,10)," ·"," ",en(l)||l.mealLabel||"No quantity recorded"]})]}),a.jsxs($,{tone:"meta",children:[l.totals.calories.toFixed(0)," kcal"]})]}),a.jsxs("div",{className:"flex flex-wrap gap-2",children:[a.jsx(K,{type:"button",size:"sm",variant:"secondary",onClick:()=>s(l),children:"Edit"}),a.jsx(K,{type:"button",size:"sm",variant:"ghost",pending:g,onClick:()=>d(l),children:"Delete"}),a.jsx(K,{type:"button",size:"sm",variant:"secondary",pending:g,onClick:()=>r(l),children:"Log again"})]})]},l.id))})}],onSubmit:async()=>t(!1),submitLabel:"Done"})}function tn(e){switch(e){case"healthkit_daily_active_energy":return"HealthKit daily active energy";case"workout_movement_fallback":return"workout + movement fallback";case"target_inference_only":return"plan target inference";default:return e||"unknown source"}}function nn(e){const t=e.energyModel,n=t.sourceAvailability,r=[n.healthKitDailyEnergy?"HealthKit active energy":null,t.restingEnergyCalories!=null?"HealthKit resting energy":null,n.workoutEnergy?"workout energy":null,n.movementTripCalories?"movement-trip calories":null].filter(Boolean);return r.length>0?r.join(", "):"no measured expenditure streams"}function rn(e){const t=e.energyModel,n=t.recentFoodLogDayCount>0?`${t.recentFoodLogCount} recent food log${t.recentFoodLogCount===1?"":"s"} across ${t.recentFoodLogDayCount} logged day${t.recentFoodLogDayCount===1?"":"s"}`:"no recent logged food days";if(t.estimatedTdeeKcal==null)return`No TDEE estimate yet. Average logged intake is ${i(t.averageCalorieIntake)} kcal/day from ${n}.`;const r=`Recent average balance: intake ${i(t.averageCalorieIntake)} - TDEE ${i(t.estimatedTdeeKcal)} = ${W(t.estimatedDailyEnergyBalanceKcal)} kcal/day.`,s=t.restingEnergyCalories!=null&&t.activeBurnKcal!=null?`TDEE = resting ${i(t.restingEnergyCalories)} + active burn ${i(t.activeBurnKcal)}.`:`TDEE is falling back to the configured plan estimate ${i(t.inferredTdee)}.`,d=t.energySourceConfidence==="healthkit_daily_active_energy"?`Active burn uses HealthKit daily active energy ${i(t.activeBurnKcal)}; workout and movement are evidence only.`:t.energySourceConfidence==="workout_movement_fallback"?`Active burn fallback = workout ${i(t.workoutEnergyKcal)} + movement ${i(t.movementCaloriesKcal)} = ${i(t.activeBurnKcal)}, so movement is not added again.`:"Active burn is not measured yet.";return`${r} ${s} ${d} Food window: ${n}. Negative means estimated deficit; this is not today's remaining calories.`}function sn(e){const t=e.energyModel,n=t.restingEnergyCalories!=null&&t.activeBurnKcal!=null,r=e.todayLedger.dateKey,s=t.recentFoodLogDayCount>0?`${t.recentFoodLogCount} recent food log${t.recentFoodLogCount===1?"":"s"} across ${t.recentFoodLogDayCount} distinct logged day${t.recentFoodLogDayCount===1?"":"s"}`:"no recent logged food days",d=t.energySourceConfidence==="healthkit_daily_active_energy"?`active burn = HealthKit daily active energy average = ${i(t.activeBurnKcal)} kcal/day`:t.energySourceConfidence==="workout_movement_fallback"?`active burn = workout average ${i(t.workoutEnergyKcal)} + movement-trip average ${i(t.movementCaloriesKcal)} = ${i(t.activeBurnKcal)} kcal/day`:"active burn is not measured; Forge falls back to plan inference",g=t.restingEnergyCalories!=null&&t.activeBurnKcal!=null?`TDEE = resting energy average ${i(t.restingEnergyCalories)} + active burn average ${i(t.activeBurnKcal)} = ${i(t.estimatedTdeeKcal)} kcal/day.`:`TDEE = ${i(t.estimatedTdeeKcal)} kcal/day from the configured plan because complete resting + active energy is not available.`,l=t.estimatedTdeeKcal!=null?`Energy gap = average logged intake - TDEE = ${i(t.averageCalorieIntake)} - ${i(t.estimatedTdeeKcal)} = ${W(t.estimatedDailyEnergyBalanceKcal)} kcal/day.`:"Energy gap cannot be computed until Forge has either measured expenditure or an inferred TDEE.",o=t.energySourceConfidence==="healthkit_daily_active_energy"?`selected active burn = HealthKit daily active energy average = ${i(t.activeBurnKcal)} kcal/day. Workout and movement are visible as evidence but are not added.`:t.energySourceConfidence==="workout_movement_fallback"?`selected active burn = workout average ${i(t.workoutEnergyKcal)} + movement-trip average ${i(t.movementCaloriesKcal)} = ${i(t.activeBurnKcal)} kcal/day. This is why movement can appear next to active burn: it is a component of active burn here, not a separate add-on.`:"selected active burn is unavailable, so TDEE falls back to the configured plan estimate.",c=t.restingEnergyCalories!=null&&t.activeBurnKcal!=null&&t.estimatedTdeeKcal!=null?t.energySourceConfidence==="healthkit_daily_active_energy"?`Arithmetic shown here: active burn ${i(t.activeBurnKcal)} = HealthKit daily active energy average; TDEE ${i(t.estimatedTdeeKcal)} = resting ${i(t.restingEnergyCalories)} + active burn ${i(t.activeBurnKcal)}; energy gap ${W(t.estimatedDailyEnergyBalanceKcal)} = intake ${i(t.averageCalorieIntake)} - TDEE ${i(t.estimatedTdeeKcal)}.`:t.energySourceConfidence==="workout_movement_fallback"?`Arithmetic shown here: active burn ${i(t.activeBurnKcal)} = workout ${i(t.workoutEnergyKcal)} + movement ${i(t.movementCaloriesKcal)}; TDEE ${i(t.estimatedTdeeKcal)} = resting ${i(t.restingEnergyCalories)} + active burn ${i(t.activeBurnKcal)}; energy gap ${W(t.estimatedDailyEnergyBalanceKcal)} = intake ${i(t.averageCalorieIntake)} - TDEE ${i(t.estimatedTdeeKcal)}.`:`Arithmetic shown here: TDEE ${i(t.estimatedTdeeKcal)} = resting ${i(t.restingEnergyCalories)} + active burn ${i(t.activeBurnKcal)}; energy gap ${W(t.estimatedDailyEnergyBalanceKcal)} = intake ${i(t.averageCalorieIntake)} - TDEE ${i(t.estimatedTdeeKcal)}.`:"Arithmetic shown here uses the available expenditure branch; some terms are unavailable because Forge does not yet have both resting and active energy evidence.",w=t.recentFoodLogDayCount>0?`Average intake = total calories in the latest ${t.recentFoodLogCount} non-discarded food log${t.recentFoodLogCount===1?"":"s"} / ${t.recentFoodLogDayCount} logged day${t.recentFoodLogDayCount===1?"":"s"}. It does not divide by silent calendar days.`:"Average logged intake is 0 because there are no recent food logs in the current window.",b=t.energySourceConfidence==="healthkit_daily_active_energy"?"Active burn is using HealthKit daily active energy first. Workout and movement values remain visible as evidence, but movement is not added again on top of HealthKit active energy.":t.energySourceConfidence==="workout_movement_fallback"?"HealthKit daily active energy is missing, so active burn falls back to workout energy plus movement-trip calories.":"No measured active-burn stream is available, so this is driven by the plan target and should be treated as low-confidence.",x=`Today is separate: today's target = baseline plan target + (today active calories - default active calories). Today active calories currently use ${va(t.todayActiveCaloriesSource)}: ${i(t.todayActiveCaloriesKcal)} kcal. Default active calories: ${i(t.baselineActiveCaloriesKcal)} kcal. Today's adjustment: ${W(t.todayTargetAdjustmentKcal)} kcal.`,m=t.energySourceConfidence==="healthkit_daily_active_energy"?"Data path: recent food logs provide intake; HealthKit daily active-energy rows provide active burn; resting-energy rows provide basal/resting expenditure.":t.energySourceConfidence==="workout_movement_fallback"?"Data path: recent food logs provide intake; HealthKit resting-energy rows provide resting expenditure; workout-session energy plus movement-trip calories provide fallback active burn.":"Data path: recent food logs provide intake; expenditure is using the configured plan inference because measured expenditure streams are incomplete.";return a.jsxs("span",{className:"grid gap-2",children:[a.jsxs("span",{children:[a.jsx("span",{className:"font-semibold text-[var(--ui-ink-strong)]",children:"What this card means:"})," ","this is a historical energy-balance estimate, not the remaining food budget for today. Negative means estimated deficit; positive means estimated surplus."]}),a.jsxs("span",{children:[a.jsx("span",{className:"font-semibold text-[var(--ui-ink-strong)]",children:"Formula:"})," ",l]}),a.jsxs("span",{children:[a.jsx("span",{className:"font-semibold text-[var(--ui-ink-strong)]",children:"TDEE:"})," ","TDEE means total daily energy expenditure: the estimated calories burned per day. Forge uses"," ",n?"measured resting energy plus the selected active-burn branch":"the configured/inferred plan estimate because measured resting plus active expenditure is incomplete",". Objective deficit or surplus is not subtracted here; that belongs to the intake target."]}),a.jsxs("span",{children:[a.jsx("span",{className:"font-semibold text-[var(--ui-ink-strong)]",children:"Selected branch:"})," ",t.energySourceConfidence==="healthkit_daily_active_energy"?"HealthKit daily active energy exists, so active burn uses that value. Workout, movement, and step values are shown only as evidence.":t.energySourceConfidence==="workout_movement_fallback"?"HealthKit daily active energy is missing, so active burn uses workout calories plus movement-trip calories.":"Measured expenditure is incomplete, so TDEE falls back to the configured plan estimate."]}),a.jsxs("span",{children:[a.jsx("span",{className:"font-semibold text-[var(--ui-ink-strong)]",children:"Active-burn branch:"})," ",o]}),a.jsxs("span",{children:[a.jsx("span",{className:"font-semibold text-[var(--ui-ink-strong)]",children:"Arithmetic:"})," ",c]}),a.jsxs("span",{children:[a.jsx("span",{className:"font-semibold text-[var(--ui-ink-strong)]",children:"Why these numbers:"})," ","The displayed movement value is therefore"," ",t.energySourceConfidence==="workout_movement_fallback"?"part of the active-burn calculation":"supporting evidence only",", and it is not the same thing as today's editable active-calorie budget."]}),a.jsxs("span",{children:[a.jsx("span",{className:"font-semibold text-[var(--ui-ink-strong)]",children:"Current data:"})," ","intake ",i(t.averageCalorieIntake)," kcal/day; TDEE"," ",i(t.estimatedTdeeKcal)," kcal/day; resting"," ",i(t.restingEnergyCalories)," kcal/day; active burn"," ",i(t.activeBurnKcal)," kcal/day; workout"," ",i(t.workoutEnergyKcal)," kcal/day; movement"," ",i(t.movementCaloriesKcal)," kcal/day."," ",t.energySourceConfidence==="workout_movement_fallback"?"On this branch, active burn already equals workout plus movement, so movement is not an extra add-on after active burn.":"On this branch, movement is shown as evidence and is not added on top of active burn."]}),a.jsxs("span",{children:[a.jsx("span",{className:"font-semibold text-[var(--ui-ink-strong)]",children:"Data lineage:"})," ",m]}),a.jsxs("span",{children:[a.jsx("span",{className:"font-semibold text-[var(--ui-ink-strong)]",children:"Food window:"})," ",w," Current denominator: ",s,"."]}),a.jsxs("span",{children:[a.jsx("span",{className:"font-semibold text-[var(--ui-ink-strong)]",children:"Expenditure:"})," ",g," ",d,". TDEE means total daily energy expenditure, the estimated calories burned per day before applying the weight-loss or weight-gain objective."]}),a.jsxs("span",{children:[a.jsx("span",{className:"font-semibold text-[var(--ui-ink-strong)]",children:"TDEE source:"})," ",n?"measured expenditure branch: resting energy average plus selected active-burn branch":"plan-inference branch because Forge does not yet have both resting and active expenditure streams",". TDEE is an expenditure estimate; the goal deficit or surplus is applied when planning intake targets, not when calculating historical TDEE."]}),a.jsxs("span",{children:[a.jsx("span",{className:"font-semibold text-[var(--ui-ink-strong)]",children:"Calculation path:"})," ","Forge first tries HealthKit daily active energy for active burn. If that is missing, it uses workout energy plus movement-trip calories. TDEE is resting energy plus whichever active-burn branch was selected. The objective deficit or surplus is not part of this historical TDEE."]}),a.jsxs("span",{children:[a.jsx("span",{className:"font-semibold text-[var(--ui-ink-strong)]",children:"Source:"})," ",tn(t.energySourceConfidence)," across"," ",t.evidenceDays," expenditure evidence day",t.evidenceDays===1?"":"s"," ending the selected day (",r,"). Available streams: ",nn(e),"."," ",b]}),a.jsxs("span",{children:[a.jsx("span",{className:"font-semibold text-[var(--ui-ink-strong)]",children:"Movement:"})," ","movement kcal is a component of fallback active burn. If HealthKit daily active energy exists, Forge shows movement as supporting evidence but does not add it again. If HealthKit active energy is missing, fallback active burn is workout average + movement average; the displayed active burn number already includes that movement component."]}),a.jsxs("span",{children:[a.jsx("span",{className:"font-semibold text-[var(--ui-ink-strong)]",children:"Today:"})," ",x]})]})}function on(e){const t=W(e);return t==="n/a"?t:`${t} kcal/d`}function va(e){switch(e){case"today_workout_energy":return"today's workout energy";case"today_healthkit_active_energy":return"today's HealthKit active energy";case"today_workout_movement_energy":return"today's workout and movement energy";case"today_workout_movement_step_energy":return"today's workout, movement, and step energy";case"today_workout_step_energy":return"today's workout and step energy";case"today_movement_step_energy":return"today's movement and step energy";case"today_movement_trip_calories":return"today's movement trip calories";case"today_step_estimate":return"today's estimated step calories";case"user_override":return"your manual active-calorie override";default:return"the default daily active calories"}}function ln(e){const[t,n,r]=e.split("-").map(Number),s=new Date(t,n-1,r),d=new Date(t,n-1,r+1);return{dayStartAt:s.toISOString(),dayEndAt:d.toISOString()}}function cn(){const e=new Date,t=new Date(e);return t.setHours(24,0,2,0),Math.max(1e3,t.getTime()-e.getTime())}function jn(){const e=Ua(),t=qa(),n=e.selectedUserIds,[r,s]=F.useState(()=>$e()),d=F.useMemo(()=>ln(r),[r]),g=F.useMemo(()=>["forge-weight-loss-view",r,...n],[r,n]),[l,o]=F.useState(!1),[c,w]=F.useState(!1),[b,x]=F.useState(!1),[m,S]=F.useState(!1),[E,M]=F.useState(!1),[_,T]=F.useState(null),[L,B]=F.useState(null),[P,H]=F.useState(""),[te,J]=F.useState(null),[O,U]=F.useState(null),[ne,re]=F.useState("search"),[oe,Z]=F.useState(void 0),[Q,V]=F.useState(()=>fe()),[ge,f]=F.useState(()=>aa()),v=za({queryKey:g,queryFn:async()=>(await st(n,{dateKey:r,...d})).weightLoss}),j=v.data;F.useEffect(()=>{const u=()=>{s(Oe=>{const Ue=$e();return Ue===Oe?Oe:Ue})},h=window.setTimeout(u,cn());return window.addEventListener("focus",u),document.addEventListener("visibilitychange",u),()=>{window.clearTimeout(h),window.removeEventListener("focus",u),document.removeEventListener("visibilitychange",u)}},[r]),F.useEffect(()=>{!j||c||l||Kt(j)||(w(!0),J(Ee(j)),T(`Forge needs the missing profile fields before the calorie and macro plan can be trusted.
|
|
3
|
-
|
|
4
|
-
- Confirm age, height, current weight, objective, weekly rate, and active calories.
|
|
5
|
-
- Known HealthKit and movement values are prefilled when available.`),o(!0))},[c,j,l]),F.useEffect(()=>{j&&(H(String(Math.round(j.energyModel.todayActiveCaloriesKcal??0))),B(null))},[j==null?void 0:j.generatedAt,j==null?void 0:j.energyModel.todayActiveCaloriesKcal]);const X=()=>t.invalidateQueries({queryKey:g}),ke=q({mutationFn:async u=>(await Qa({query:u,userIds:n})).foods}),me=q({mutationFn:async u=>Va({text:u,userIds:n,commitCandidate:!1}),onSuccess:({candidate:u})=>{V(Bt(u,"chatgpt"))}}),Le=q({mutationFn:async u=>Ye(fa(u),n),onSuccess:()=>{V(fe()),x(!1),X()}}),Pe=q({mutationFn:async({foodLogId:u,draft:h})=>Ya(u,Ot(h),n),onSuccess:()=>{V(fe()),U(null),x(!1),X()}}),Ne=q({mutationFn:async u=>Ja(u.id,n),onSuccess:()=>{X()}}),we=q({mutationFn:async u=>Za({dayKey:j==null?void 0:j.todayLedger.dateKey,activeCaloriesKcal:u,notes:u==null?"":"Manual active-calorie override from the weight-loss view"},n),onSuccess:()=>{B(null),X()},onError:u=>{B(u instanceof Error?u.message:"Could not save active calories")}}),he=q({mutationFn:async u=>{const h=Number(u.currentWeightKg);await Xa(_t(u),n),Number.isFinite(h)&&await Je({weightKg:h,notes:"Updated from weight-plan setup."},n)},onSuccess:()=>{o(!1),X()}}),Re=q({mutationFn:async u=>{const h=Zt(u);await Promise.all([h.body.weightKg!==null||h.body.waistCm!==null||h.body.bodyFatPercent!==null?Je(h.body,n):Promise.resolve(),h.subjective.energy!==null||h.subjective.hunger!==null||h.subjective.cravings!==null?et(h.subjective,n):Promise.resolve(),h.gut.bloating!==null?at(h.gut,n):Promise.resolve(),h.appearance.facePuffiness!==null||h.appearance.leanness!==null?tt(h.appearance,n):Promise.resolve()])},onSuccess:()=>{f(aa()),S(!1),X()}}),pe=q({mutationFn:async u=>Ye({mealLabel:u.mealLabel??"Saved meal",source:"saved_meal",confirmationState:"confirmed",notes:u.notes??"",items:u.items.map(h=>({foodId:h.foodId,name:h.name,brand:h.brand,quantity:h.quantity,unit:h.unit,grams:h.grams,calories:h.calories,proteinGrams:h.proteinGrams,carbohydrateGrams:h.carbohydrateGrams,fatGrams:h.fatGrams,fiberGrams:h.fiberGrams,sugarGrams:h.sugarGrams,sodiumMg:h.sodiumMg,potassiumMg:h.potassiumMg,caffeineMg:h.caffeineMg,alcoholGrams:h.alcoholGrams,glycemicIndex:h.glycemicIndex,novaGroup:h.novaGroup,fermented:h.fermented,probiotic:h.probiotic,fodmapLevel:h.fodmapLevel,tags:h.tags,confidence:h.confidence??.85}))},n),onSuccess:()=>{X()}});if(v.isLoading)return a.jsx(nt,{title:"Loading weight-loss signals",description:"Combining food logs, HealthKit, movement, workouts, body check-ins, subjective state, and gut signals."});if(v.isError||!v.data)return a.jsx(rt,{error:v.error??new Error("Weight-loss view unavailable"),onRetry:()=>void v.refetch()});const C=v.data,I=C.todayLedger,We=I.totals,Ce=We.calories,Fe=I.targetCalories-Ce,ya=I.plannedTargetCalories??I.targetCalories,Be=C.energyModel.todayActiveCaloriesKcal??C.energyModel.activeBurnKcal??C.energyModel.activeEnergyCalories??C.energyModel.movementCaloriesKcal??0,ja=C.energyModel.baselineActiveCaloriesKcal??Be,Me=I.activeAdjustmentCalories??0,ka=Me===0?"no active-calorie adjustment":`${Me>0?"+":""}${Me.toFixed(0)} kcal from ${va(I.activeCaloriesSource)}`,Na=I.targetCalories>0?Math.min(140,Math.max(0,Ce/I.targetCalories*100)):0,wa=C.energyModel,He=C.weightTrend,xe=C.foodQuality,Ge=C.trainingFuel,Ca=C.subjective,Fa=C.gut,Ma=ot(C.hypotheses),Se=te??Ee(C),Ga=()=>{T(null),J(Ee(C)),o(!0)},Ke=(u="search")=>{U(null),re(u),Z(u==="custom"?"amounts":"search"),V(u==="custom"?Ht():fe()),x(!0)},qe=u=>{U(u.id),re("search"),Z("amounts"),V(Wt(u)),x(!0),M(!1)},ze=u=>{typeof window<"u"&&!window.confirm(`Delete ${u.mealLabel??"this meal"} from the food log?`)||Ne.mutate(u)},Sa=()=>{const u=Number(P);if(!Number.isFinite(u)||u<0){B("Enter a valid active-calorie value.");return}we.mutate(Math.round(u))},Ka=()=>{we.mutate(null)};return a.jsxs("div",{className:"mx-auto grid w-full max-w-[1500px] gap-5",children:[a.jsx(Oa,{title:"Weight Loss",description:"A guided Forge body composition lab: editable goals, science-based calorie and macro planning, exact food quantities, body measures, energy, gut comfort, look, and testable food hypotheses.",badge:`${I.targetCalories.toFixed(0)} kcal budget · ${C.summary.loggedMealCount} food logs`}),a.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.15fr)_minmax(340px,0.85fr)]",children:[a.jsx(mt,{ledger:I,remainingCalories:Fe,intakePercent:Na,logSavedPending:pe.isPending||Ne.isPending,onLogAgain:u=>pe.mutate(u),onEditMeal:qe,onDeleteMeal:ze}),a.jsxs("div",{className:"grid min-w-0 gap-4",children:[a.jsx(it,{view:C,onOpenPlan:Ga,onOpenFoodSearch:()=>Ke("search"),onOpenCustomFood:()=>Ke("custom"),onOpenChatGptFood:()=>Ke("chatgpt"),onOpenCheckin:()=>S(!0),onOpenHistory:()=>M(!0)}),a.jsx(dt,{view:C,draftValue:P,pending:we.isPending,error:L,onDraftChange:H,onSave:Sa,onReset:Ka})]})]}),a.jsxs("section",{className:"grid gap-4 xl:grid-cols-4",children:[a.jsx(Y,{label:"Today",value:`${Ce.toFixed(0)} kcal`,detail:`${Fe.toFixed(0)} kcal remaining against today's ${I.targetCalories.toFixed(0)} kcal target; ${ka}.`,icon:Qe,tone:Fe>=0?"green":"rose",help:`Today's target = baseline plan target + (today active calories - default active calories). Here: ${ya.toFixed(0)} + (${Be.toFixed(0)} - ${ja.toFixed(0)}) = ${I.targetCalories.toFixed(0)} kcal. If no workout or same-day active evidence exists, Forge uses the default daily active calories so the target stays at baseline.`}),a.jsx(Y,{label:"Protein",value:`${We.proteinGrams.toFixed(0)}g`,detail:`${C.target.proteinGramsTarget.toFixed(0)}g target. Protein anchors the plan while cutting or gaining.`,icon:Wa,help:"Protein grams are compared with the plan target, which uses g/kg body-weight logic and caps impossible values inside the calorie target."}),a.jsx(Y,{label:"Energy gap",value:on(wa.estimatedDailyEnergyBalanceKcal),detail:rn(C),icon:Ba,tone:"amber",help:sn(C),helpMaxWidthPx:560}),a.jsx(Y,{label:"Weight trend",value:W(He.sevenDayRateKg,2),detail:`Latest ${i(He.latestWeightKg,1)} kg. Trend uses check-ins, not noisy single weigh-ins.`,icon:_e,tone:"green",help:"Weight trend uses recent body check-ins to estimate direction. Single weigh-ins can jump from water, sodium, gut content, and training inflammation."})]}),a.jsx(xt,{view:C}),a.jsx(Ft,{view:C}),a.jsxs("section",{className:"grid gap-4 xl:grid-cols-4",children:[a.jsx(Y,{label:"Food quality",value:be(xe.qualityScore),detail:`Fiber density ${i(xe.fiberPer1000Kcal,1)}g/1000 kcal, protein density ${i(xe.proteinPer1000Kcal,1)}g/1000 kcal, ultra-processed share ${i(xe.ultraProcessedShare,0)}%.`,icon:Qe,tone:"green",help:"Food quality combines density and exposure signals such as fiber per 1000 kcal, protein per 1000 kcal, ultra-processed share, sodium, sugar, and available micronutrient evidence."}),a.jsx(Y,{label:"Training fuel",value:be(Ge.fuelingScore),detail:`Recent workout load ${i(Ge.recentTrainingLoad)} with ${i(Ge.carbsPerTrainingLoad,1)}g carbs per load unit.`,icon:ia,tone:"amber",help:"Training fuel relates carbohydrate and protein timing to recent workout load. It is meant to find performance and recovery patterns, not force a fixed carb rule."}),a.jsx(Y,{label:"Subjective",value:be(Ca.averageFocus),detail:"Focus, energy, hunger, cravings, and performance are tracked as food-effect evidence.",icon:_e,help:"Subjective signals are self-rated energy, focus, hunger, cravings, and performance. Forge uses them to discover food and timing effects."}),a.jsx(Y,{label:"Gut",value:be(Fa.averageBloating),detail:"Bloating, reflux, stool type, and suspected triggers connect food choices to comfort and look.",icon:Ha,tone:"rose",help:"Gut signals include bloating, reflux, stool type, and suspected triggers. They help connect foods to comfort, water retention, and appearance hypotheses."})]}),a.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1fr)_minmax(360px,0.8fr)]",children:[a.jsx(ht,{hypotheses:Ma}),a.jsx(pt,{experiments:C.experiments})]}),a.jsx($t,{open:l,onOpenChange:o,view:C,value:Se,onChange:u=>{J(u),T(null)},pending:he.isPending,error:_??(he.error instanceof Error?he.error.message:null),onSubmit:async()=>{const u=Et(Se);if(u){T(u);return}await he.mutateAsync(Se)}}),a.jsx(qt,{open:b,onOpenChange:x,value:Q,onChange:V,foodResults:ke.data??[],searchPending:ke.isPending,chatGptPending:me.isPending,chatGptError:me.error instanceof Error?me.error.message:null,logPending:Le.isPending||Pe.isPending,intent:ne,initialStepId:oe,onSearch:u=>ke.mutate(u),onParseWithChatGpt:u=>me.mutateAsync(u).then(()=>{}),mode:O?"edit":"create",onSubmit:async()=>{if(O){await Pe.mutateAsync({foodLogId:O,draft:Q});return}await Le.mutateAsync(Q)}}),a.jsx(Jt,{open:m,onOpenChange:S,value:ge,onChange:f,pending:Re.isPending,onSubmit:async()=>{await Re.mutateAsync(ge)}}),a.jsx(an,{open:E,onOpenChange:M,meals:C.recentMeals,pending:pe.isPending||Ne.isPending,onLogAgain:u=>pe.mutate(u),onEdit:qe,onDelete:ze})]})}export{jn as WeightLossPage};
|