mystack-rig 1.2.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.2.0 → mystack_rig-1.2.1}/GLOSSARY.md +8 -0
  2. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/PKG-INFO +28 -1
  3. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/README.md +27 -0
  4. mystack_rig-1.2.1/docs/adr/0002-outputs-as-separate-object-via-file-handoff.md +16 -0
  5. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/src/cli/main.py +111 -0
  6. mystack_rig-1.2.1/src/cli/outputs.py +102 -0
  7. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/src/cli/remote_dev.py +201 -0
  8. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/src/mystack_rig.egg-info/PKG-INFO +28 -1
  9. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/src/mystack_rig.egg-info/SOURCES.txt +5 -0
  10. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/src/mystack_rig.egg-info/scm_file_list.json +5 -0
  11. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/src/mystack_rig.egg-info/scm_version.json +2 -2
  12. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/test_init_command.py +1 -1
  13. mystack_rig-1.2.1/tests/test_inspect_describe.py +261 -0
  14. mystack_rig-1.2.1/tests/test_outputs.py +209 -0
  15. mystack_rig-1.2.1/tests/test_outputs_storage.py +210 -0
  16. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/test_remote_dev_coverage_extensions.py +1 -0
  17. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/.coveragerc +0 -0
  18. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/.flake8 +0 -0
  19. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/.github/workflows/release.yml +0 -0
  20. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/.github/workflows/tests.yml +0 -0
  21. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/.gitignore +0 -0
  22. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/.rig/playbooks/README.md +0 -0
  23. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/.rig/playbooks/vpn-gateway.yml +0 -0
  24. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/CLI_STORAGE_SUMMARY.md +0 -0
  25. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/Dockerfile +0 -0
  26. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/GIT_CLONE_FEATURE.md +0 -0
  27. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/HETZNER_STORAGE_GUIDE.md +0 -0
  28. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/HETZNER_STORAGE_SECURITY_GUIDE.md +0 -0
  29. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/LICENSE +0 -0
  30. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/Makefile +0 -0
  31. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/README_REAL_E2E.md +0 -0
  32. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/STORAGE_CLI_GUIDE.md +0 -0
  33. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/docs/adr/0001-per-profile-generated-state-bucket.md +0 -0
  34. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/docs/architecture.md +0 -0
  35. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/docs/architecture.png +0 -0
  36. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/docs/architecture.svg +0 -0
  37. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/forged-idea.md +0 -0
  38. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/pyproject.toml +0 -0
  39. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/pytest.ini +0 -0
  40. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/requirements.txt +0 -0
  41. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/sample.env +0 -0
  42. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/scripts/coverage_badge.py +0 -0
  43. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/scripts/pypi_version.py +0 -0
  44. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/setup.cfg +0 -0
  45. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/src/__init__.py +0 -0
  46. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/src/cli/__init__.py +0 -0
  47. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/src/cli/__main__.py +0 -0
  48. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/src/cli/agents.py +0 -0
  49. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/src/cli/config.py +0 -0
  50. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/src/cli/encrypt.py +0 -0
  51. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/src/cli/git.py +0 -0
  52. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/src/cli/last_env.py +0 -0
  53. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/src/cli/last_session.py +0 -0
  54. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/src/cli/log.py +0 -0
  55. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/src/cli/requirements.txt +0 -0
  56. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/src/cli/snapshots.py +0 -0
  57. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/src/cli/state_bucket.py +0 -0
  58. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/src/cli/storage.py +0 -0
  59. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/src/cli/vault_keys.py +0 -0
  60. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/src/cli/vpn.py +0 -0
  61. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/src/mystack_rig.egg-info/dependency_links.txt +0 -0
  62. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/src/mystack_rig.egg-info/entry_points.txt +0 -0
  63. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/src/mystack_rig.egg-info/requires.txt +0 -0
  64. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/src/mystack_rig.egg-info/top_level.txt +0 -0
  65. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/test_hetzner_integration.py +0 -0
  66. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/conftest.py +0 -0
  67. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/test_agents.py +0 -0
  68. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/test_ansible_galaxy.py +0 -0
  69. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/test_attach_command.py +0 -0
  70. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/test_credential_security.py +0 -0
  71. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/test_destroy_command.py +0 -0
  72. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/test_dev_command.py +0 -0
  73. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/test_encrypt_command.py +0 -0
  74. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/test_encrypt_coverage.py +0 -0
  75. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/test_firewall_client_ip.py +0 -0
  76. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/test_git_clone_unit.py +0 -0
  77. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/test_git_manager.py +0 -0
  78. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/test_gitignore_init.py +0 -0
  79. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/test_hetzner_storage.py +0 -0
  80. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/test_last_env.py +0 -0
  81. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/test_last_session.py +0 -0
  82. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/test_log.py +0 -0
  83. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/test_main_coverage.py +0 -0
  84. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/test_pypi_version.py +0 -0
  85. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/test_real_e2e_integration.py +0 -0
  86. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/test_real_e2e_storage.py +0 -0
  87. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/test_real_e2e_vpn.py +0 -0
  88. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/test_real_e2e_vpn_tunnel.py +0 -0
  89. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/test_remote_dev.py +0 -0
  90. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/test_rig_ansible_vars.py +0 -0
  91. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/test_rig_config.py +0 -0
  92. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/test_setup_provision.py +0 -0
  93. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/test_simulation_storage.py +0 -0
  94. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/test_small_module_coverage.py +0 -0
  95. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/test_snapshots.py +0 -0
  96. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/test_state_bucket.py +0 -0
  97. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/test_storage_basic.py +0 -0
  98. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/test_vault_keys.py +0 -0
  99. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/test_vpn_optional.py +0 -0
  100. {mystack_rig-1.2.0 → mystack_rig-1.2.1}/tests/test_vpn_unit.py +0 -0
  101. {mystack_rig-1.2.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.2.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 |
@@ -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()
@@ -1133,6 +1221,25 @@ def main(argv=None):
1133
1221
  help="Include environments owned by other identities in this workspace",
1134
1222
  )
1135
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
+ )
1242
+
1136
1243
  cache_parser = subparsers.add_parser(
1137
1244
  "cache",
1138
1245
  help="Manage Hetzner snapshots created after the configure (build) stage",
@@ -1270,6 +1377,10 @@ def main(argv=None):
1270
1377
  return _cmd_dev(args)
1271
1378
  if args.command == "list":
1272
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)
1273
1384
  if args.command == "cache":
1274
1385
  return _cmd_cache(args)
1275
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)
@@ -1639,6 +1639,78 @@ class RemoteDevManager:
1639
1639
  log.warning("Could not save state: %s", e)
1640
1640
  return False
1641
1641
 
1642
+ # -- Environment Outputs (ADR 0002) ------------------------------------
1643
+
1644
+ outputs_prefix = "remote-dev/outputs"
1645
+
1646
+ def _outputs_key(self, name: str) -> str:
1647
+ """One Outputs object per Environment name (no owner segment)."""
1648
+ return f"{self.outputs_prefix}/{name}.yml"
1649
+
1650
+ def load_outputs(self, name: str) -> Optional[Dict]:
1651
+ """Stored Outputs for an Environment, or None if none were recorded."""
1652
+ if not self.storage_manager or not self._state_bucket_present():
1653
+ return None
1654
+ return self._read_outputs_object(name)
1655
+
1656
+ def _read_outputs_object(self, name: str) -> Optional[Dict]:
1657
+ """Read the Outputs object if it exists.
1658
+
1659
+ Existence is checked with a listing first: ``download_file`` retries
1660
+ "not found" for ~30s (eventual consistency after upload), which would
1661
+ make a never-written object look like a hang.
1662
+ """
1663
+ assert self.storage_manager is not None
1664
+ key = self._outputs_key(name)
1665
+ if key not in self.storage_manager.list_objects(self.state_bucket, key):
1666
+ return None
1667
+ return self._read_yaml_object(key)
1668
+
1669
+ def save_outputs(self, name: str, new: Dict) -> bool:
1670
+ """Shallow-merge *new* into the Environment's stored Outputs."""
1671
+ if not self.storage_manager:
1672
+ return False
1673
+ from cli.outputs import merge_outputs
1674
+ try:
1675
+ if not self._ensure_state_bucket():
1676
+ log.warning("Could not ensure state bucket exists")
1677
+ return False
1678
+ merged = merge_outputs(self._read_outputs_object(name), new)
1679
+ merged['updated_at'] = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime())
1680
+ import tempfile
1681
+ fd, tmp = tempfile.mkstemp(suffix=".yml")
1682
+ try:
1683
+ with os.fdopen(fd, 'w') as f:
1684
+ yaml.dump(merged, f, default_flow_style=False, sort_keys=False)
1685
+ os.chmod(tmp, 0o600)
1686
+ self.storage_manager.upload_file(self.state_bucket, tmp, self._outputs_key(name))
1687
+ finally:
1688
+ try:
1689
+ os.unlink(tmp)
1690
+ except OSError:
1691
+ pass
1692
+ return True
1693
+ except StateBucketError:
1694
+ raise
1695
+ except Exception as e:
1696
+ log.warning("Could not save outputs: %s", e)
1697
+ return False
1698
+
1699
+ def find_record(self, name: str) -> Optional[Dict]:
1700
+ """The stored record of the Environment called *name*, whoever owns it."""
1701
+ for record in self._load_state().get('environments', []):
1702
+ if record.get('name') == name:
1703
+ return record
1704
+ return None
1705
+
1706
+ def conflicting_owner(self, name: str, owner: str) -> Optional[str]:
1707
+ """Owner of an existing *name* when it isn't *owner*, else None."""
1708
+ record = self.find_record(name)
1709
+ if not record:
1710
+ return None
1711
+ existing = record.get('owner')
1712
+ return existing if existing and existing != owner else None
1713
+
1642
1714
  def _delete_state(self, name: str) -> bool:
1643
1715
  """Remove an environment's record(s), whoever owns them."""
1644
1716
  if not self.storage_manager:
@@ -1656,6 +1728,7 @@ class RemoteDevManager:
1656
1728
  if key.endswith(suffix):
1657
1729
  self.storage_manager.delete_object(self.state_bucket, key)
1658
1730
  self._drop_legacy_record(name)
1731
+ self.storage_manager.delete_object(self.state_bucket, self._outputs_key(name))
1659
1732
  log.debug("State removed for %s", name)
1660
1733
  return True
1661
1734
 
@@ -1931,8 +2004,85 @@ class RemoteDevEnvironment:
1931
2004
  log.error("SSH key generation failed: %s", e)
1932
2005
  return False
1933
2006
 
2007
+ def exists(self) -> bool:
2008
+ """True when a record for this Environment is in the State bucket."""
2009
+ return self.manager.find_record(self.name) is not None
2010
+
2011
+ def stored_outputs(self) -> Optional[Dict]:
2012
+ """The Outputs stored for this Environment (None if none recorded)."""
2013
+ return self.manager.load_outputs(self.name)
2014
+
2015
+ def inspect_details(self) -> Optional[Dict[str, Any]]:
2016
+ """Technical details of this Environment, or None if it is unknown.
2017
+
2018
+ Combines the stored record with live Hetzner server data. If the live
2019
+ lookup fails, the stored data is returned with ``stale`` set.
2020
+ """
2021
+ self.resolve_resources()
2022
+ record = self.manager.find_record(self.name)
2023
+ if record is None and not self.vm_id:
2024
+ return None
2025
+ record = record or {}
2026
+ details: Dict[str, Any] = {
2027
+ 'name': self.name,
2028
+ 'owner': record.get('owner'),
2029
+ 'id': record.get('id') or self.vm_id,
2030
+ 'status': None,
2031
+ 'ip': record.get('ip') or self.vm_ip,
2032
+ 'type': record.get('type'),
2033
+ 'region': record.get('region'),
2034
+ 'ssh_key_id': record.get('ssh_key_id') or self.ssh_key_id,
2035
+ 'firewall_id': record.get('firewall_id') or self.firewall_id,
2036
+ 'created_at': record.get('created_at'),
2037
+ 'updated_at': record.get('updated_at'),
2038
+ 'stale': False,
2039
+ }
2040
+ try:
2041
+ if not self.vm_id:
2042
+ raise ValueError("no server id")
2043
+ server = (self.manager.get_vm(self.vm_id) or {}).get('server') or {}
2044
+ if not server:
2045
+ raise ValueError("server not found")
2046
+ details['status'] = server.get('status')
2047
+ details['ip'] = _ipv4_from_public_net(server.get('public_net') or {}) or details['ip']
2048
+ details['type'] = (server.get('server_type') or {}).get('name') or details['type']
2049
+ details['region'] = (server.get('datacenter') or {}).get('name') or details['region']
2050
+ except Exception as exc:
2051
+ log.debug("Live server lookup failed for %s: %s", self.name, exc)
2052
+ details['stale'] = True
2053
+ details['connection'] = {
2054
+ 'host': details['ip'],
2055
+ 'user': 'root',
2056
+ 'ssh_key_path': f'/tmp/{self.ssh_key_name}',
2057
+ }
2058
+ return details
2059
+
2060
+ def name_available(self) -> bool:
2061
+ """False when another owner already holds this name in the State bucket.
2062
+
2063
+ Environment names are unique across owners (ADR 0002): Outputs are
2064
+ keyed by name alone. The owner re-creating its own name is allowed.
2065
+ """
2066
+ if not self.manager.storage_manager:
2067
+ return True
2068
+ from cli.state_bucket import StateBucketNotConfigured
2069
+ try:
2070
+ other = self.manager.conflicting_owner(self.name, self._owner_identity())
2071
+ except StateBucketNotConfigured:
2072
+ return True # no bucket yet, so nothing can conflict
2073
+ if other:
2074
+ log.error(
2075
+ "Environment name '%s' is already used by '%s'; choose another name",
2076
+ self.name,
2077
+ other,
2078
+ )
2079
+ return False
2080
+ return True
2081
+
1934
2082
  def setup(self, project_dir: Optional[str] = None):
1935
2083
  """Set up the complete remote development environment"""
2084
+ if not self.name_available():
2085
+ return False
1936
2086
  log.info("Creating remote environment '%s'", self.name)
1937
2087
 
1938
2088
  # Prefer matching Hetzner snapshots for faster boot / fewer playbooks.
@@ -2285,6 +2435,10 @@ class RemoteDevEnvironment:
2285
2435
  continue
2286
2436
  log.error("%s playbook failed", kind.capitalize())
2287
2437
  return False
2438
+ # Outputs published by this stage (never from destroy).
2439
+ captured = getattr(ansible, "last_outputs", None)
2440
+ if captured and kind != "destroy":
2441
+ self.manager.save_outputs(self.name, captured)
2288
2442
  # Snapshot only after configure (build layer); never after authorize.
2289
2443
  if kind == SNAPSHOT_AFTER:
2290
2444
  if not self._snapshot_after_playbook(kind, project):
@@ -5739,6 +5893,8 @@ class AnsibleManager:
5739
5893
  return False
5740
5894
  return True
5741
5895
 
5896
+ last_outputs: Optional[Dict[str, Any]] = None
5897
+
5742
5898
  def _run_one_playbook(
5743
5899
  self,
5744
5900
  playbook_path: str,
@@ -5746,6 +5902,48 @@ class AnsibleManager:
5746
5902
  vault_password: Optional[str] = None,
5747
5903
  stream: bool = False,
5748
5904
  ansible_args: Optional[Sequence[str]] = None,
5905
+ ) -> bool:
5906
+ """Run one playbook and capture the Outputs it publishes (ADR 0002).
5907
+
5908
+ The playbook receives ``rig_outputs_file`` and may write its
5909
+ ``rig_outputs`` dict there. After a successful run the parsed content
5910
+ is left in ``self.last_outputs`` (None when nothing valid was written).
5911
+ """
5912
+ import tempfile
5913
+ from cli.outputs import read_outputs_file
5914
+
5915
+ self.last_outputs = None
5916
+ out_dir = os.path.join("/tmp", ".rig", "ansible-outputs")
5917
+ os.makedirs(out_dir, mode=0o700, exist_ok=True)
5918
+ fd, outputs_path = tempfile.mkstemp(suffix=".yml", dir=out_dir)
5919
+ os.close(fd)
5920
+ try:
5921
+ ok = self._exec_playbook(
5922
+ playbook_path,
5923
+ extra_vars=extra_vars,
5924
+ vault_password=vault_password,
5925
+ stream=stream,
5926
+ ansible_args=ansible_args,
5927
+ outputs_file=outputs_path,
5928
+ )
5929
+ if ok:
5930
+ # read_outputs_file treats a missing or empty file as no outputs
5931
+ self.last_outputs = read_outputs_file(outputs_path)
5932
+ return ok
5933
+ finally:
5934
+ try:
5935
+ os.unlink(outputs_path)
5936
+ except OSError:
5937
+ pass
5938
+
5939
+ def _exec_playbook(
5940
+ self,
5941
+ playbook_path: str,
5942
+ extra_vars: Optional[Dict[str, Any]] = None,
5943
+ vault_password: Optional[str] = None,
5944
+ stream: bool = False,
5945
+ ansible_args: Optional[Sequence[str]] = None,
5946
+ outputs_file: Optional[str] = None,
5749
5947
  ) -> bool:
5750
5948
  import shlex
5751
5949
 
@@ -5809,6 +6007,9 @@ class AnsibleManager:
5809
6007
  cmd.extend(["-e", f"@{filtered_identity}"])
5810
6008
  vars_path = filtered_identity
5811
6009
 
6010
+ if outputs_file:
6011
+ cmd.extend(["-e", f"rig_outputs_file={outputs_file}"])
6012
+
5812
6013
  # Runtime rig_* context (and caller extras) after vars.yml so they win.
5813
6014
  if extra_vars:
5814
6015
  self.extra_vars.update(extra_vars)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mystack-rig
3
- Version: 1.2.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 |