cinna-cli 0.7.0__tar.gz → 0.7.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 (130) hide show
  1. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/PKG-INFO +1 -1
  2. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/account_workspace/account_workspace.md +6 -3
  3. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/account_workspace/account_workspace_acceptance.md +4 -1
  4. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/account_workspace/account_workspace_tech.md +18 -6
  5. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/pyproject.toml +1 -1
  6. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/src/cinna/account.py +64 -10
  7. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/src/cinna/main.py +3 -2
  8. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/tests/test_onboarding.py +204 -9
  9. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/uv.lock +1 -1
  10. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/.claude/commands/cinna-cli.feature.doc.md +0 -0
  11. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/.github/workflows/publish.yml +0 -0
  12. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/.gitignore +0 -0
  13. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/LICENSE.md +0 -0
  14. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/README.md +0 -0
  15. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/README.md +0 -0
  16. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/agent_addons/agent_addons.md +0 -0
  17. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/agent_addons/agent_addons_acceptance.md +0 -0
  18. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/agent_addons/agent_addons_tech.md +0 -0
  19. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/agent_api/agent_api.md +0 -0
  20. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/agent_api/agent_api_acceptance.md +0 -0
  21. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/agent_api/agent_api_tech.md +0 -0
  22. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/agent_management/agent_management.md +0 -0
  23. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/agent_management/agent_management_acceptance.md +0 -0
  24. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/agent_management/agent_management_tech.md +0 -0
  25. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/agent_schedules/agent_schedules.md +0 -0
  26. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/agent_schedules/agent_schedules_acceptance.md +0 -0
  27. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/agent_schedules/agent_schedules_tech.md +0 -0
  28. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/artifacts/artifacts.md +0 -0
  29. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/artifacts/artifacts_acceptance.md +0 -0
  30. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/artifacts/artifacts_tech.md +0 -0
  31. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/bootstrap_onboarding/bootstrap_onboarding.md +0 -0
  32. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/bootstrap_onboarding/bootstrap_onboarding_acceptance.md +0 -0
  33. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/bootstrap_onboarding/bootstrap_onboarding_tech.md +0 -0
  34. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/dashboards/dashboards.md +0 -0
  35. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/dashboards/dashboards_acceptance.md +0 -0
  36. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/dashboards/dashboards_tech.md +0 -0
  37. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/delegation/delegation.md +0 -0
  38. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/delegation/delegation_acceptance.md +0 -0
  39. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/delegation/delegation_tech.md +0 -0
  40. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/doctor/doctor.md +0 -0
  41. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/doctor/doctor_acceptance.md +0 -0
  42. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/doctor/doctor_tech.md +0 -0
  43. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/git_versioning/git_versioning.md +0 -0
  44. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/git_versioning/git_versioning_acceptance.md +0 -0
  45. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/git_versioning/git_versioning_tech.md +0 -0
  46. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/improvement_requests/improvement_requests.md +0 -0
  47. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/improvement_requests/improvement_requests_acceptance.md +0 -0
  48. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/improvement_requests/improvement_requests_tech.md +0 -0
  49. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/live_sync/live_sync.md +0 -0
  50. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/live_sync/live_sync_acceptance.md +0 -0
  51. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/live_sync/live_sync_tech.md +0 -0
  52. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/local_agent_import/local_agent_import.md +0 -0
  53. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/local_agent_import/local_agent_import_acceptance.md +0 -0
  54. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/local_agent_import/local_agent_import_tech.md +0 -0
  55. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/mcp_integration/mcp_integration.md +0 -0
  56. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/mcp_integration/mcp_integration_acceptance.md +0 -0
  57. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/mcp_integration/mcp_integration_tech.md +0 -0
  58. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/remote_chat/remote_chat.md +0 -0
  59. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/remote_chat/remote_chat_acceptance.md +0 -0
  60. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/remote_chat/remote_chat_tech.md +0 -0
  61. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/remote_exec/remote_exec.md +0 -0
  62. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/remote_exec/remote_exec_acceptance.md +0 -0
  63. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/remote_exec/remote_exec_tech.md +0 -0
  64. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/team_library/team_library.md +0 -0
  65. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/team_library/team_library_acceptance.md +0 -0
  66. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/features/team_library/team_library_tech.md +0 -0
  67. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/interface.md +0 -0
  68. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/docs/mutagen_capabilities.md +0 -0
  69. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/scripts/check_docs_references.py +0 -0
  70. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/src/cinna/__init__.py +0 -0
  71. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/src/cinna/agent_api_connections.py +0 -0
  72. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/src/cinna/artifacts.py +0 -0
  73. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/src/cinna/auth.py +0 -0
  74. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/src/cinna/bootstrap.py +0 -0
  75. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/src/cinna/chat.py +0 -0
  76. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/src/cinna/cli_version.py +0 -0
  77. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/src/cinna/client.py +0 -0
  78. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/src/cinna/config.py +0 -0
  79. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/src/cinna/console.py +0 -0
  80. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/src/cinna/context.py +0 -0
  81. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/src/cinna/dashboards.py +0 -0
  82. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/src/cinna/delegation.py +0 -0
  83. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/src/cinna/doctor.py +0 -0
  84. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/src/cinna/errors.py +0 -0
  85. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/src/cinna/git_versioning.py +0 -0
  86. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/src/cinna/improve.py +0 -0
  87. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/src/cinna/kit_contract.py +0 -0
  88. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/src/cinna/library.py +0 -0
  89. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/src/cinna/local_import.py +0 -0
  90. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/src/cinna/logging.py +0 -0
  91. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/src/cinna/mcp_proxy.py +0 -0
  92. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/src/cinna/mutagen_runtime.py +0 -0
  93. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/src/cinna/scenarios.py +0 -0
  94. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/src/cinna/sync.py +0 -0
  95. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/src/cinna/sync_session.py +0 -0
  96. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/src/cinna/sync_ssh_shim.py +0 -0
  97. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/src/cinna/sync_tui.py +0 -0
  98. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/src/cinna/templates/ACCOUNT_CLAUDE.md.template +0 -0
  99. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/src/cinna/templates/CHAT_TESTING.md +0 -0
  100. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/src/cinna/templates/CLAUDE.md.template +0 -0
  101. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/src/cinna/templates/GIT_VERSIONING.md +0 -0
  102. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/src/cinna/templates/__init__.py +0 -0
  103. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/tests/__init__.py +0 -0
  104. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/tests/conftest.py +0 -0
  105. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/tests/test_account.py +0 -0
  106. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/tests/test_agent_api_access.py +0 -0
  107. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/tests/test_agent_api_connections.py +0 -0
  108. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/tests/test_artifacts.py +0 -0
  109. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/tests/test_auth.py +0 -0
  110. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/tests/test_bootstrap.py +0 -0
  111. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/tests/test_chat.py +0 -0
  112. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/tests/test_cli_version.py +0 -0
  113. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/tests/test_client.py +0 -0
  114. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/tests/test_config.py +0 -0
  115. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/tests/test_console.py +0 -0
  116. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/tests/test_context.py +0 -0
  117. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/tests/test_dashboards.py +0 -0
  118. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/tests/test_delegation.py +0 -0
  119. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/tests/test_doctor.py +0 -0
  120. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/tests/test_git_versioning.py +0 -0
  121. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/tests/test_improve.py +0 -0
  122. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/tests/test_kit_contract.py +0 -0
  123. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/tests/test_library.py +0 -0
  124. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/tests/test_local_import.py +0 -0
  125. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/tests/test_main.py +0 -0
  126. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/tests/test_mutagen_runtime.py +0 -0
  127. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/tests/test_scenarios.py +0 -0
  128. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/tests/test_sync.py +0 -0
  129. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/tests/test_sync_session.py +0 -0
  130. {cinna_cli-0.7.0 → cinna_cli-0.7.1}/tests/test_sync_ssh_shim.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: cinna-cli
3
- Version: 0.7.0
3
+ Version: 0.7.1
4
4
  Summary: Local development CLI for Cinna Core agents
5
5
  Project-URL: Homepage, https://github.com/opencinna/cinna-cli
6
6
  Project-URL: Repository, https://github.com/opencinna/cinna-cli
@@ -102,7 +102,9 @@ each with its own token, registry entry, and Mutagen session.
102
102
  `cinna login` gives, minus the browser. A bare token reuses the stored
103
103
  platform URL.
104
104
  3. The new token must be for the **same account**: a different platform origin,
105
- or a different `sub` on the token, is refused (exit 11) and nothing is written.
105
+ or a different `owner_id` on the token, is refused (exit 11) and nothing is
106
+ written. The token's `sub` is not compared: the platform mints a new token
107
+ row, and so a new `sub`, on every exchange.
106
108
  4. Child tokens are not touched; `cinna doctor` re-mints expired ones as usual.
107
109
 
108
110
  ### Driven by Cinna Desktop (no terminal)
@@ -126,8 +128,9 @@ each with its own token, registry entry, and Mutagen session.
126
128
  `not_an_account_workspace`, …) · `2` bad invocation.
127
129
  5. Later the desktop runs `cinna account set-token "<setup_command>" --no-input
128
130
  --json` to refresh silently, and `cinna account status --json` to read token
129
- validity, synced agents, context-package freshness and whether the installed
130
- cinna-cli matches the version the platform pins.
131
+ validity, the owning account (`account.id`, read from the token even when it
132
+ has expired), synced agents, context-package freshness and whether the
133
+ installed cinna-cli matches the version the platform pins.
131
134
 
132
135
  ### Discover and attach agents
133
136
  1. `cinna account agents` lists the agents the account can access — name + id,
@@ -357,7 +357,10 @@ the silent-secret and scope-drift bugs live.
357
357
  cinna doctor --dry-run
358
358
  ```
359
359
  - **Expected:** exactly one JSON line with `result`, `workspace`,
360
- `platform_url`, `frontend_url`, `machine_name`, `active_workspace`
360
+ `platform_url`, `frontend_url`, `machine_name`, `account` (`{id}` — the
361
+ token's `owner_id`, present even with an expired token or the platform down;
362
+ `email` only if the platform returns one; the key is absent, not `null`, for a
363
+ token without `owner_id`), `active_workspace`
361
364
  (`{id,name}` or `null`), `token` (`valid|expired|unreachable`),
362
365
  `synced_agents`, `agents[]`, `context_package{local,remote,state}` and
363
366
  `cli{installed,required,state}`. When the platform publishes
@@ -140,12 +140,15 @@ Related (documented here as integration points): `cinna agent sync` →
140
140
  - `src/cinna/account.py:run_account_set_token()` — `find_account_root()` →
141
141
  `parse_account_setup_input(…, fallback_platform_url=<stored>/api)` →
142
142
  exchange under the **stored** `machine_name` → `_same_origin()` check on
143
- `platform_url` and `_jwt_claims()` `sub` comparison (both raise
143
+ `platform_url` and `_token_owner_id()` `owner_id` comparison, skipped when
144
+ either token lacks one (both raise
144
145
  `AccountMismatchError`, 11, before any write) → rewrite `account_token` +
145
146
  refreshed `platform_url` / `frontend_url` → `save_account_config()`.
146
147
  `user_workspace_*`, `machine_name`, `context/`, children untouched.
147
148
  - `src/cinna/account.py:_jwt_claims()` — unverified base64 decode of a JWT
148
- payload, only to compare `sub`; opaque tokens yield `None` (no comparison).
149
+ payload, only to read `owner_id` (`_token_owner_id()`); opaque tokens yield
150
+ `None` (no comparison, no account id). Never `sub`: core's `create_cli_jwt`
151
+ puts the CLI token row id there, a fresh uuid per mint.
149
152
  - `src/cinna/account.py:_account_result_fields()` — the shared `--json` final
150
153
  line of setup / set-token (`workspace`, `platform_url`, `frontend_url`,
151
154
  `machine_name`, `context_package: ok|failed|skipped`).
@@ -165,7 +168,8 @@ Related (documented here as integration points): `cinna agent sync` →
165
168
  row with the local checkout from `list_child_workspaces()`.
166
169
  - `src/cinna/account.py:run_account_status()` — `probe_account_token()` +
167
170
  `context_package_status()` + `cli_version_status()`; in JSON mode emits the
168
- single `result` line (`token`, `active_workspace`, `synced_agents`, `agents[]`,
171
+ single `result` line (`account{id,email?}`, `token`, `active_workspace`,
172
+ `synced_agents`, `agents[]`,
169
173
  `context_package{local,remote,state}`, `cli{installed,required,state}`) and
170
174
  returns; otherwise the Rich table + `_synced_agents_table()` +
171
175
  `_print_token_reauth_hint()` (which now names `cinna account set-token` next
@@ -278,7 +282,7 @@ All consumed by `src/cinna/client.py:AccountClient` with the account token
278
282
  `platform_url`, `frontend_url`, `machine_name`. Used by both `account setup`
279
283
  and `account set-token`; the CLI relies on the response being identical for a
280
284
  first and a repeat exchange (no `user`/owner field is required — the
281
- same-account check works from the origin and the token's own `sub`).
285
+ same-account check works from the origin and the token's own `owner_id`).
282
286
  - `GET /.well-known/cinna-desktop` (unauthenticated, platform origin) — the
283
287
  desktop discovery document; `local_dev.cinna_cli_version` is the cinna-cli
284
288
  pin (`src/cinna/cli_version.py:fetch_required_cli_version()`). Absent block,
@@ -323,10 +327,18 @@ All consumed by `src/cinna/client.py:AccountClient` with the account token
323
327
  - **Absolute `--dir` is used as is, parents created** — `resolve_account_dir()`;
324
328
  the `workspace` reported in JSON is the path the caller passed.
325
329
  (`tests/test_onboarding.py:test_setup_absolute_dir_used_as_is_and_parents_created`)
326
- - **`set-token` never rebinds** — the origin / `sub` checks precede the write;
330
+ - **`set-token` never rebinds** — the origin / `owner_id` checks precede the write;
327
331
  on mismatch `account.json` is byte-identical afterwards.
328
332
  (`tests/test_onboarding.py:test_account_set_token_platform_mismatch_exits_11`,
329
- `test_account_set_token_subject_mismatch_exits_11`)
333
+ `test_account_set_token_owner_mismatch_exits_11`; a same-owner refresh with a
334
+ new `sub` passes, `test_account_set_token_same_owner_new_sub_succeeds`)
335
+ - **`account status --json` names the account** — `_account_identity()`:
336
+ `account.id` is the token's `owner_id` claim, a local read present for valid,
337
+ expired and unreachable tokens; `account.email` only when the probe's 2xx body
338
+ carries `account.email` (core's `GET /cli/account/agents` does not today, so it
339
+ is normally absent); no `account` key, never `null`, without an `owner_id`.
340
+ (`tests/test_onboarding.py:test_status_json_account_id_*`,
341
+ `test_status_json_no_account_key_without_owner_id`)
330
342
  - **`set-token` preserves everything but the token** — active user workspace,
331
343
  machine name and child configs survive.
332
344
  (`tests/test_onboarding.py:test_account_set_token_swaps_token_in_place`)
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "cinna-cli"
3
- version = "0.7.0"
3
+ version = "0.7.1"
4
4
  description = "Local development CLI for Cinna Core agents"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
@@ -441,11 +441,16 @@ def context_package_hint(state: str) -> str | None:
441
441
  # ── Token probe ─────────────────────────────────────────────────────────────
442
442
 
443
443
 
444
- def probe_account_token(config: AccountConfig) -> str:
444
+ def probe_account_token(config: AccountConfig, identity: dict | None = None) -> str:
445
445
  """Classify the stored account token: valid / expired / unreachable.
446
446
 
447
447
  Same pattern as the per-agent ``_probe_token_statuses`` — a cheap
448
448
  authenticated GET; 2xx → valid, 401 → expired, anything else → unreachable.
449
+
450
+ When ``identity`` is given and the probe answers 2xx with an
451
+ ``account: {email}`` object, the email is stored in it under ``"email"``.
452
+ Core's ``/cli/account/agents`` listing does not carry one today, so this is
453
+ read only when present and never makes the probe fail.
449
454
  """
450
455
  platform_url = config.platform_url.rstrip("/")
451
456
  if not platform_url or not config.account_token:
@@ -462,10 +467,40 @@ def probe_account_token(config: AccountConfig) -> str:
462
467
  if response.status_code == 401:
463
468
  return "expired"
464
469
  if 200 <= response.status_code < 300:
470
+ if identity is not None:
471
+ email = _probe_account_email(response)
472
+ if email:
473
+ identity["email"] = email
465
474
  return "valid"
466
475
  return "unreachable"
467
476
 
468
477
 
478
+ def _probe_account_email(response) -> str | None:
479
+ """The ``account.email`` of a probe response body, or None — any shape
480
+ that is not a JSON object with a non-empty string there yields None."""
481
+ try:
482
+ body = response.json()
483
+ except Exception:
484
+ return None
485
+ account = body.get("account") if isinstance(body, dict) else None
486
+ email = account.get("email") if isinstance(account, dict) else None
487
+ return email if isinstance(email, str) and email.strip() else None
488
+
489
+
490
+ def _account_identity(token: str | None, email: str | None = None) -> dict | None:
491
+ """The ``account`` object of ``account status --json``: the token's
492
+ ``owner_id`` claim (a local, unverified read — present even when the token
493
+ is expired or the platform is unreachable) plus the probe's email when it
494
+ returned one. None when the token carries no readable ``owner_id``."""
495
+ owner_id = _token_owner_id(token)
496
+ if not owner_id:
497
+ return None
498
+ identity = {"id": owner_id}
499
+ if email:
500
+ identity["email"] = email
501
+ return identity
502
+
503
+
469
504
  # ── Browser re-auth (device authorization flow) ─────────────────────────────
470
505
  #
471
506
  # `cinna login` refreshes the account token in place without a pasted setup
@@ -1068,9 +1103,12 @@ def _account_result_fields(
1068
1103
  def _jwt_claims(token: str) -> dict | None:
1069
1104
  """Best-effort, *unverified* decode of a JWT's payload segment.
1070
1105
 
1071
- Used only to compare the ``sub`` of the stored and the freshly exchanged
1072
- account token — the CLI never trusts these claims for anything else, and
1073
- a token that is not a JWT simply yields ``None`` (no comparison).
1106
+ Used only to read the ``owner_id`` claim (the owning user's id): to compare
1107
+ the stored and the freshly exchanged account token, and to name the account
1108
+ in ``account status --json``. Never ``sub`` — core puts the CLI token row id
1109
+ there, a fresh one per mint, so it names a token, not an account. The CLI
1110
+ never trusts these claims for anything else, and a token that is not a JWT
1111
+ simply yields ``None`` (no comparison, no account id).
1074
1112
  """
1075
1113
  import base64
1076
1114
 
@@ -1085,6 +1123,14 @@ def _jwt_claims(token: str) -> dict | None:
1085
1123
  return data if isinstance(data, dict) else None
1086
1124
 
1087
1125
 
1126
+ def _token_owner_id(token: str | None) -> str | None:
1127
+ """The ``owner_id`` claim of a JWT-shaped token, or None."""
1128
+ if not token:
1129
+ return None
1130
+ owner_id = (_jwt_claims(token) or {}).get("owner_id")
1131
+ return owner_id if isinstance(owner_id, str) and owner_id else None
1132
+
1133
+
1088
1134
  def _same_origin(a: str, b: str) -> bool:
1089
1135
  pa, pb = urlparse(a.strip()), urlparse(b.strip())
1090
1136
  return (pa.scheme, pa.netloc.lower()) == (pb.scheme, pb.netloc.lower())
@@ -1100,8 +1146,9 @@ def run_account_set_token(setup_input: str) -> None:
1100
1146
  active user workspace, the machine name, ``context/`` and the children
1101
1147
  under ``agents/`` are untouched — the same in-place contract ``cinna
1102
1148
  login`` gives. Refuses to write when the new token is for a different
1103
- account (platform origin differs, or both tokens carry a ``sub`` claim
1104
- and they differ) — exit 11, ``account_mismatch``.
1149
+ account (platform origin differs, or both tokens carry an ``owner_id``
1150
+ claim and they differ) — exit 11, ``account_mismatch``. ``sub`` is not
1151
+ compared: core mints a new token row, and so a new ``sub``, every time.
1105
1152
  """
1106
1153
  total = 2
1107
1154
  account_root = find_account_root()
@@ -1127,9 +1174,9 @@ def run_account_set_token(setup_input: str) -> None:
1127
1174
  f"workspace ({account_cfg.platform_url}). Run 'cinna account setup' "
1128
1175
  f"in a new directory to connect it."
1129
1176
  )
1130
- old_sub = (_jwt_claims(account_cfg.account_token) or {}).get("sub")
1131
- new_sub = (_jwt_claims(payload["account_token"]) or {}).get("sub")
1132
- if old_sub and new_sub and old_sub != new_sub:
1177
+ old_owner = _token_owner_id(account_cfg.account_token)
1178
+ new_owner = _token_owner_id(payload["account_token"])
1179
+ if old_owner and new_owner and old_owner != new_owner:
1133
1180
  raise AccountMismatchError(
1134
1181
  "Token belongs to a different account than this workspace. "
1135
1182
  "Run 'cinna account setup' in a new directory to connect it."
@@ -1356,19 +1403,24 @@ def run_account_status() -> None:
1356
1403
  account_root = find_account_root()
1357
1404
  account_cfg = load_account_config(account_root)
1358
1405
 
1406
+ probed: dict = {}
1359
1407
  with console.spinner("Checking token..."):
1360
- token_status = probe_account_token(account_cfg)
1408
+ token_status = probe_account_token(account_cfg, identity=probed)
1409
+ account_identity = _account_identity(account_cfg.account_token, probed.get("email"))
1361
1410
 
1362
1411
  children = list_child_workspaces(account_root)
1363
1412
  pkg_state, pkg_local, pkg_remote = context_package_status(account_cfg, account_root)
1364
1413
  cli_status = cli_version_status(account_cfg.platform_url)
1365
1414
 
1366
1415
  if console.json_mode:
1416
+ # ``account`` is omitted, never null, when the token names no owner.
1417
+ identity_field = {"account": account_identity} if account_identity else {}
1367
1418
  console.emit_result(
1368
1419
  workspace=str(account_root),
1369
1420
  platform_url=account_cfg.platform_url,
1370
1421
  frontend_url=account_cfg.frontend_url,
1371
1422
  machine_name=account_cfg.machine_name,
1423
+ **identity_field,
1372
1424
  active_workspace=(
1373
1425
  {
1374
1426
  "id": account_cfg.user_workspace_id,
@@ -1403,6 +1455,8 @@ def run_account_status() -> None:
1403
1455
  table.add_row("Platform", account_cfg.platform_url)
1404
1456
  table.add_row("Frontend", account_cfg.frontend_url)
1405
1457
  table.add_row("Machine", account_cfg.machine_name)
1458
+ if account_identity:
1459
+ table.add_row("Account", account_identity.get("email") or account_identity["id"])
1406
1460
  table.add_row("Account root", str(account_root))
1407
1461
  if account_cfg.user_workspace_id:
1408
1462
  ws_label = account_cfg.user_workspace_name or account_cfg.user_workspace_id
@@ -377,8 +377,9 @@ def account_status():
377
377
  """Show account workspace info and account token validity.
378
378
 
379
379
  With ``--json`` the summary is a single ``{"result": "ok", …}`` line
380
- (platform / frontend URLs, machine name, token state, synced agents,
381
- context-package and cinna-cli version freshness).
380
+ (platform / frontend URLs, machine name, the owning ``account`` id read from
381
+ the token, token state, synced agents, context-package and cinna-cli version
382
+ freshness).
382
383
  """
383
384
  from cinna.account import run_account_status
384
385
 
@@ -9,6 +9,7 @@ account workspace in place. These tests pin that contract.
9
9
  import base64
10
10
  import json
11
11
  import stat
12
+ import uuid
12
13
  from pathlib import Path
13
14
  from unittest.mock import patch
14
15
 
@@ -38,13 +39,29 @@ SETUP_URL = "https://platform.example.com/api/cli-setup/account/TOK"
38
39
  SETUP_COMMAND = f"curl -sL {SETUP_URL} | python3 -"
39
40
 
40
41
 
41
- def _jwt(sub: str) -> str:
42
- """An unsigned JWT-shaped token carrying ``sub`` (never verified)."""
42
+ def _b64(obj) -> str:
43
+ return base64.urlsafe_b64encode(json.dumps(obj).encode()).decode().rstrip("=")
43
44
 
44
- def b64(obj):
45
- return base64.urlsafe_b64encode(json.dumps(obj).encode()).decode().rstrip("=")
46
45
 
47
- return f"{b64({'alg': 'none'})}.{b64({'sub': sub, 'token_type': 'cli-account'})}.sig"
46
+ def _jwt(owner_id: str, sub: str | None = None) -> str:
47
+ """An unsigned, core-shaped account JWT (never verified).
48
+
49
+ Like core's ``create_cli_jwt``: ``owner_id`` is the user, ``sub`` is the
50
+ CLI token row id — a fresh uuid per mint unless the test pins one.
51
+ """
52
+ claims = {
53
+ "sub": sub or str(uuid.uuid4()),
54
+ "agent_id": None,
55
+ "owner_id": owner_id,
56
+ "token_type": "cli-account",
57
+ "exp": 4102444800,
58
+ }
59
+ return f"{_b64({'alg': 'none'})}.{_b64(claims)}.sig"
60
+
61
+
62
+ def _jwt_without_owner(sub: str) -> str:
63
+ """A JWT carrying only ``sub`` — no readable account owner."""
64
+ return f"{_b64({'alg': 'none'})}.{_b64({'sub': sub, 'token_type': 'cli-account'})}.sig"
48
65
 
49
66
 
50
67
  def _payload(**overrides) -> dict:
@@ -293,10 +310,11 @@ def test_account_set_token_swaps_token_in_place(
293
310
  child = account_root / "agents" / "crm"
294
311
  (child / ".cinna").mkdir(parents=True)
295
312
  (child / ".cinna" / "config.json").write_text('{"cli_token": "child"}')
313
+ fresh = _jwt("user-1") # same owner, new token row (new sub), as core mints
296
314
  mock_post.return_value = httpx.Response(
297
315
  200,
298
316
  json=_payload(
299
- account_token=_jwt("user-1") + "new",
317
+ account_token=fresh,
300
318
  frontend_url="https://ui2.example.com",
301
319
  machine_name="laptop",
302
320
  ),
@@ -311,7 +329,7 @@ def test_account_set_token_swaps_token_in_place(
311
329
  assert mock_post.call_args[0][0] == SETUP_URL
312
330
 
313
331
  cfg = load_account_config(account_root)
314
- assert cfg.account_token == _jwt("user-1") + "new"
332
+ assert cfg.account_token == fresh
315
333
  assert cfg.frontend_url == "https://ui2.example.com"
316
334
  assert cfg.platform_url == account_cfg.platform_url
317
335
  assert cfg.machine_name == "laptop"
@@ -355,17 +373,68 @@ def test_account_set_token_platform_mismatch_exits_11(
355
373
 
356
374
 
357
375
  @patch("cinna.account.httpx.post")
358
- def test_account_set_token_subject_mismatch_exits_11(
376
+ def test_account_set_token_same_owner_new_sub_succeeds(
377
+ mock_post, runner, account_root, account_cfg, monkeypatch
378
+ ):
379
+ """Core mints a new token row, so a new ``sub``, on every exchange; the
380
+ owner is what names the account. A refresh must not read as a mismatch."""
381
+ account_cfg.account_token = _jwt("user-1", sub="token-row-1")
382
+ save_account_config(account_cfg, account_root)
383
+ monkeypatch.chdir(account_root)
384
+ fresh = _jwt("user-1", sub="token-row-2")
385
+ mock_post.return_value = httpx.Response(200, json=_payload(account_token=fresh))
386
+ result = runner.invoke(cli, ["account", "set-token", SETUP_COMMAND, "--json"])
387
+ assert result.exit_code == 0, result.output
388
+ assert _json_lines(result)[-1]["result"] == "ok"
389
+ assert load_account_config(account_root).account_token == fresh
390
+
391
+
392
+ @patch("cinna.account.httpx.post")
393
+ def test_account_set_token_owner_mismatch_exits_11(
359
394
  mock_post, runner, account_root, account_cfg, monkeypatch
360
395
  ):
361
396
  monkeypatch.chdir(account_root)
362
397
  mock_post.return_value = httpx.Response(200, json=_payload(account_token=_jwt("user-2")))
398
+ result = runner.invoke(cli, ["account", "set-token", SETUP_COMMAND, "--json"])
399
+ assert result.exit_code == EXIT_ACCOUNT_MISMATCH
400
+ final = _json_lines(result)[-1]
401
+ assert final["code"] == "account_mismatch"
402
+ assert "different account" in final["detail"]
403
+ assert load_account_config(account_root).account_token == account_cfg.account_token
404
+
405
+
406
+ @patch("cinna.account.httpx.post")
407
+ def test_account_set_token_owner_mismatch_same_sub_exits_11(
408
+ mock_post, runner, account_root, account_cfg, monkeypatch
409
+ ):
410
+ """A matching ``sub`` does not vouch for the account; ``owner_id`` decides."""
411
+ account_cfg.account_token = _jwt("user-1", sub="token-row-1")
412
+ save_account_config(account_cfg, account_root)
413
+ monkeypatch.chdir(account_root)
414
+ mock_post.return_value = httpx.Response(
415
+ 200, json=_payload(account_token=_jwt("user-2", sub="token-row-1"))
416
+ )
363
417
  result = runner.invoke(cli, ["account", "set-token", SETUP_COMMAND])
364
418
  assert result.exit_code == EXIT_ACCOUNT_MISMATCH
365
- assert "different account" in result.output
366
419
  assert load_account_config(account_root).account_token == account_cfg.account_token
367
420
 
368
421
 
422
+ @patch("cinna.account.httpx.post")
423
+ def test_account_set_token_missing_owner_skips_account_check(
424
+ mock_post, runner, account_root, account_cfg, monkeypatch
425
+ ):
426
+ """A stored token without ``owner_id`` (different ``sub`` too) leaves only
427
+ the origin check; the refresh goes through."""
428
+ account_cfg.account_token = _jwt_without_owner("token-row-1")
429
+ save_account_config(account_cfg, account_root)
430
+ monkeypatch.chdir(account_root)
431
+ fresh = _jwt("user-2", sub="token-row-2")
432
+ mock_post.return_value = httpx.Response(200, json=_payload(account_token=fresh))
433
+ result = runner.invoke(cli, ["account", "set-token", SETUP_COMMAND])
434
+ assert result.exit_code == 0, result.output
435
+ assert load_account_config(account_root).account_token == fresh
436
+
437
+
369
438
  @patch("cinna.account.httpx.post")
370
439
  def test_account_set_token_opaque_tokens_skip_subject_check(
371
440
  mock_post, runner, account_root, account_cfg, monkeypatch
@@ -649,6 +718,7 @@ def test_status_json(_probe, _pkg, mock_cli, runner, account_root, monkeypatch):
649
718
  "platform_url": "https://platform.example.com",
650
719
  "frontend_url": "https://ui.example.com",
651
720
  "machine_name": "laptop",
721
+ "account": {"id": "user-1"},
652
722
  "active_workspace": {"id": "ws-1", "name": "Sales"},
653
723
  "token": "valid",
654
724
  "synced_agents": 1,
@@ -680,11 +750,136 @@ def test_status_json_expired_token_is_still_ok_result(
680
750
  assert result.exit_code == 0, result.output
681
751
  final = _json_lines(result)[-1]
682
752
  assert final["token"] == "expired"
753
+ assert final["account"] == {"id": "user-1"}
683
754
  assert final["active_workspace"] is None
684
755
  assert final["synced_agents"] == 0
685
756
  assert final["cli"]["state"] == "unknown"
686
757
 
687
758
 
759
+ class _ProbeResponse:
760
+ def __init__(self, status_code: int, body=None):
761
+ self.status_code = status_code
762
+ self._body = body
763
+
764
+ def json(self):
765
+ if self._body is None:
766
+ raise ValueError("no body")
767
+ return self._body
768
+
769
+
770
+ @pytest.fixture
771
+ def offline_status_extras():
772
+ """The status command's other platform reads, stubbed so only the token
773
+ probe (driven through ``httpx.get``) decides the outcome."""
774
+ with patch(
775
+ "cinna.account.context_package_status", return_value=("unreachable", None, None)
776
+ ), patch(
777
+ "cinna.account.cli_version_status",
778
+ return_value={"installed": "0.4.0", "required": None, "state": "unknown"},
779
+ ):
780
+ yield
781
+
782
+
783
+ def _status_json(runner, account_root, monkeypatch, probe) -> dict:
784
+ monkeypatch.setattr(httpx, "get", probe)
785
+ monkeypatch.chdir(account_root)
786
+ result = runner.invoke(cli, ["account", "status", "--json"])
787
+ assert result.exit_code == 0, result.output
788
+ lines = _json_lines(result)
789
+ assert len(lines) == 1
790
+ return lines[0]
791
+
792
+
793
+ def test_status_json_account_id_with_valid_token(
794
+ runner, account_root, monkeypatch, offline_status_extras
795
+ ):
796
+ """Core's listing carries no email: the account is named by id alone."""
797
+ final = _status_json(
798
+ runner, account_root, monkeypatch,
799
+ lambda *a, **k: _ProbeResponse(200, {"data": [], "count": 0}),
800
+ )
801
+ assert final["token"] == "valid"
802
+ assert final["account"] == {"id": "user-1"}
803
+
804
+
805
+ def test_status_json_account_email_when_server_returns_it(
806
+ runner, account_root, monkeypatch, offline_status_extras
807
+ ):
808
+ final = _status_json(
809
+ runner, account_root, monkeypatch,
810
+ lambda *a, **k: _ProbeResponse(
811
+ 200, {"data": [], "count": 0, "account": {"email": "builder@example.com"}}
812
+ ),
813
+ )
814
+ assert final["account"] == {"id": "user-1", "email": "builder@example.com"}
815
+
816
+
817
+ @pytest.mark.parametrize(
818
+ "body", [None, ["not", "an", "object"], {"account": {"email": None}}, {"account": "x"}]
819
+ )
820
+ def test_status_json_unreadable_email_is_omitted(
821
+ body, runner, account_root, monkeypatch, offline_status_extras
822
+ ):
823
+ final = _status_json(
824
+ runner, account_root, monkeypatch, lambda *a, **k: _ProbeResponse(200, body)
825
+ )
826
+ assert final["token"] == "valid"
827
+ assert final["account"] == {"id": "user-1"}
828
+
829
+
830
+ def test_status_json_account_id_with_expired_token(
831
+ runner, account_root, monkeypatch, offline_status_extras
832
+ ):
833
+ """A 401 never yields an email, even if the body had one; the id stays."""
834
+ final = _status_json(
835
+ runner, account_root, monkeypatch,
836
+ lambda *a, **k: _ProbeResponse(401, {"account": {"email": "builder@example.com"}}),
837
+ )
838
+ assert final["token"] == "expired"
839
+ assert final["account"] == {"id": "user-1"}
840
+
841
+
842
+ def test_status_json_account_id_when_server_unreachable(
843
+ runner, account_root, monkeypatch, offline_status_extras
844
+ ):
845
+ def offline(*a, **k):
846
+ raise httpx.ConnectError("offline")
847
+
848
+ final = _status_json(runner, account_root, monkeypatch, offline)
849
+ assert final["token"] == "unreachable"
850
+ assert final["account"] == {"id": "user-1"}
851
+
852
+
853
+ @pytest.mark.parametrize("token", ["opaque-account-token", None])
854
+ def test_status_json_no_account_key_without_owner_id(
855
+ token, runner, account_root, account_cfg, monkeypatch, offline_status_extras
856
+ ):
857
+ account_cfg.account_token = token or _jwt_without_owner("token-row-1")
858
+ save_account_config(account_cfg, account_root)
859
+ final = _status_json(
860
+ runner, account_root, monkeypatch,
861
+ lambda *a, **k: _ProbeResponse(
862
+ 200, {"account": {"email": "builder@example.com"}}
863
+ ),
864
+ )
865
+ assert final["token"] == "valid"
866
+ assert "account" not in final
867
+
868
+
869
+ def test_status_human_names_the_account(
870
+ runner, account_root, monkeypatch, offline_status_extras
871
+ ):
872
+ monkeypatch.setenv("COLUMNS", "200")
873
+ monkeypatch.setattr(
874
+ httpx, "get",
875
+ lambda *a, **k: _ProbeResponse(200, {"account": {"email": "builder@example.com"}}),
876
+ )
877
+ monkeypatch.chdir(account_root)
878
+ result = runner.invoke(cli, ["account", "status"])
879
+ assert result.exit_code == 0, result.output
880
+ assert "builder@example.com" in result.output
881
+
882
+
688
883
  def test_json_implies_no_input():
689
884
  console.set_json_mode(True)
690
885
  assert console.no_input is True
@@ -136,7 +136,7 @@ wheels = [
136
136
 
137
137
  [[package]]
138
138
  name = "cinna-cli"
139
- version = "0.7.0"
139
+ version = "0.7.1"
140
140
  source = { editable = "." }
141
141
  dependencies = [
142
142
  { name = "click" },
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes