sweatstack-cli 0.16.0__tar.gz → 0.17.1__tar.gz

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.
Files changed (101) hide show
  1. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/CHANGELOG.md +40 -0
  2. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/Makefile +7 -1
  3. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/PKG-INFO +1 -1
  4. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/pyproject.toml +1 -1
  5. sweatstack_cli-0.17.1/scripts/vendor_tool_template.sh +61 -0
  6. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/src/sweatstack_cli/api/client.py +9 -0
  7. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/src/sweatstack_cli/auth/tokens.py +16 -7
  8. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/src/sweatstack_cli/commands/auth.py +15 -6
  9. sweatstack_cli-0.17.1/src/sweatstack_cli/commands/tool.py +439 -0
  10. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/src/sweatstack_cli/exceptions.py +4 -0
  11. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/src/sweatstack_cli/project.py +44 -5
  12. sweatstack_cli-0.17.1/src/sweatstack_cli/templates/tool/index.html +353 -0
  13. sweatstack_cli-0.17.1/src/sweatstack_cli/templates/tool/vendor/duckdb.mjs +12652 -0
  14. sweatstack_cli-0.17.1/src/sweatstack_cli/templates/tool/vendor/licenses/apache-arrow.txt +2261 -0
  15. sweatstack_cli-0.17.1/src/sweatstack_cli/templates/tool/vendor/licenses/duckdb-wasm.txt +7 -0
  16. sweatstack_cli-0.17.1/src/sweatstack_cli/templates/tool/vendor/licenses/uplot.txt +21 -0
  17. sweatstack_cli-0.17.1/src/sweatstack_cli/templates/tool/vendor/sweatstack.js +44 -0
  18. sweatstack_cli-0.17.1/src/sweatstack_cli/templates/tool/vendor/uPlot.iife.min-1.6.31.js +2 -0
  19. sweatstack_cli-0.17.1/src/sweatstack_cli/templates/tool/vendor/uPlot.min-1.6.31.css +1 -0
  20. sweatstack_cli-0.17.1/src/sweatstack_cli/templates/tool/vendor.json +7 -0
  21. sweatstack_cli-0.17.1/src/sweatstack_cli/tools/deploy.py +174 -0
  22. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/src/sweatstack_cli/tools/policy.json +3 -2
  23. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/src/sweatstack_cli/tools/server.py +71 -9
  24. sweatstack_cli-0.17.1/src/sweatstack_cli/tools/signin.py +468 -0
  25. sweatstack_cli-0.17.1/src/sweatstack_cli/tools/template.py +110 -0
  26. sweatstack_cli-0.17.1/tests/e2e/fake_sweatstack.py +206 -0
  27. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/tests/e2e/test_page_template.py +7 -177
  28. sweatstack_cli-0.17.1/tests/e2e/test_tool_template.py +177 -0
  29. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/tests/test_auth/test_tokens.py +10 -3
  30. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/tests/test_commands/test_auth.py +30 -0
  31. sweatstack_cli-0.17.1/tests/test_commands/test_tool_commands.py +277 -0
  32. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/tests/test_tools/test_check.py +1 -1
  33. sweatstack_cli-0.17.1/tests/test_tools/test_deploy.py +168 -0
  34. sweatstack_cli-0.17.1/tests/test_tools/test_signin.py +633 -0
  35. sweatstack_cli-0.17.1/tests/test_tools/test_template.py +140 -0
  36. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/uv.lock +1 -1
  37. sweatstack_cli-0.16.0/src/sweatstack_cli/commands/tool.py +0 -153
  38. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/.claude/settings.local.json +0 -0
  39. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/.claude/skills/sweatstack/SKILL.md +0 -0
  40. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/.claude/skills/sweatstack/api.md +0 -0
  41. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/.claude/skills/sweatstack/auth.md +0 -0
  42. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/.claude/skills/sweatstack/cli.md +0 -0
  43. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/.claude/skills/sweatstack/pyscript.md +0 -0
  44. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/.claude/skills/sweatstack/webapp.md +0 -0
  45. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/.gitignore +0 -0
  46. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/.python-version +0 -0
  47. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/CREATE_PRIVATE_APP.md +0 -0
  48. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/DEVELOPMENT.md +0 -0
  49. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/PLAN.md +0 -0
  50. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/README.md +0 -0
  51. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/plans/001-page-init-command.md +0 -0
  52. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/src/sweatstack_cli/__init__.py +0 -0
  53. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/src/sweatstack_cli/api/__init__.py +0 -0
  54. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/src/sweatstack_cli/auth/__init__.py +0 -0
  55. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/src/sweatstack_cli/auth/callback_server.py +0 -0
  56. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/src/sweatstack_cli/auth/jwt.py +0 -0
  57. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/src/sweatstack_cli/auth/pkce.py +0 -0
  58. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/src/sweatstack_cli/commands/__init__.py +0 -0
  59. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/src/sweatstack_cli/commands/app.py +0 -0
  60. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/src/sweatstack_cli/commands/page.py +0 -0
  61. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/src/sweatstack_cli/config.py +0 -0
  62. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/src/sweatstack_cli/console.py +0 -0
  63. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/src/sweatstack_cli/go_live.py +0 -0
  64. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/src/sweatstack_cli/main.py +0 -0
  65. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/src/sweatstack_cli/py.typed +0 -0
  66. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/src/sweatstack_cli/services/__init__.py +0 -0
  67. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/src/sweatstack_cli/services/applications.py +0 -0
  68. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/src/sweatstack_cli/templates/page/index.html +0 -0
  69. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/src/sweatstack_cli/tools/__init__.py +0 -0
  70. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/src/sweatstack_cli/tools/check.py +0 -0
  71. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/src/sweatstack_cli/tools/content_types.json +0 -0
  72. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/src/sweatstack_cli/tools/policy.py +0 -0
  73. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/src/sweatstack_cli/tools/rewrite.py +0 -0
  74. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/src/sweatstack_cli/version_check.py +0 -0
  75. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/sweatstack.toml +0 -0
  76. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/tests/__init__.py +0 -0
  77. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/tests/conftest.py +0 -0
  78. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/tests/e2e/__init__.py +0 -0
  79. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/tests/e2e/test_tool_serve.py +0 -0
  80. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/tests/test_api/__init__.py +0 -0
  81. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/tests/test_api/test_client.py +0 -0
  82. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/tests/test_auth/__init__.py +0 -0
  83. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/tests/test_auth/test_authenticator.py +0 -0
  84. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/tests/test_auth/test_authorize_url.py +0 -0
  85. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/tests/test_auth/test_callback_server.py +0 -0
  86. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/tests/test_auth/test_jwt.py +0 -0
  87. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/tests/test_auth/test_pkce.py +0 -0
  88. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/tests/test_commands/__init__.py +0 -0
  89. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/tests/test_commands/test_app.py +0 -0
  90. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/tests/test_commands/test_cli.py +0 -0
  91. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/tests/test_commands/test_page_deploy.py +0 -0
  92. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/tests/test_commands/test_page_init.py +0 -0
  93. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/tests/test_project.py +0 -0
  94. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/tests/test_services/__init__.py +0 -0
  95. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/tests/test_services/test_applications.py +0 -0
  96. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/tests/test_tools/__init__.py +0 -0
  97. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/tests/test_tools/test_policy.py +0 -0
  98. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/tests/test_tools/test_rewrite.py +0 -0
  99. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/tests/test_tools/test_server.py +0 -0
  100. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/tests/test_version.py +0 -0
  101. {sweatstack_cli-0.16.0 → sweatstack_cli-0.17.1}/tests/test_version_check.py +0 -0
@@ -4,6 +4,46 @@ All notable changes to this project are documented here. The format is based on
4
4
  [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project
5
5
  adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [0.17.1] - 2026-11-20
8
+
9
+ ### Fixed
10
+
11
+ - Signing in to another SweatStack with `SWEATSTACK_URL`, such as staging, no longer
12
+ replaces the production sign-in. Production keeps `tokens.json`, shared with the
13
+ Python library, and any other SweatStack its own `tokens-{host}.json`. If you signed in
14
+ to another SweatStack with an earlier version, run `sweatstack login` again.
15
+ - `sweatstack status` says "Not authenticated", and exits with 1, when SweatStack refuses
16
+ the stored sign-in, instead of "Authenticated" without a name.
17
+
18
+ ## [0.17.0] - 2026-11-20
19
+
20
+ ### Added
21
+
22
+ - `sweatstack tool create` creates a private tool on SweatStack Tools, writes its
23
+ `[tool]` section to `sweatstack.toml`, and scaffolds the tool template. On a
24
+ developer's first tool it sets their handle and public name. Every prompt has an
25
+ option, so an agent can run it without a terminal.
26
+ - `sweatstack tool deploy` checks the folder against the Tools contract (paths, the
27
+ reserved `_gate` and `_sweatstack` prefixes, links outside the folder, size and file
28
+ limits) before anything is sent, then uploads only the files SweatStack does not
29
+ store yet, four at a time. An upload refused while another deploy of the tool runs
30
+ (409) or while the store is unavailable (503) is retried for half a minute.
31
+ `--allow-external` deploys despite
32
+ references `tool check` reports.
33
+ - `sweatstack tool deploys` lists a tool's kept deploys, newest first, with the one serving.
34
+ - `sweatstack tool rollback [DEPLOY_ID]` serves an earlier deploy again, and
35
+ `sweatstack tool publish [--unlisted]` makes a tool listed or unlisted.
36
+ - The tool template: one page, with SweatStack Tools' `sweatstack.js` and a pinned
37
+ DuckDB-WASM in the tool's own folder, that plots the latest activity. It has no OAuth
38
+ code: SweatStack Tools signs people in.
39
+ - `sweatstack tool serve` signs people in as SweatStack Tools does, at
40
+ `http://{slug}.localhost:{port}`, when `sweatstack.toml` gives the tool scopes beyond
41
+ `openid profile`. Chromium and Firefox; Safari keeps no `__Host-` cookie on plain http.
42
+
43
+ ### Fixed
44
+
45
+ - A name or title with a quote no longer breaks `sweatstack.toml`.
46
+
7
47
  ## [0.16.0] - 2026-11-20
8
48
 
9
49
  ### Added
@@ -1,4 +1,4 @@
1
- .PHONY: help install dev test test-e2e lint format typecheck check clean build publish refresh-policy
1
+ .PHONY: help install dev test test-e2e lint format typecheck check clean build publish refresh-policy vendor-tool-template
2
2
 
3
3
  help:
4
4
  @echo "SweatStack CLI Development Commands"
@@ -12,6 +12,7 @@ help:
12
12
  @echo " make typecheck Run type checker"
13
13
  @echo " make check Run all checks (lint, format, typecheck, test)"
14
14
  @echo " make refresh-policy Copy the live SweatStack Tools policy into the package"
15
+ @echo " make vendor-tool-template Rebuild the tool template's files and download pins (needs Node)"
15
16
  @echo " make clean Remove build artifacts"
16
17
  @echo " make build Build distribution packages"
17
18
  @echo " make publish Publish to PyPI"
@@ -54,6 +55,11 @@ refresh-policy:
54
55
  curl -fsS https://sweatstack.tools/v1/policy -o src/sweatstack_cli/tools/policy.json
55
56
  uv run python -c "import json; from sweatstack_cli.tools.policy import parse_policy; parse_policy(json.load(open('src/sweatstack_cli/tools/policy.json')), 'built-in')"
56
57
 
58
+ # The files the `tool create` template ships, and the SHA-256 pins of the files it downloads.
59
+ # Run after changing a version in scripts/vendor_tool_template.sh, and commit the result.
60
+ vendor-tool-template:
61
+ ./scripts/vendor_tool_template.sh
62
+
57
63
  build:
58
64
  rm -rf dist
59
65
  uv build
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: sweatstack-cli
3
- Version: 0.16.0
3
+ Version: 0.17.1
4
4
  Summary: Command-line interface for SweatStack — the sports data platform for developers
5
5
  Project-URL: Homepage, https://sweatstack.no
6
6
  Project-URL: Documentation, https://docs.sweatstack.no
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "sweatstack-cli"
3
- version = "0.16.0"
3
+ version = "0.17.1"
4
4
  description = "Command-line interface for SweatStack — the sports data platform for developers"
5
5
  readme = "README.md"
6
6
  authors = [{ name = "Aart Goossens", email = "aart@sweatstack.no" }]
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env bash
2
+ # Rebuilds the files the `tool create` template ships, and the pins of the files it downloads.
3
+ # Needs Node (npm, npx) and curl. Run from the repo root with `make vendor-tool-template`.
4
+ #
5
+ # Shipped in the package (small): the sign-in reference implementation, copied from the Tools app's
6
+ # contract (TOOLS_REPO, ../sweatstack-tools-v2 by default), uPlot, DuckDB-WASM's browser module
7
+ # bundled with esbuild (it imports apache-arrow by name), and their licences. Downloaded by `tool create` (large), each
8
+ # pinned by SHA-256 in vendor.json: DuckDB's EH WebAssembly, its worker, and the Parquet extension,
9
+ # which DuckDB otherwise fetches from extensions.duckdb.org, where SweatStack Tools blocks it.
10
+ set -euo pipefail
11
+
12
+ UPLOT=1.6.31
13
+ DUCKDB_WASM=1.32.0
14
+ DUCKDB=v1.4.3 # DuckDB's own version inside DuckDB-WASM $DUCKDB_WASM
15
+ ESBUILD=0.28.2
16
+
17
+ OUT=src/sweatstack_cli/templates/tool
18
+ TOOLS_REPO=${TOOLS_REPO:-../sweatstack-tools-v2}
19
+ REFERENCE="$TOOLS_REPO/contract/sign-in/sweatstack.js"
20
+ [ -f "$REFERENCE" ] || { echo "No $REFERENCE: set TOOLS_REPO to the Tools app's repository" >&2; exit 1; }
21
+ WORK=$(mktemp -d)
22
+ trap 'rm -rf "$WORK"' EXIT
23
+
24
+ (cd "$WORK" && npm init -y >/dev/null && npm install --no-audit --no-fund --save-exact \
25
+ "uplot@$UPLOT" "@duckdb/duckdb-wasm@$DUCKDB_WASM" "esbuild@$ESBUILD" >/dev/null)
26
+
27
+ rm -rf "$OUT/vendor" && mkdir -p "$OUT/vendor/licenses"
28
+ cp "$WORK/node_modules/uplot/dist/uPlot.iife.min.js" "$OUT/vendor/uPlot.iife.min-$UPLOT.js"
29
+ cp "$WORK/node_modules/uplot/dist/uPlot.min.css" "$OUT/vendor/uPlot.min-$UPLOT.css"
30
+ (cd "$WORK" && npx esbuild node_modules/@duckdb/duckdb-wasm/dist/duckdb-browser.mjs \
31
+ --bundle --format=esm --log-level=warning --outfile=duckdb.mjs)
32
+ cp "$WORK/duckdb.mjs" "$OUT/vendor/duckdb.mjs"
33
+ cp "$REFERENCE" "$OUT/vendor/sweatstack.js"
34
+ cp "$WORK/node_modules/uplot/LICENSE" "$OUT/vendor/licenses/uplot.txt"
35
+ # The npm package declares MIT but carries no licence file: take it from the release tag.
36
+ curl -fsSL "https://raw.githubusercontent.com/duckdb/duckdb-wasm/v$DUCKDB_WASM/LICENSE" -o "$OUT/vendor/licenses/duckdb-wasm.txt"
37
+ cp "$WORK/node_modules/apache-arrow/LICENSE.txt" "$OUT/vendor/licenses/apache-arrow.txt"
38
+
39
+ download() { # published path, URL: fetch it, and print its pin
40
+ local path=$1 url=$2 file="$WORK/download"
41
+ curl -fsSL "$url" -o "$file"
42
+ printf ' {"path": "%s", "url": "%s", "size": %s, "sha256": "%s"}' \
43
+ "$path" "$url" "$(wc -c < "$file" | tr -d ' ')" "$(shasum -a 256 "$file" | cut -d' ' -f1)"
44
+ }
45
+
46
+ {
47
+ echo '{'
48
+ echo ' "downloads": ['
49
+ download "vendor/duckdb-eh.wasm" "https://cdn.jsdelivr.net/npm/@duckdb/duckdb-wasm@$DUCKDB_WASM/dist/duckdb-eh.wasm"; echo ','
50
+ download "vendor/duckdb-browser-eh.worker.js" "https://cdn.jsdelivr.net/npm/@duckdb/duckdb-wasm@$DUCKDB_WASM/dist/duckdb-browser-eh.worker.js"; echo ','
51
+ download "vendor/duckdb-extensions/$DUCKDB/wasm_eh/parquet.duckdb_extension.wasm" "https://extensions.duckdb.org/$DUCKDB/wasm_eh/parquet.duckdb_extension.wasm"; echo
52
+ echo ' ]'
53
+ echo '}'
54
+ } > "$OUT/vendor.json"
55
+
56
+ # The npm package's files must be the ones jsDelivr serves.
57
+ for name in duckdb-eh.wasm duckdb-browser-eh.worker.js; do
58
+ local_sha=$(shasum -a 256 "$WORK/node_modules/@duckdb/duckdb-wasm/dist/$name" | cut -d' ' -f1)
59
+ grep -q "$local_sha" "$OUT/vendor.json" || { echo "jsDelivr's $name differs from the npm package" >&2; exit 1; }
60
+ done
61
+ echo "Wrote $OUT/vendor/ and $OUT/vendor.json"
@@ -172,6 +172,7 @@ class APIClient:
172
172
  status_code=response.status_code,
173
173
  code=code,
174
174
  detail=detail,
175
+ body=self._json_object(response),
175
176
  )
176
177
 
177
178
  # Handle empty responses
@@ -181,6 +182,14 @@ class APIClient:
181
182
  result: dict[str, Any] = response.json()
182
183
  return result
183
184
 
185
+ @staticmethod
186
+ def _json_object(response: httpx.Response) -> dict[str, object] | None:
187
+ try:
188
+ data = response.json()
189
+ except ValueError:
190
+ return None
191
+ return data if isinstance(data, dict) else None
192
+
184
193
  def _extract_error(self, response: httpx.Response) -> tuple[str, str | None]:
185
194
  """Extract the human-readable detail and optional machine-readable code.
186
195
 
@@ -4,24 +4,29 @@ from __future__ import annotations
4
4
 
5
5
  import json
6
6
  import os
7
+ import re
7
8
  import time
8
9
  from dataclasses import dataclass
9
10
  from pathlib import Path
10
11
  from typing import Protocol
12
+ from urllib.parse import urlsplit
11
13
 
12
14
  import platformdirs
13
15
 
16
+ from sweatstack_cli.config import DEFAULT_API_URL, get_settings
14
17
 
15
- def get_tokens_path() -> Path:
18
+
19
+ def get_tokens_path(api_url: str | None = None) -> Path:
16
20
  """
17
- Get the path to the tokens file.
21
+ Get the path to the tokens file of the SweatStack at `api_url` (`SWEATSTACK_URL`'s by default).
18
22
 
19
- Uses platformdirs for OS-appropriate user data directory.
20
- This path is shared with the sweatstack Python library for
21
- seamless interoperability.
23
+ Uses platformdirs for OS-appropriate user data directory. Production's sign-in is
24
+ `tokens.json`, shared with the sweatstack Python library for seamless interoperability.
25
+ Any other SweatStack, such as staging, keeps its own file named after its host, so
26
+ signing in there never replaces the production sign-in.
22
27
 
23
28
  Returns:
24
- Path to tokens.json file.
29
+ Path to tokens.json, or tokens-{host}.json for another SweatStack.
25
30
 
26
31
  Platform-specific paths:
27
32
  - macOS: ~/Library/Application Support/SweatStack/tokens.json
@@ -29,7 +34,11 @@ def get_tokens_path() -> Path:
29
34
  - Windows: %APPDATA%\\SweatStack\\SweatStack\\tokens.json
30
35
  """
31
36
  data_dir = Path(platformdirs.user_data_dir("SweatStack", "SweatStack"))
32
- return data_dir / "tokens.json"
37
+ url = (api_url or get_settings().api_url).rstrip("/")
38
+ if url == DEFAULT_API_URL:
39
+ return data_dir / "tokens.json"
40
+ host = re.sub(r"[^A-Za-z0-9.-]", "-", urlsplit(url).netloc or url)
41
+ return data_dir / f"tokens-{host}.json"
33
42
 
34
43
 
35
44
  @dataclass(frozen=True, slots=True)
@@ -3,6 +3,7 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  from datetime import datetime
6
+ from typing import Any
6
7
 
7
8
  import typer
8
9
 
@@ -10,7 +11,7 @@ from sweatstack_cli.api import APIClient
10
11
  from sweatstack_cli.auth import Authenticator
11
12
  from sweatstack_cli.auth.jwt import decode_jwt_payload
12
13
  from sweatstack_cli.console import console
13
- from sweatstack_cli.exceptions import APIError, AuthenticationError
14
+ from sweatstack_cli.exceptions import APIError, AuthenticationError, SecondFactorRequired
14
15
  from sweatstack_cli.version_check import check_for_update
15
16
 
16
17
 
@@ -92,18 +93,26 @@ def status() -> None:
92
93
  auth = Authenticator()
93
94
  tokens = auth.get_valid_tokens()
94
95
 
96
+ user: dict[str, Any] | None = None
97
+ if tokens is not None:
98
+ try:
99
+ user = APIClient(authenticator=auth).get("/api/v1/oauth/userinfo")
100
+ except SecondFactorRequired:
101
+ pass # A step-up is not a refusal of the sign-in.
102
+ except AuthenticationError:
103
+ # Stored tokens SweatStack refuses (revoked, or from another SweatStack) are no sign-in.
104
+ tokens = None
105
+ except APIError:
106
+ pass # SweatStack could not say who this is; the sign-in may still be good.
107
+
95
108
  if tokens is None:
96
109
  console.print("[red]✗[/red] Not authenticated")
97
110
  else:
98
111
  console.print("[green]✓[/green] Authenticated")
99
- try:
100
- client = APIClient(authenticator=auth)
101
- user = client.get("/api/v1/oauth/userinfo")
112
+ if user is not None:
102
113
  console.print(f" Name: {_display_name(user)}")
103
114
  console.print(f" Email: {user.get('email', 'unknown')}")
104
115
  console.print(f" ID: {user.get('sub', 'unknown')}")
105
- except (AuthenticationError, APIError):
106
- pass # Silently skip user info on error
107
116
  console.print(f" Passkey: {_confirmation(tokens.access_token)}")
108
117
 
109
118
  # Check version