CareMax Authentication
CRITICAL RULES
- 1. This is a silent prerequisite for ALL caremax-* skills. Do NOT ask "do you want to authenticate?" — just execute.
- NEVER write your own curl commands. Only use the scripts below.
- NEVER split auth into multiple steps manually. Use
./scripts/auth-flow.sh (from this skill root) — it opens browser AND auto-polls until done. - BASE URL DETECTION: If the user specifies a custom URL (local dev 默认
http://localhost:8788,须与后端 wrangler [dev] 端口一致), you MUST:
- Pass it as the first argument:
bash ./scripts/auth-flow.sh http://localhost:8788 (run from
this skill root — see path convention below)
- After auth completes,
credentials.json will have
base_url set to that URL
- All subsequent
api-call.sh,
list-system-presets.sh,
quick-log.sh,
upload.sh,
ocr-stream.sh will auto-use it
- Look for URL patterns like
http://localhost:XXXX,
caremax(http://...), or explicit "use local" / "use localhost"
Scripts
Path convention (no ~/.claude — product-agnostic)
- - This skill (
caremax-auth): run commands with current working directory = this folder (the directory that contains SKILL.md and scripts/). Invoke scripts as ./scripts/<name>.sh. - Other
caremax-* skills sit as sibling directories next to caremax-auth (e.g. skills/caremax-indicators/ and skills/caremax-auth/ in the repo, or ~/.agents/skills/<name>/ after install). From those folders, call auth as ../caremax-auth/scripts/<name>.sh.
Credentials file location is unchanged: ~/.caremax/credentials.json (not under any product’s config dir).
api-call.sh — Make authenticated API calls (PRIMARY TOOL)
This is what you should use for all API calls. It auto-checks token, auto-refreshes if expired.
CODEBLOCK0
If it returns {"error":"no_credentials",...} → run ./scripts/auth-flow.sh (see below), then retry.
list-system-presets.sh — 当前账号可快捷记录的指标列表
与 App 「快捷记一笔」 芯片一致:先看有哪些 preset_key / 显示名 / 默认单位,再调用 quick-log.sh。
CODEBLOCK1
quick-log.sh — 快捷记一笔(单条数值)
CODEBLOCK2
可选参数:--unit、--date(YYYY-MM-DD)、--member(家庭成员 UUID)。底层走 api-call.sh,自动带用户 OAuth token。
upload.sh — Upload files (images/PDFs) to CareMax
CODEBLOCK3
Returns: INLINECODE34
Use the returned id values as fileIds for ocr-stream.sh.
IMPORTANT: Do NOT use api-call.sh for file uploads — it only supports JSON body. Always use upload.sh for multipart file uploads.
download-file.sh — Download a source file from a session
CODEBLOCK4
Get file_id from session detail (source_files[].id in reports, or files[].id in session).
ocr-stream.sh — OCR with real-time SSE progress (for caremax-ocr skill)
CODEBLOCK5
Outputs one JSON per line as OCR progresses. Last line (step=done) has the full results.
Read each line and display progress to the user. See caremax-ocr skill for details.
Handles errors gracefully:
- - 409 (session already processing) → outputs INLINECODE43
- 403 (quota exceeded) → outputs INLINECODE44
- Pipeline auto-resumes from saved checkpoint on retry (no work is lost)
auth-flow.sh — One-shot full authorization (opens browser + auto-polls)
CODEBLOCK6
This script does EVERYTHING in one shot:
- 1. Requests device code from the API
- Opens the user's browser to the authorize page
- Automatically polls every 5 seconds until the user approves (up to 15 min)
- Saves token to INLINECODE45
Output when done: INLINECODE46
Run this in the background so you can tell the user what's happening while it polls:
bash ./scripts/auth-flow.sh &
Then tell the user: "I've opened the authorization page in your browser. Please log in and click Allow. I'll detect it automatically."
Wait for the background job to finish — it will output the result.
check-token.sh — Check token status (used internally by api-call.sh)
CODEBLOCK8
Output: INLINECODE47
refresh-token.sh — Refresh expired token (used internally by api-call.sh)
CODEBLOCK9
Standard Workflow
Quick vitals (快捷记一笔)
CODEBLOCK10
Query data
CODEBLOCK11
Upload + OCR (save medical reports from images)
This is a session-based multi-step workflow. One upload session groups all files + reports together.
Step 1: Upload → creates a session
bash ./scripts/upload.sh /path/to/image1.jpg /path/to/image2.jpg
Returns:
{ "session_id": "uuid", "member_id": "uuid", "files": [{ "id": "...", "original_name": "..." }] }
Save
session_id — it's used for all subsequent steps.
Step 2: OCR (with real-time progress)
CODEBLOCK14
Each output line is a JSON progress event. Relay to the user:
- -
step=normalize → "正在预处理文件..." - INLINECODE50 → "正在 OCR 识别第 X/Y 页..."
- INLINECODE51 → "AI 正在分析报告结构..."
- INLINECODE52 → "正在标准化指标名称..."
- INLINECODE53 → OCR complete,
data contains reports array
Step 3: Present results for user review (MANDATORY)
Do NOT call confirm automatically. Parse the step=done data and show:
CODEBLOCK15
Wait for user to say 确认/保存/OK.
Step 4: Confirm and save
CODEBLOCK16
Returns: INLINECODE56
After success: "已保存 N 份报告。"
Query sessions
CODEBLOCK17
Delete session (undo entire upload)
bash ./scripts/api-call.sh DELETE /api/skill/sessions/<session_id>
Deletes the session + all files + all reports atomically.
CareMax 认证
关键规则
- 1. 这是所有 caremax-* 技能的静默前置条件。不要问您是否要进行身份验证?——直接执行。
- 永远不要自己编写 curl 命令。仅使用以下脚本。
- 永远不要手动将认证拆分为多个步骤。使用 ./scripts/auth-flow.sh(从此技能根目录)——它会打开浏览器并自动轮询直到完成。
- 基础 URL 检测:如果用户指定了自定义 URL(本地开发默认 http://localhost:8788,须与后端 wrangler [dev] 端口一致),你必须:
- 将其作为第一个参数传递:bash ./scripts/auth-flow.sh http://localhost:8788(从
此技能根目录运行——见下方路径约定)
- 认证完成后,credentials.json 中的 base_url 将设置为该 URL
- 所有后续的 api-call.sh、list-system-presets.sh、quick-log.sh、upload.sh、ocr-stream.sh 将自动使用它
- 查找类似 http://localhost:XXXX、caremax(http://...) 或明确的使用本地/使用 localhost等 URL 模式
脚本
路径约定(无 ~/.claude——与产品无关)
- - 此技能(caremax-auth): 使用当前工作目录 = 此文件夹(包含 SKILL.md 和 scripts/ 的目录)运行命令。脚本调用方式为 ./scripts/<名称>.sh。
- 其他 caremax-* 技能作为同级目录位于 caremax-auth 旁边(例如仓库中的 skills/caremax-indicators/ 和 skills/caremax-auth/,或安装后的 ~/.agents/skills/<名称>/)。从这些文件夹中,调用认证脚本的方式为 ../caremax-auth/scripts/<名称>.sh。
凭证文件位置不变:~/.caremax/credentials.json(不在任何产品的配置目录下)。
api-call.sh — 进行经过认证的 API 调用(主要工具)
这是你应该用于所有 API 调用的工具。它会自动检查令牌,如果过期则自动刷新。
bash
bash ./scripts/api-call.sh GET /api/skill/indicators
bash ./scripts/api-call.sh POST /api/skill/records/search {query:血常规}
bash ./scripts/api-call.sh GET /api/skill/indicators/trend?id=xxx
如果返回 {error:no_credentials,...} → 运行 ./scripts/auth-flow.sh(见下方),然后重试。
list-system-presets.sh — 当前账号可快捷记录的指标列表
与 App 「快捷记一笔」 芯片一致:先看有哪些 preset_key / 显示名 / 默认单位,再调用 quick-log.sh。
bash
bash ./scripts/list-system-presets.sh
quick-log.sh — 快捷记一笔(单条数值)
bash
bash ./scripts/quick-log.sh
bash ./scripts/quick-log.sh weight 72.5 --unit kg --date 2026-03-29
bash ./scripts/quick-log.sh height 175 --member memberuuid>
可选参数:--unit、--date(YYYY-MM-DD)、--member(家庭成员 UUID)。底层走 api-call.sh,自动带用户 OAuth token。
upload.sh — 上传文件(图片/PDF)到 CareMax
bash
bash ./scripts/upload.sh /path/to/report.jpg
bash ./scripts/upload.sh /path/to/img1.jpg /path/to/img2.png
返回:{files:[{id:...,memberid:...,originalname:...}]}
使用返回的 id 值作为 ocr-stream.sh 的 fileIds。
重要:不要使用 api-call.sh 进行文件上传——它只支持 JSON 主体。始终使用 upload.sh 进行多部分文件上传。
download-file.sh — 从会话下载源文件
bash
bash ./scripts/download-file.sh id> [outputpath]
示例:
bash ./scripts/download-file.sh abc-123 ~/Downloads/report.jpg
从会话详情中获取 fileid(报告中的 sourcefiles[].id,或会话中的 files[].id)。
ocr-stream.sh — 带实时 SSE 进度的 OCR(用于 caremax-ocr 技能)
bash
bash ./scripts/ocr-stream.sh
随着 OCR 的进行,每行输出一个 JSON。最后一行(step=done)包含完整结果。
读取每一行并向用户显示进度。详情请参阅 caremax-ocr 技能。
优雅地处理错误:
- - 409(会话已在处理中)→ 输出 {step:error,code:processinginprogress,...}
- 403(配额超限)→ 输出 {step:error,code:ocrlimitexceeded,...}
- 管道在重试时从保存的检查点自动恢复(不会丢失任何工作)
auth-flow.sh — 一次性完整授权(打开浏览器 + 自动轮询)
bash
默认(生产环境)
bash ./scripts/auth-flow.sh
自定义基础 URL(localhost / 预发布环境)
bash ./scripts/auth-flow.sh http://localhost:8788
此脚本一次性完成所有操作:
- 1. 向 API 请求设备码
- 在用户浏览器中打开授权页面
- 每 5 秒自动轮询,直到用户批准(最多 15 分钟)
- 将令牌保存到 ~/.caremax/credentials.json
完成时输出:{status:authorized,accesstoken:sk-caremax-...,baseurl:...}
在后台运行此脚本,以便在轮询时告知用户正在发生的事情:
bash
bash ./scripts/auth-flow.sh &
然后告诉用户:我已打开浏览器中的授权页面。请登录并点击允许。我将自动检测。
等待后台任务完成——它将输出结果。
check-token.sh — 检查令牌状态(由 api-call.sh 内部使用)
bash
bash ./scripts/check-token.sh
输出:{status:valid|expired|missing, ...}
refresh-token.sh — 刷新过期的令牌(由 api-call.sh 内部使用)
bash
bash ./scripts/refresh-token.sh
标准工作流程
快捷记一笔
用户想要记录身高/体重等
→ ./scripts/list-system-presets.sh → 从 JSON 中选择 preset_key
→ ./scripts/quick-log.sh [--unit ...] [--date ...] [--member ...]
查询数据
用户询问健康数据
→ 运行:./scripts/api-call.sh GET /api/skill/xxx
├── 令牌有效 → 返回数据 → 完成
├── 令牌过期 → 自动刷新 → 返回数据 → 完成
└── 无令牌 → 返回错误
→ 运行:./scripts/auth-flow.sh [base_url](后台)
→ auth-flow.sh 自动轮询并保存令牌
→ 重试:./scripts/api-call.sh → 返回数据 → 完成
上传 + OCR(从图片保存医疗报告)
这是一个基于会话的多步骤工作流程。一个上传会话将所有文件+报告分组在一起。
步骤 1:上传 → 创建会话
bash
bash ./scripts/upload.sh /path/to/image1.jpg /path/to/image2.jpg
返回:
json
{ sessionid: uuid, memberid: uuid, files: [{ id: ..., original_name: ... }] }
保存 session_id——它用于所有后续步骤。
步骤 2:OCR(带实时进度)
bash
bash ./scripts/ocr-stream.sh
每行输出都是一个 JSON 进度事件。向用户传达:
- - step=normalize → 正在预处理文件...
- step=ocr → 正在 OCR 识别第 X/Y 页...
- step=structure → AI 正在分析报告结构...
- step=normalize_indicators → 正在标准化指标名称...
- step=done → OCR 完成,data 包含报告数组
步骤 3:展示结果供用户审核(必须)
不要自动调用确认。 解析 step=done 数据并显示:
识别到 N 份报告:
📋 报告 1: {report_title}
来源: {sourcePages.join(, )}
日期: {test_date} 医生: {doctor} 科室: {department}
┌──────────────────┬────────