ctx-cloud-setup

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Context Mode Cloud Setup

Context Mode Cloud 配置指南

Interactive onboarding flow to connect this plugin to Context Mode Cloud.
用于将此插件连接至Context Mode Cloud的交互式入门流程。

Instructions

操作步骤

  1. Check existing config — read
    ~/.context-mode/sync.json
    using Bash:
    cat ~/.context-mode/sync.json 2>/dev/null || echo "NOT_FOUND"
    • If the file exists and contains a non-empty
      api_token
      , inform the user that cloud sync is already configured and show the current
      api_url
      and
      organization_id
      (never reveal the token — show only the last 4 characters masked as
      ctx_****abcd
      ).
    • Ask if they want to reconfigure or keep the current settings. If they want to keep, stop here.
  2. Collect configuration — ask the user for three values, one at a time:
    a) API URL
    • Default:
      https://api.context-mode.com
    • Tell the user: "Press Enter to use the default, or paste your self-hosted API URL."
    • If the user says "default", use
      https://api.context-mode.com
      .
    b) API Token
    • Tell the user: "Paste your API token from the Context Mode dashboard: Settings > API Tokens."
    • This field is required — do not proceed without it.
    • Validate format: token should start with
      ctx_
      and be at least 20 characters. If invalid, warn and ask again.
    c) Organization ID
    • Tell the user: "Paste your Organization ID from the dashboard: Settings > Team."
    • This field is required — do not proceed without it.
  3. Save config — write the merged config to
    ~/.context-mode/sync.json
    using Bash:
    bash
    mkdir -p ~/.context-mode
    cat > ~/.context-mode/sync.json << 'JSONEOF'
    {
      "enabled": true,
      "api_url": "<API_URL>",
      "api_token": "<API_TOKEN>",
      "organization_id": "<ORG_ID>",
      "batch_size": 50,
      "flush_interval_ms": 30000
    }
    JSONEOF
    chmod 600 ~/.context-mode/sync.json
    Replace
    <API_URL>
    ,
    <API_TOKEN>
    , and
    <ORG_ID>
    with the collected values.
  4. Test the connection — send a health check using Bash:
    bash
    curl -sf -o /dev/null -w "%{http_code}" \
      -H "Authorization: Bearer <API_TOKEN>" \
      "<API_URL>/api/health"
    • 200
      = success
    • Any other code or failure = connection error
  5. Display results as markdown directly in the conversation:
    On success:
    ## context-mode cloud setup
    - [x] Config saved to ~/.context-mode/sync.json
    - [x] Connection test: PASS (200 OK)
    - [x] Organization: <ORG_ID>
    
    Cloud sync is now active. Events will be sent to the dashboard
    on your next Claude Code session. Run `/ctx-cloud-status` to
    check sync health at any time.
    On failure:
    ## context-mode cloud setup
    - [x] Config saved to ~/.context-mode/sync.json
    - [ ] Connection test: FAIL (<error details>)
    
    Config was saved but the connection test failed. Check that:
    1. Your API URL is reachable
    2. Your API token is valid and not expired
    3. Your network allows outbound HTTPS
    
    Run `/ctx-cloud-setup` again to reconfigure.
  1. 检查现有配置 — 使用Bash读取
    ~/.context-mode/sync.json
    文件:
    cat ~/.context-mode/sync.json 2>/dev/null || echo "NOT_FOUND"
    • 如果文件已存在且包含非空的
      api_token
      ,告知用户云同步已完成配置,并显示当前的
      api_url
      organization_id
      (绝对不可泄露完整令牌——仅显示最后4位,格式如
      ctx_****abcd
      )。
    • 询问用户是否需要重新配置保留当前设置。若用户选择保留,流程到此结束。
  2. 收集配置信息 — 分三次向用户请求以下三个值:
    a) API URL
    • 默认值:
      https://api.context-mode.com
    • 告知用户:“按回车键使用默认值,或粘贴您的自托管API URL。”
    • 若用户输入“default”,则使用
      https://api.context-mode.com
    b) API 令牌
    • 告知用户:“从Context Mode控制面板粘贴您的API令牌:设置 > API令牌。”
    • 此字段为必填项 — 未获取到令牌则不继续流程。
    • 格式验证:令牌需以
      ctx_
      开头且长度至少为20字符。若格式无效,发出警告并重新请求。
    c) 组织ID
    • 告知用户:“从控制面板粘贴您的组织ID:设置 > 团队。”
    • 此字段为必填项 — 未获取到组织ID则不继续流程。
  3. 保存配置 — 使用Bash将合并后的配置写入
    ~/.context-mode/sync.json
    文件:
    bash
    mkdir -p ~/.context-mode
    cat > ~/.context-mode/sync.json << 'JSONEOF'
    {
      "enabled": true,
      "api_url": "<API_URL>",
      "api_token": "<API_TOKEN>",
      "organization_id": "<ORG_ID>",
      "batch_size": 50,
      "flush_interval_ms": 30000
    }
    JSONEOF
    chmod 600 ~/.context-mode/sync.json
    <API_URL>
    <API_TOKEN>
    <ORG_ID>
    替换为收集到的对应值。
  4. 测试连接 — 使用Bash发送健康检查请求:
    bash
    curl -sf -o /dev/null -w "%{http_code}" \
      -H "Authorization: Bearer <API_TOKEN>" \
      "<API_URL>/api/health"
    • 返回
      200
      = 连接成功
    • 其他状态码或请求失败 = 连接错误
  5. 展示结果 — 直接在对话中以markdown格式显示:
    连接成功时:
    ## context-mode cloud 配置结果
    - [x] 配置已保存至~/.context-mode/sync.json
    - [x] 连接测试:通过(200 OK)
    - [x] 组织:<ORG_ID>
    
    云同步现已激活。在您的下一次Claude Code会话中,事件将被发送至控制面板。随时运行`/ctx-cloud-status`命令检查同步健康状态。
    连接失败时:
    ## context-mode cloud 配置结果
    - [x] 配置已保存至~/.context-mode/sync.json
    - [ ] 连接测试:失败(<错误详情>)
    
    配置已保存但连接测试失败。请检查:
    1. 您的API URL是否可访问
    2. 您的API令牌是否有效且未过期
    3. 您的网络是否允许HTTPS出站请求
    
    重新运行`/ctx-cloud-setup`命令进行重新配置。

Security Notes

安全注意事项

  • Never log or display the full API token. Always mask it.
  • Set file permissions to
    600
    (owner read/write only).
  • The token is sent only over HTTPS in the
    Authorization
    header.
  • 绝不要记录或显示完整的API令牌,始终对其进行掩码处理。
  • 将文件权限设置为
    600
    (仅所有者可读写)。
  • 令牌仅通过HTTPS在
    Authorization
    请求头中传输。