mystack-rig 1.1.0__tar.gz → 1.2.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. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/GLOSSARY.md +8 -0
  2. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/PKG-INFO +28 -1
  3. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/README.md +27 -0
  4. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/docs/adr/0001-per-profile-generated-state-bucket.md +2 -0
  5. mystack_rig-1.2.1/docs/adr/0002-outputs-as-separate-object-via-file-handoff.md +16 -0
  6. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/src/cli/main.py +125 -4
  7. mystack_rig-1.2.1/src/cli/outputs.py +102 -0
  8. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/src/cli/remote_dev.py +380 -122
  9. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/src/mystack_rig.egg-info/PKG-INFO +28 -1
  10. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/src/mystack_rig.egg-info/SOURCES.txt +5 -0
  11. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/src/mystack_rig.egg-info/scm_file_list.json +5 -0
  12. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/src/mystack_rig.egg-info/scm_version.json +2 -2
  13. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_init_command.py +1 -1
  14. mystack_rig-1.2.1/tests/test_inspect_describe.py +261 -0
  15. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_main_coverage.py +21 -0
  16. mystack_rig-1.2.1/tests/test_outputs.py +209 -0
  17. mystack_rig-1.2.1/tests/test_outputs_storage.py +210 -0
  18. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_remote_dev_coverage_extensions.py +53 -11
  19. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_state_bucket.py +177 -23
  20. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/.coveragerc +0 -0
  21. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/.flake8 +0 -0
  22. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/.github/workflows/release.yml +0 -0
  23. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/.github/workflows/tests.yml +0 -0
  24. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/.gitignore +0 -0
  25. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/.rig/playbooks/README.md +0 -0
  26. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/.rig/playbooks/vpn-gateway.yml +0 -0
  27. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/CLI_STORAGE_SUMMARY.md +0 -0
  28. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/Dockerfile +0 -0
  29. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/GIT_CLONE_FEATURE.md +0 -0
  30. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/HETZNER_STORAGE_GUIDE.md +0 -0
  31. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/HETZNER_STORAGE_SECURITY_GUIDE.md +0 -0
  32. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/LICENSE +0 -0
  33. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/Makefile +0 -0
  34. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/README_REAL_E2E.md +0 -0
  35. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/STORAGE_CLI_GUIDE.md +0 -0
  36. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/docs/architecture.md +0 -0
  37. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/docs/architecture.png +0 -0
  38. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/docs/architecture.svg +0 -0
  39. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/forged-idea.md +0 -0
  40. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/pyproject.toml +0 -0
  41. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/pytest.ini +0 -0
  42. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/requirements.txt +0 -0
  43. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/sample.env +0 -0
  44. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/scripts/coverage_badge.py +0 -0
  45. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/scripts/pypi_version.py +0 -0
  46. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/setup.cfg +0 -0
  47. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/src/__init__.py +0 -0
  48. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/src/cli/__init__.py +0 -0
  49. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/src/cli/__main__.py +0 -0
  50. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/src/cli/agents.py +0 -0
  51. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/src/cli/config.py +0 -0
  52. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/src/cli/encrypt.py +0 -0
  53. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/src/cli/git.py +0 -0
  54. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/src/cli/last_env.py +0 -0
  55. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/src/cli/last_session.py +0 -0
  56. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/src/cli/log.py +0 -0
  57. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/src/cli/requirements.txt +0 -0
  58. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/src/cli/snapshots.py +0 -0
  59. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/src/cli/state_bucket.py +0 -0
  60. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/src/cli/storage.py +0 -0
  61. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/src/cli/vault_keys.py +0 -0
  62. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/src/cli/vpn.py +0 -0
  63. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/src/mystack_rig.egg-info/dependency_links.txt +0 -0
  64. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/src/mystack_rig.egg-info/entry_points.txt +0 -0
  65. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/src/mystack_rig.egg-info/requires.txt +0 -0
  66. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/src/mystack_rig.egg-info/top_level.txt +0 -0
  67. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/test_hetzner_integration.py +0 -0
  68. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/conftest.py +0 -0
  69. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_agents.py +0 -0
  70. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_ansible_galaxy.py +0 -0
  71. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_attach_command.py +0 -0
  72. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_credential_security.py +0 -0
  73. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_destroy_command.py +0 -0
  74. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_dev_command.py +0 -0
  75. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_encrypt_command.py +0 -0
  76. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_encrypt_coverage.py +0 -0
  77. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_firewall_client_ip.py +0 -0
  78. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_git_clone_unit.py +0 -0
  79. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_git_manager.py +0 -0
  80. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_gitignore_init.py +0 -0
  81. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_hetzner_storage.py +0 -0
  82. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_last_env.py +0 -0
  83. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_last_session.py +0 -0
  84. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_log.py +0 -0
  85. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_pypi_version.py +0 -0
  86. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_real_e2e_integration.py +0 -0
  87. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_real_e2e_storage.py +0 -0
  88. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_real_e2e_vpn.py +0 -0
  89. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_real_e2e_vpn_tunnel.py +0 -0
  90. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_remote_dev.py +0 -0
  91. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_rig_ansible_vars.py +0 -0
  92. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_rig_config.py +0 -0
  93. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_setup_provision.py +0 -0
  94. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_simulation_storage.py +0 -0
  95. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_small_module_coverage.py +0 -0
  96. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_snapshots.py +0 -0
  97. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_storage_basic.py +0 -0
  98. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_vault_keys.py +0 -0
  99. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_vpn_optional.py +0 -0
  100. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_vpn_unit.py +0 -0
  101. {mystack_rig-1.1.0 → mystack_rig-1.2.1}/tests/test_workspace_git_clone.py +0 -0
@@ -16,6 +16,14 @@ _Avoid_: Production bucket, installation bucket
16
16
  A project repository containing a `.rig/` directory, which owns its own State buckets.
17
17
  _Avoid_: Project (ambiguous with a Hetzner Cloud project)
18
18
 
19
+ **Environment**:
20
+ A remote development machine provisioned by rig, owned by one identity and tracked in a State bucket.
21
+ _Avoid_: Instance, VM, server
22
+
23
+ **Outputs**:
24
+ The named values that an Environment's playbooks publish for the user (URLs, ports, credentials), kept alongside the Environment and shown by `rig describe`.
25
+ _Avoid_: Facts, results
26
+
19
27
  **Test bucket**:
20
28
  A throwaway state bucket used only by automated test runs.
21
29
  _Avoid_: Dev bucket
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mystack-rig
3
- Version: 1.1.0
3
+ Version: 1.2.1
4
4
  Summary: Ephemeral remotes with full local parity for coding agents
5
5
  Author: mystack-cloud
6
6
  License-Expression: MIT
@@ -227,6 +227,8 @@ Global: `-v` playbook tasks and debug · `-vv`/`-vvv`/`-vvvv` ansible verbosity
227
227
  | `ssh` | `[name]` `[-- command]` | Shell on the VM in `/workspace`. A command after `--` runs instead of a login shell |
228
228
  | `dev` | `[name]` `[--path /workspace]` `[--browser]` `[--editor code\|cursor\|…]` | Remote-SSH by default; `--editor` opens another IDE from `editor.enabled`. Defaults to `editor.default` |
229
229
  | `list` | | Lists envs, or `No remote environments` |
230
+ | `inspect` | `[name]` `[--json]` | Technical details of one env: stored record plus live Hetzner status. Falls back to stored data (flagged stale) if the API is unreachable. Data goes to stdout |
231
+ | `describe` | `[name]` `[--json]` `[--show-secrets]` | Outputs published by the env's playbooks (see below). Sensitive values are masked unless `--show-secrets` |
230
232
  | `delete` | `[name …]` `[--tags TAGS]` | Runs finalize then destroy playbooks, then deletes the VM; multi-name OK. `--tags` limits both playbooks |
231
233
  | `cache` | `list\|clear` `[--system\|--workspace] [--all] [-y]` | List or clear; unused by default, `--all` includes current |
232
234
  | `vars encrypt` | `[--stdin-name VAR]` `[--personal]` | Vault into shared or identity vars (after master-key unlock) |
@@ -265,6 +267,31 @@ Also available from vars files (defaults): `workspace_root`, `coding_agent_type`
265
267
 
266
268
  `vscode_browser_password` is auto-generated (vaulted) for code-server browser login (`rig dev --browser`). Reveal with `rig vars decrypt vscode_browser_password` (also printed when opening browser mode).
267
269
 
270
+ ## Playbook outputs
271
+
272
+ `rig describe` shows the values your playbooks publish. A playbook publishes them by writing YAML to the path in the `rig_outputs_file` extra var, which rig sets on every run. Add a task like this to any playbook, including custom ones:
273
+
274
+ ```yaml
275
+ - name: Publish outputs
276
+ delegate_to: localhost
277
+ become: false
278
+ ansible.builtin.copy:
279
+ dest: "{{ rig_outputs_file }}"
280
+ content: "{{ {'rig_outputs': rig_outputs, 'rig_outputs_sensitive': ['my_api_key']} | to_nice_yaml }}"
281
+ vars:
282
+ rig_outputs:
283
+ vscode_url: "https://{{ rig_vm_ip }}:8443"
284
+ my_api_key: "{{ some_secret }}"
285
+ ```
286
+
287
+ - `rig_outputs` (required) is a dict of name to value. Without it the file is ignored.
288
+ - `rig_outputs_sensitive` (optional) lists extra keys to mask. Keys containing `password`, `secret`, `token` or `key` are always masked.
289
+ - After each successful create-side stage (`provision`, `configure`, `authorize`, `materialize`, `finalize`) rig shallow-merges the file into the stored outputs, so later runs overwrite only the keys they emit. Failed runs and `destroy` store nothing.
290
+ - Outputs are stored as written in the State bucket at `remote-dev/outputs/<name>.yml`, readable by anyone with bucket credentials. Masking is a display default, not access control. `rig delete` removes them.
291
+ - Environment names are unique across owners in a State bucket, and `create` rejects a name another owner already uses.
292
+
293
+ See `docs/adr/0002-outputs-as-separate-object-via-file-handoff.md`.
294
+
268
295
  ## Credentials
269
296
 
270
297
  | Source | Purpose |
@@ -204,6 +204,8 @@ Global: `-v` playbook tasks and debug · `-vv`/`-vvv`/`-vvvv` ansible verbosity
204
204
  | `ssh` | `[name]` `[-- command]` | Shell on the VM in `/workspace`. A command after `--` runs instead of a login shell |
205
205
  | `dev` | `[name]` `[--path /workspace]` `[--browser]` `[--editor code\|cursor\|…]` | Remote-SSH by default; `--editor` opens another IDE from `editor.enabled`. Defaults to `editor.default` |
206
206
  | `list` | | Lists envs, or `No remote environments` |
207
+ | `inspect` | `[name]` `[--json]` | Technical details of one env: stored record plus live Hetzner status. Falls back to stored data (flagged stale) if the API is unreachable. Data goes to stdout |
208
+ | `describe` | `[name]` `[--json]` `[--show-secrets]` | Outputs published by the env's playbooks (see below). Sensitive values are masked unless `--show-secrets` |
207
209
  | `delete` | `[name …]` `[--tags TAGS]` | Runs finalize then destroy playbooks, then deletes the VM; multi-name OK. `--tags` limits both playbooks |
208
210
  | `cache` | `list\|clear` `[--system\|--workspace] [--all] [-y]` | List or clear; unused by default, `--all` includes current |
209
211
  | `vars encrypt` | `[--stdin-name VAR]` `[--personal]` | Vault into shared or identity vars (after master-key unlock) |
@@ -242,6 +244,31 @@ Also available from vars files (defaults): `workspace_root`, `coding_agent_type`
242
244
 
243
245
  `vscode_browser_password` is auto-generated (vaulted) for code-server browser login (`rig dev --browser`). Reveal with `rig vars decrypt vscode_browser_password` (also printed when opening browser mode).
244
246
 
247
+ ## Playbook outputs
248
+
249
+ `rig describe` shows the values your playbooks publish. A playbook publishes them by writing YAML to the path in the `rig_outputs_file` extra var, which rig sets on every run. Add a task like this to any playbook, including custom ones:
250
+
251
+ ```yaml
252
+ - name: Publish outputs
253
+ delegate_to: localhost
254
+ become: false
255
+ ansible.builtin.copy:
256
+ dest: "{{ rig_outputs_file }}"
257
+ content: "{{ {'rig_outputs': rig_outputs, 'rig_outputs_sensitive': ['my_api_key']} | to_nice_yaml }}"
258
+ vars:
259
+ rig_outputs:
260
+ vscode_url: "https://{{ rig_vm_ip }}:8443"
261
+ my_api_key: "{{ some_secret }}"
262
+ ```
263
+
264
+ - `rig_outputs` (required) is a dict of name to value. Without it the file is ignored.
265
+ - `rig_outputs_sensitive` (optional) lists extra keys to mask. Keys containing `password`, `secret`, `token` or `key` are always masked.
266
+ - After each successful create-side stage (`provision`, `configure`, `authorize`, `materialize`, `finalize`) rig shallow-merges the file into the stored outputs, so later runs overwrite only the keys they emit. Failed runs and `destroy` store nothing.
267
+ - Outputs are stored as written in the State bucket at `remote-dev/outputs/<name>.yml`, readable by anyone with bucket credentials. Masking is a display default, not access control. `rig delete` removes them.
268
+ - Environment names are unique across owners in a State bucket, and `create` rejects a name another owner already uses.
269
+
270
+ See `docs/adr/0002-outputs-as-separate-object-via-file-handoff.md`.
271
+
245
272
  ## Credentials
246
273
 
247
274
  | Source | Purpose |
@@ -19,3 +19,5 @@ The fixed default bucket name `rig` collided with other Hetzner customers, becau
19
19
  - Generating a name edits `vars.yml`, so init prints a reminder to commit it.
20
20
  - There is no migration from the legacy `rig` bucket. Existing environments there must be cleaned up manually.
21
21
  - Test mode (`is_test`) uses its own Test bucket and never reads or writes `vars.yml` or `~/.rig/config`.
22
+ - The bucket is shared by every Identity using the Profile, but visibility is per Identity. Each environment record stores an `owner` (the Identity that created it). `rig list` shows only the caller's environments; `rig list --all` shows everyone's, labelled with the owner. Records without an `owner` (created before this) appear only under `--all`. This is a visibility default, not access control: anyone with the bucket credentials can read all records.
23
+ - Environment records are one object each, at `remote-dev/environments/by-owner/<owner>/<name>.yml`. A save or destroy touches only that key, so concurrent runs by different Identities cannot overwrite each other (the earlier single `state.yml` index was read-merge-overwrite and could lose entries). The legacy `state.yml` index is still read, never written except to remove an entry on destroy.
@@ -0,0 +1,16 @@
1
+ # Outputs are a separate per-name object, handed off from Ansible via a file
2
+
3
+ `rig describe` shows the Outputs that an Environment's playbooks publish. Playbooks write a `rig_outputs` dict to a controller-side file whose path rig passes as `rig_outputs_file`. After each successful non-destroy stage rig shallow-merges that file into the stored Outputs. The Outputs are stored as one object per Environment name at `remote-dev/outputs/<name>.yml` in the State bucket, separate from the Environment record.
4
+
5
+ ## Considered Options
6
+
7
+ - **Parse Ansible stdout or a JSON callback**: rejected. Rig only gets a bool from `ansible-playbook` today, and parsing output is fragile and ties rig to a callback plugin.
8
+ - **Store Outputs inside the Environment record**: rejected. `_save_state` merges and rewrites the whole record on every update, and `list` scans the records prefix, so a growing and sensitive blob there raises the cost of every save and list.
9
+ - **Key Outputs by owner like records**: rejected. Outputs are a property of the Environment, so `describe <name>` returns one result for everyone in the Workspace and Profile.
10
+
11
+ ## Consequences
12
+
13
+ - Playbook authors must opt in by writing `rig_outputs_file`. Rig's default playbooks ship a snippet that does this, and custom playbooks follow the documented convention.
14
+ - Environment names must be unique across owners within a State bucket, so `create` rejects a name that already exists under any owner.
15
+ - Outputs are stored as written. The bucket is shared by the whole team, so sensitive values are readable by anyone with bucket credentials. `describe` masks them by default (keys matching `password`, `secret`, `token` or `key`, or listed in `rig_outputs_sensitive`). Encrypting them with the vault shared key is a follow-up.
16
+ - `rig delete` removes the Outputs object together with the Environment record. A failed playbook writes nothing, and the destroy stage captures nothing.
@@ -4,6 +4,7 @@ Main entry point for the remote development environment CLI
4
4
  """
5
5
 
6
6
  import argparse
7
+ import json
7
8
  import sys
8
9
  import os
9
10
  from typing import List, Optional
@@ -347,6 +348,93 @@ def _cmd_ssh(args: argparse.Namespace) -> int:
347
348
  return 1
348
349
 
349
350
 
351
+ def _env_for_readonly_cmd(args: argparse.Namespace, usage: str, need_storage: bool = False):
352
+ """Shared setup for inspect/describe.
353
+
354
+ Returns ``(env, name)`` on success, or ``(None, exit_code)``.
355
+ """
356
+ _load_credentials()
357
+ if not os.getenv('HETZNER_CLOUD_API_TOKEN'):
358
+ log.error("Hetzner credentials missing. Run 'rig init' or set HETZNER_CLOUD_API_TOKEN")
359
+ return None, 1
360
+ name = resolve_env_name(getattr(args, "name", None), getattr(args, "name_flag", None))
361
+ if not name:
362
+ log.error("Environment name is required (no last environment remembered)")
363
+ log.info("Usage: %s", usage)
364
+ return None, 1
365
+ storage_manager = None
366
+ try:
367
+ storage_manager = StorageManager()
368
+ except ValueError:
369
+ if need_storage:
370
+ log.error("Object storage credentials are missing; cannot read environment state")
371
+ return None, 1
372
+ return RemoteDevEnvironment(name=name, storage_manager=storage_manager), name
373
+
374
+
375
+ def _cmd_inspect(args: argparse.Namespace) -> int:
376
+ """Print the technical details of one environment."""
377
+ from cli.outputs import format_kv
378
+ env, name = _env_for_readonly_cmd(args, "rig inspect [name] [--json]")
379
+ if env is None:
380
+ return name
381
+ try:
382
+ details = env.inspect_details()
383
+ if details is None:
384
+ log.error("Environment '%s' not found", name)
385
+ return 1
386
+ remember_last_env(name)
387
+ if details.get("stale"):
388
+ log.warning("Live server data unavailable; showing stored data (stale)")
389
+ if getattr(args, "json", False):
390
+ print(json.dumps(details, indent=2, default=str))
391
+ else:
392
+ print(format_kv(details))
393
+ return 0
394
+ except Exception as e:
395
+ log.error("Error inspecting environment: %s", e)
396
+ return 1
397
+
398
+
399
+ def _cmd_describe(args: argparse.Namespace) -> int:
400
+ """Print the outputs published by an environment's playbooks."""
401
+ from cli.outputs import (
402
+ OUTPUTS_KEY,
403
+ SENSITIVE_KEY,
404
+ format_kv,
405
+ mask_outputs,
406
+ )
407
+ env, name = _env_for_readonly_cmd(
408
+ args, "rig describe [name] [--json] [--show-secrets]", need_storage=True
409
+ )
410
+ if env is None:
411
+ return name
412
+ try:
413
+ if not env.exists():
414
+ log.error("Environment '%s' not found", name)
415
+ return 1
416
+ remember_last_env(name)
417
+ stored = env.stored_outputs() or {}
418
+ outputs = stored.get(OUTPUTS_KEY) or {}
419
+ use_json = bool(getattr(args, "json", False))
420
+ if not outputs:
421
+ if use_json:
422
+ print("{}")
423
+ else:
424
+ log.info("No outputs recorded for %s", name)
425
+ return 0
426
+ shown = mask_outputs(
427
+ outputs,
428
+ sensitive=stored.get(SENSITIVE_KEY) or [],
429
+ show_secrets=bool(getattr(args, "show_secrets", False)),
430
+ )
431
+ print(json.dumps(shown, indent=2, default=str) if use_json else format_kv(shown))
432
+ return 0
433
+ except Exception as e:
434
+ log.error("Error describing environment: %s", e)
435
+ return 1
436
+
437
+
350
438
  def _cmd_apply(args: argparse.Namespace) -> int:
351
439
  """Re-run lifecycle playbooks on an existing environment."""
352
440
  _load_credentials()
@@ -518,7 +606,7 @@ def _cmd_dev(args: argparse.Namespace) -> int:
518
606
  return 1
519
607
 
520
608
 
521
- def _cmd_list(_args: argparse.Namespace) -> int:
609
+ def _cmd_list(args: argparse.Namespace) -> int:
522
610
  _load_credentials()
523
611
  hetzner_token = os.getenv('HETZNER_CLOUD_API_TOKEN')
524
612
  if not hetzner_token:
@@ -533,13 +621,15 @@ def _cmd_list(_args: argparse.Namespace) -> int:
533
621
 
534
622
  try:
535
623
  env = RemoteDevEnvironment(storage_manager=storage_manager)
536
- environments = env.list_environments()
624
+ all_ids = bool(getattr(args, "all", False))
625
+ environments = env.list_environments(all_identities=True) if all_ids else env.list_environments()
537
626
  if not environments:
538
627
  log.info("No remote environments")
539
628
  return 0
540
629
  log.info("Remote environments:")
541
630
  for env_info in environments:
542
- log.info(" - %s (%s)", env_info.get("name"), env_info.get("status"))
631
+ owner = f" [{env_info.get('owner') or 'unknown'}]" if all_ids else ""
632
+ log.info(" - %s (%s)%s", env_info.get("name"), env_info.get("status"), owner)
543
633
  return 0
544
634
  except Exception as e:
545
635
  log.error("Error listing environments: %s", e)
@@ -1121,7 +1211,34 @@ def main(argv=None):
1121
1211
  ),
1122
1212
  )
1123
1213
 
1124
- subparsers.add_parser("list", help="List remote environments")
1214
+ list_parser = subparsers.add_parser(
1215
+ "list",
1216
+ help="List your remote environments (--all: every identity's)",
1217
+ )
1218
+ list_parser.add_argument(
1219
+ "--all",
1220
+ action="store_true",
1221
+ help="Include environments owned by other identities in this workspace",
1222
+ )
1223
+
1224
+ for cmd_name, cmd_help in (
1225
+ ("inspect", "Show technical details of an environment (stored + live)"),
1226
+ ("describe", "Show the outputs published by an environment's playbooks"),
1227
+ ):
1228
+ sub = subparsers.add_parser(cmd_name, help=cmd_help)
1229
+ sub.add_argument(
1230
+ "name",
1231
+ nargs="?",
1232
+ help="Environment name (defaults to last handled env in /tmp/.rig/last-env)",
1233
+ )
1234
+ sub.add_argument("--name", dest="name_flag", help="Environment name (same as positional)")
1235
+ sub.add_argument("--json", action="store_true", help="Machine-readable JSON on stdout")
1236
+ if cmd_name == "describe":
1237
+ sub.add_argument(
1238
+ "--show-secrets",
1239
+ action="store_true",
1240
+ help="Show sensitive output values instead of masking them",
1241
+ )
1125
1242
 
1126
1243
  cache_parser = subparsers.add_parser(
1127
1244
  "cache",
@@ -1260,6 +1377,10 @@ def main(argv=None):
1260
1377
  return _cmd_dev(args)
1261
1378
  if args.command == "list":
1262
1379
  return _cmd_list(args)
1380
+ if args.command == "inspect":
1381
+ return _cmd_inspect(args)
1382
+ if args.command == "describe":
1383
+ return _cmd_describe(args)
1263
1384
  if args.command == "cache":
1264
1385
  return _cmd_cache(args)
1265
1386
  if args.command == "delete":
@@ -0,0 +1,102 @@
1
+ """Environment Outputs: parsing, merging and masking.
2
+
3
+ Playbooks publish Outputs by writing a YAML file (path given as the
4
+ ``rig_outputs_file`` extra var) shaped like::
5
+
6
+ rig_outputs: # required: dict of name -> value
7
+ url: https://...
8
+ password: ...
9
+ rig_outputs_sensitive: # optional: extra keys to mask in `rig describe`
10
+ - custom_secret
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ import copy
16
+ import re
17
+ from typing import Any, Dict, Iterable, List, Optional
18
+
19
+ import yaml
20
+
21
+ MASK = "********"
22
+ OUTPUTS_KEY = "rig_outputs"
23
+ SENSITIVE_KEY = "rig_outputs_sensitive"
24
+
25
+ _SENSITIVE_RE = re.compile(r"password|secret|token|key", re.IGNORECASE)
26
+
27
+
28
+ def is_sensitive_key(key: Any) -> bool:
29
+ return bool(_SENSITIVE_RE.search(str(key)))
30
+
31
+
32
+ def mask_outputs(
33
+ outputs: Dict[str, Any],
34
+ sensitive: Iterable[str] = (),
35
+ show_secrets: bool = False,
36
+ ) -> Dict[str, Any]:
37
+ """Return a copy of *outputs* with sensitive values replaced by MASK."""
38
+ if show_secrets:
39
+ return copy.deepcopy(outputs)
40
+ explicit = {str(s) for s in sensitive or ()}
41
+
42
+ def _walk(value: Any) -> Any:
43
+ if not isinstance(value, dict):
44
+ return copy.deepcopy(value)
45
+ result = {}
46
+ for k, v in value.items():
47
+ if str(k) in explicit or is_sensitive_key(k):
48
+ result[k] = MASK
49
+ else:
50
+ result[k] = _walk(v)
51
+ return result
52
+
53
+ return _walk(outputs)
54
+
55
+
56
+ def merge_outputs(
57
+ stored: Optional[Dict[str, Any]],
58
+ new: Dict[str, Any],
59
+ ) -> Dict[str, Any]:
60
+ """Shallow-merge *new* over *stored* (later keys win); union sensitive keys."""
61
+ stored = stored or {}
62
+ outputs: Dict[str, Any] = dict(stored.get(OUTPUTS_KEY) or {})
63
+ outputs.update(new.get(OUTPUTS_KEY) or {})
64
+ sensitive: List[str] = list(stored.get(SENSITIVE_KEY) or [])
65
+ for key in new.get(SENSITIVE_KEY) or []:
66
+ if key not in sensitive:
67
+ sensitive.append(key)
68
+ return {OUTPUTS_KEY: outputs, SENSITIVE_KEY: sensitive}
69
+
70
+
71
+ def read_outputs_file(path: str) -> Optional[Dict[str, Any]]:
72
+ """Parse a playbook-written outputs file; None if missing or malformed."""
73
+ try:
74
+ with open(path, "r", encoding="utf-8") as handle:
75
+ data = yaml.safe_load(handle)
76
+ except (OSError, yaml.YAMLError):
77
+ return None
78
+ if not isinstance(data, dict) or not isinstance(data.get(OUTPUTS_KEY), dict):
79
+ return None
80
+ sensitive = data.get(SENSITIVE_KEY)
81
+ result: Dict[str, Any] = {OUTPUTS_KEY: data[OUTPUTS_KEY]}
82
+ if isinstance(sensitive, list):
83
+ result[SENSITIVE_KEY] = [str(s) for s in sensitive]
84
+ return result
85
+
86
+
87
+ def format_kv(data: Dict[str, Any], indent: int = 0) -> str:
88
+ """Render a dict as plain ``key: value`` lines (nested dicts indented)."""
89
+ pad = " " * indent
90
+ lines: List[str] = []
91
+ for key, value in data.items():
92
+ if isinstance(value, dict):
93
+ lines.append(f"{pad}{key}:")
94
+ if value:
95
+ lines.append(format_kv(value, indent + 1))
96
+ elif isinstance(value, (list, tuple)):
97
+ lines.append(f"{pad}{key}: {', '.join(str(v) for v in value) or '-'}")
98
+ elif value is None or value == "":
99
+ lines.append(f"{pad}{key}: -")
100
+ else:
101
+ lines.append(f"{pad}{key}: {value}")
102
+ return "\n".join(lines)