Skip to content

Add Health action support#192

Open
CorrectRoadH wants to merge 8 commits into
electrikmilk:mainfrom
CorrectRoadH:health-quantity-decompile
Open

Add Health action support#192
CorrectRoadH wants to merge 8 commits into
electrikmilk:mainfrom
CorrectRoadH:health-quantity-decompile

Conversation

@CorrectRoadH

@CorrectRoadH CorrectRoadH commented May 16, 2026

Copy link
Copy Markdown
Contributor

This adds a standard Health action include with support for the Health actions exposed through Shortcuts.

It covers logging quantity samples, category samples, blood pressure, and workouts, plus finding samples, reading sample details, Health app navigation, Health search, sleep schedule, tabs, records, and physical activity. The general sample logging helpers are named logHealthQuantitySample and logHealthCategorySample to make it clear they create Health samples.

For example, importing a Shortcut that logs blood pressure now produces standard syntax like this:

#include 'actions/health'

logBloodPressure(qty(high, "mmHg"), qty(low, "mmHg"))

A demo Shortcut with several Health actions decompiles into standard calls as well:

const output = logHealthQuantitySample(qty(20, "count"), "Steps", CurrentDate)
findHealthSamples(output)
openHealthView("HKDisplayCategoryIdentifier_13", "呼吸", "lungs.fill")
openHealthData("HKDisplayTypeIdentifierForcedVitalCapacity", "最大肺活量", "lungs.fill")
logHealthCategorySample("Acne", "Present", nil, CurrentDate, CurrentDate)
logWorkout("Basketball", qty(500, "Cal"))

This also keeps support for WFQuantityFieldValue in rawAction(...) so custom Health workflows can round-trip through import without losing the quantity value structure.

Health sample types and units were filled out using the local HealthKit SDK headers, and the action identifiers were cross-checked against local Shortcuts and App Intents metadata. While testing imports, I also fixed a decompilation issue where non-Latin output names could sanitize to an empty identifier and produce invalid code like const = ...; those now fall back to output.

@CorrectRoadH CorrectRoadH force-pushed the health-quantity-decompile branch from 5cb6ae7 to fb04a0b Compare May 16, 2026 01:57
@CorrectRoadH CorrectRoadH changed the title Fix Health quantity raw action import Add Health quantity action support May 16, 2026
@CorrectRoadH CorrectRoadH force-pushed the health-quantity-decompile branch from fb04a0b to cc442fe Compare May 16, 2026 02:11
@CorrectRoadH CorrectRoadH changed the title Add Health quantity action support Add Health action support May 16, 2026
@CorrectRoadH CorrectRoadH force-pushed the health-quantity-decompile branch from cc442fe to 5e98d78 Compare May 16, 2026 02:18
@CorrectRoadH CorrectRoadH marked this pull request as ready for review May 19, 2026 10:49
@electrikmilk electrikmilk added the missing action(s) Actions missing complete implementation in the compiler. label May 20, 2026
Comment thread ReadMe.md Outdated
Comment thread actions_std.go Outdated
Comment thread cherri_test.go Outdated
Comment thread actions_std.go
@CorrectRoadH

Copy link
Copy Markdown
Contributor Author

@electrikmilk PTAL

@electrikmilk

Copy link
Copy Markdown
Owner

There are some other changes here; please state the rationale for these changes

The fileRequest() body parameter change is unrelated to Health support;
it has been moved to its own PR to keep this PR scoped to Health.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Xvr9ByAkYxnM3SJjBw9T9
@CorrectRoadH

Copy link
Copy Markdown
Contributor Author

Thanks for the review — I've scoped this PR down to Health only and split the unrelated work out:

Everything still outside actions/health.cherri is here because decompiling a real Health Shortcut and recompiling it has to round-trip through these paths. Rationale per change:

raw_actions.go + decompile.go quantity helpers — Health quantity actions store values as WFQuantityFieldValue. Without round-trip support, importing a Health Shortcut loses the magnitude/unit structure and rawAction(...) can't reproduce it. These keep qty(...) intact on import.

decompile.go mapUUID empty-name fallback — Health output/display names are frequently non-Latin (e.g. 呼吸, 最大肺活量). sanitizeIdentifier reduced these to an empty string, producing invalid const = .... They now fall back to output.

decompile.go globals loop — Decompiled Health code uses globals like CurrentDate. Previously only ShortcutInput was recognized; now any global type decompiles to its name.

decompile.go decompActionArguments — Health actions take optional middle arguments (e.g. logHealthCategorySample("Acne", "Present", nil, ...)). The old logic dropped absent args entirely, which shifted later positional args. It now emits nil for an absent-but-followed argument and trims trailing ones.

decompile.go ensureStandardActionInclude — A decompiled Health Shortcut needs #include 'actions/health' to recompile. This emits the matching standard include automatically. TestHealthDecompileRoundTrip compiles the decompiled output to prove it works.

actions_std.go textParts guard — Minor: lets splitText tolerate a call with no separator argument, defaulting to newline. This surfaced during round-trip testing; happy to pull it into a separate PR if you'd prefer it out of here.

On tests: these are Cherri-first — tests/health.cherri compiles, and TestHealthDecompileRoundTrip decompiles a Health Shortcut and recompiles the generated Cherri.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

missing action(s) Actions missing complete implementation in the compiler.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants