mystack-rig 1.7.0__tar.gz → 1.7.2__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 (129) hide show
  1. mystack_rig-1.7.2/CLAUDE.md +31 -0
  2. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/PKG-INFO +1 -1
  3. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/cli/devcontainers.py +75 -6
  4. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/cli/remote_dev.py +31 -8
  5. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/mystack_rig.egg-info/PKG-INFO +1 -1
  6. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/mystack_rig.egg-info/SOURCES.txt +1 -0
  7. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/mystack_rig.egg-info/scm_file_list.json +1 -0
  8. mystack_rig-1.7.2/src/mystack_rig.egg-info/scm_version.json +8 -0
  9. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_devcontainers.py +55 -0
  10. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_live_agent.py +9 -0
  11. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_setup_provision.py +13 -0
  12. mystack_rig-1.7.0/src/mystack_rig.egg-info/scm_version.json +0 -8
  13. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/.coveragerc +0 -0
  14. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/.git-blame-ignore-revs +0 -0
  15. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/.github/workflows/release.yml +0 -0
  16. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/.github/workflows/tests.yml +0 -0
  17. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/.gitignore +0 -0
  18. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/.rig/playbooks/README.md +0 -0
  19. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/.rig/playbooks/vpn-gateway.yml +0 -0
  20. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/CLI_STORAGE_SUMMARY.md +0 -0
  21. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/Dockerfile +0 -0
  22. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/GIT_CLONE_FEATURE.md +0 -0
  23. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/GLOSSARY.md +0 -0
  24. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/HETZNER_STORAGE_GUIDE.md +0 -0
  25. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/HETZNER_STORAGE_SECURITY_GUIDE.md +0 -0
  26. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/LICENSE +0 -0
  27. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/Makefile +0 -0
  28. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/README.md +0 -0
  29. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/README_REAL_E2E.md +0 -0
  30. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/STORAGE_CLI_GUIDE.md +0 -0
  31. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/docs/adr/0001-per-profile-generated-state-bucket.md +0 -0
  32. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/docs/adr/0002-outputs-as-separate-object-via-file-handoff.md +0 -0
  33. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/docs/adr/0003-mcp-servers-declared-once-rendered-at-authorize.md +0 -0
  34. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/docs/adr/0004-agents-run-as-live-agents-in-tmux.md +0 -0
  35. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/docs/adr/0005-docker-in-configure-for-devcontainers.md +0 -0
  36. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/docs/adr/0006-workspace-user-instead-of-root.md +0 -0
  37. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/docs/architecture.md +0 -0
  38. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/docs/architecture.png +0 -0
  39. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/docs/architecture.svg +0 -0
  40. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/forged-idea.md +0 -0
  41. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/pyproject.toml +0 -0
  42. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/pytest.ini +0 -0
  43. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/requirements.txt +0 -0
  44. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/sample.env +0 -0
  45. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/scripts/coverage_badge.py +0 -0
  46. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/scripts/pypi_version.py +0 -0
  47. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/setup.cfg +0 -0
  48. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/__init__.py +0 -0
  49. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/cli/__init__.py +0 -0
  50. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/cli/__main__.py +0 -0
  51. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/cli/agents.py +0 -0
  52. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/cli/ansible_filters/__init__.py +0 -0
  53. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/cli/ansible_filters/rig_live.py +0 -0
  54. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/cli/ansible_filters/rig_mcp.py +0 -0
  55. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/cli/assets/rig-agent-queue +0 -0
  56. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/cli/assets/rig-agent-state +0 -0
  57. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/cli/assets/tmux.conf +0 -0
  58. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/cli/config.py +0 -0
  59. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/cli/encrypt.py +0 -0
  60. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/cli/git.py +0 -0
  61. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/cli/git_author.py +0 -0
  62. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/cli/last_env.py +0 -0
  63. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/cli/last_session.py +0 -0
  64. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/cli/last_target.py +0 -0
  65. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/cli/live_agent.py +0 -0
  66. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/cli/log.py +0 -0
  67. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/cli/main.py +0 -0
  68. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/cli/mcp.py +0 -0
  69. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/cli/outputs.py +0 -0
  70. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/cli/requirements.txt +0 -0
  71. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/cli/snapshots.py +0 -0
  72. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/cli/state_bucket.py +0 -0
  73. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/cli/storage.py +0 -0
  74. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/cli/vault_keys.py +0 -0
  75. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/cli/vpn.py +0 -0
  76. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/cli/workspace_user.py +0 -0
  77. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/mystack_rig.egg-info/dependency_links.txt +0 -0
  78. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/mystack_rig.egg-info/entry_points.txt +0 -0
  79. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/mystack_rig.egg-info/requires.txt +0 -0
  80. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/src/mystack_rig.egg-info/top_level.txt +0 -0
  81. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/test_hetzner_integration.py +0 -0
  82. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/conftest.py +0 -0
  83. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_agents.py +0 -0
  84. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_ansible_galaxy.py +0 -0
  85. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_attach_command.py +0 -0
  86. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_credential_security.py +0 -0
  87. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_destroy_command.py +0 -0
  88. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_dev_command.py +0 -0
  89. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_encrypt_command.py +0 -0
  90. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_encrypt_coverage.py +0 -0
  91. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_firewall_client_ip.py +0 -0
  92. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_git_clone_unit.py +0 -0
  93. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_git_credentials_and_author.py +0 -0
  94. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_git_manager.py +0 -0
  95. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_gitignore_init.py +0 -0
  96. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_hetzner_storage.py +0 -0
  97. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_init_command.py +0 -0
  98. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_inspect_describe.py +0 -0
  99. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_last_env.py +0 -0
  100. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_last_session.py +0 -0
  101. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_last_target.py +0 -0
  102. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_live_agent_cli.py +0 -0
  103. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_log.py +0 -0
  104. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_main_coverage.py +0 -0
  105. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_mcp_command.py +0 -0
  106. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_mcp_render.py +0 -0
  107. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_outputs.py +0 -0
  108. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_outputs_storage.py +0 -0
  109. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_pypi_version.py +0 -0
  110. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_python_floor.py +0 -0
  111. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_r2_storage.py +0 -0
  112. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_real_e2e_integration.py +0 -0
  113. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_real_e2e_storage.py +0 -0
  114. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_real_e2e_vpn.py +0 -0
  115. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_real_e2e_vpn_tunnel.py +0 -0
  116. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_remote_dev.py +0 -0
  117. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_remote_dev_coverage_extensions.py +0 -0
  118. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_rig_ansible_vars.py +0 -0
  119. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_rig_config.py +0 -0
  120. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_secret_prompt_hidden.py +0 -0
  121. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_simulation_storage.py +0 -0
  122. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_small_module_coverage.py +0 -0
  123. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_snapshots.py +0 -0
  124. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_state_bucket.py +0 -0
  125. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_storage_basic.py +0 -0
  126. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_vault_keys.py +0 -0
  127. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_vpn_optional.py +0 -0
  128. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_vpn_unit.py +0 -0
  129. {mystack_rig-1.7.0 → mystack_rig-1.7.2}/tests/test_workspace_git_clone.py +0 -0
@@ -0,0 +1,31 @@
1
+ # Rig: rules for agents
2
+
3
+ Vocabulary is in `GLOSSARY.md`; decisions are in `docs/adr/`.
4
+
5
+ ## Fixing a bug or shipping a change
6
+
7
+ Do every step, in order. Don't stop after the PR.
8
+
9
+ 1. **Branch** off `master`: `fix/<what>` or `feat/<what>`. Never commit to `master`.
10
+ 2. **Test first.** Add a test that fails without the fix. Keep the diff to what the bug needs.
11
+ 3. **Run the CI gates locally** (same versions as CI):
12
+ - `uvx ruff@0.17.5 check .` and `uvx ruff@0.17.5 format --check .` (run `format .` to fix)
13
+ - `uvx mypy src/ --ignore-missing-imports`
14
+ - `uv run pytest tests/ -m "not e2e" --cov=src --cov-fail-under=90` with the same `--ignore` flags as the Unit Tests job in `.github/workflows/tests.yml`
15
+ 4. **Commit and push**, then open a PR against `master` (use the `pr` skill for the body). Commit messages are conventional (`fix:`, `feat:`).
16
+ 5. **Wait for every CI job to pass**: Lint, Type Check, Unit Tests, Integration Tests, E2E Tests and `codecov/patch`. Use `gh pr checks <n> --watch`. If one fails, fix it on the branch; never merge red.
17
+ 6. **Coverage must not drop.** The floor is 90% (`.coveragerc`), but also don't lower the current total or leave new code untested. `codecov/patch` must pass.
18
+ 7. **Merge** the PR with a merge commit (`gh pr merge <n> --merge`), then update `master`.
19
+ 8. **Release.** Tag the merge commit and push the tag; the Release workflow publishes to PyPI.
20
+ - Bug fix: bump the patch (`v1.7.0` → `v1.7.1`). New feature: bump the minor. Breaking change: bump the major.
21
+ - `git tag -a vX.Y.Z -m "<summary>" && git push origin vX.Y.Z`, then `gh run watch` the Release run and confirm the version on PyPI.
22
+ 9. **Tell the user** what was merged, the version, and anything existing Environments or workspaces must do (re-create, edit user-owned playbooks).
23
+
24
+ Ask before merging or releasing only if CI is red, coverage dropped, or the user hasn't asked for a release.
25
+
26
+ ## Testing
27
+
28
+ - Unit tests mutate `HETZNER_CLOUD_API_TOKEN` in-process. Run the real-API tests (`tests/test_real_e2e_*.py`, `tests/test_hetzner_storage.py`, `tests/test_workspace_git_clone.py`) in their own pytest process, or they fail with 401.
29
+ - Real-API and real-VM tests cost money. Delete what you create (`rig delete`, then check no servers, SSH keys or firewalls are left with the Hetzner API).
30
+ - Anything that SSHes before `authorize.yml` has run must connect as `root`: the workspace user can't log in until authorize copies its key.
31
+ - `provision.yml` and `authorize.yml` are regenerated on every run; `configure.yml` and `materialize.yml` are user-owned and never overwritten, so changes to them need a README note for existing workspaces.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mystack-rig
3
- Version: 1.7.0
3
+ Version: 1.7.2
4
4
  Summary: Ephemeral remotes with full local parity for coding agents
5
5
  Author: mystack-cloud
6
6
  License-Expression: MIT
@@ -137,16 +137,84 @@ def choose_target(
137
137
  print(f"Not a choice: {answer}")
138
138
 
139
139
 
140
- def devcontainer_folder_uri(alias: str, repo_dest: str, target: DevTarget) -> str:
141
- """``--folder-uri`` that opens *target* in its container over Remote-SSH.
140
+ def _strip_jsonc(text: str) -> str:
141
+ """Drop ``//`` and ``/* */`` comments and trailing commas (devcontainer.json is JSONC)."""
142
+ out: list[str] = []
143
+ i, n, in_str = 0, len(text), False
144
+ while i < n:
145
+ c = text[i]
146
+ if in_str:
147
+ out.append(c)
148
+ if c == "\\" and i + 1 < n:
149
+ out.append(text[i + 1])
150
+ i += 1
151
+ elif c == '"':
152
+ in_str = False
153
+ elif c == '"':
154
+ in_str = True
155
+ out.append(c)
156
+ elif text.startswith("//", i):
157
+ while i < n and text[i] != "\n":
158
+ i += 1
159
+ continue
160
+ elif text.startswith("/*", i):
161
+ end = text.find("*/", i + 2)
162
+ i = n if end < 0 else end + 2
163
+ continue
164
+ else:
165
+ out.append(c)
166
+ i += 1
167
+ return re.sub(r",(\s*[}\]])", r"\1", "".join(out))
142
168
 
143
- The folder holding the ``.devcontainer`` definition is the container's host
144
- path, and the editor mounts it at ``/workspaces/<folder name>``.
169
+
170
+ def parse_workspace_folder(config_text: str, host_path: str) -> str | None:
171
+ """``workspaceFolder`` from a devcontainer.json's text, or None when unset or unusable.
172
+
173
+ Resolves ``${localWorkspaceFolder}`` and ``${localWorkspaceFolderBasename}``;
174
+ anything else that is not an absolute path is ignored.
175
+ """
176
+ try:
177
+ data = json.loads(_strip_jsonc(config_text))
178
+ except ValueError:
179
+ return None
180
+ value = data.get("workspaceFolder") if isinstance(data, dict) else None
181
+ if not isinstance(value, str):
182
+ return None
183
+ value = value.replace("${localWorkspaceFolderBasename}", posixpath.basename(host_path))
184
+ value = value.replace("${localWorkspaceFolder}", host_path)
185
+ return value if value.startswith("/") and "${" not in value else None
186
+
187
+
188
+ def read_workspace_folder(env, repo_dest: str, target: DevTarget) -> str | None:
189
+ """The ``workspaceFolder`` *target*'s devcontainer.json sets, read from *env*'s VM over SSH.
190
+
191
+ None when it is unset or the file can't be read, so the caller falls back to the default.
145
192
  """
146
193
  config = posixpath.join(repo_dest, target.config)
194
+ try:
195
+ result = env.run_remote(f"cat {shlex.quote(config)}")
196
+ except Exception: # ssh missing, timeout, ...
197
+ return None
198
+ if result.returncode != 0:
199
+ return None
200
+ return parse_workspace_folder(result.stdout, _host_path(repo_dest, target))
201
+
202
+
203
+ def _host_path(repo_dest: str, target: DevTarget) -> str:
147
204
  # "" for the repo root, "sub/" for a subfolder
148
205
  prefix = target.config.split(".devcontainer")[0]
149
- host_path = posixpath.join(repo_dest, prefix).rstrip("/")
206
+ return posixpath.join(repo_dest, prefix).rstrip("/")
207
+
208
+
209
+ def devcontainer_folder_uri(alias: str, repo_dest: str, target: DevTarget, workspace_folder: str | None = None) -> str:
210
+ """``--folder-uri`` that opens *target* in its container over Remote-SSH.
211
+
212
+ The folder holding the ``.devcontainer`` definition is the container's host
213
+ path. The editor opens the config's ``workspaceFolder`` when it sets one,
214
+ else the Dev Containers default ``/workspaces/<folder name>``.
215
+ """
216
+ config = posixpath.join(repo_dest, target.config)
217
+ host_path = _host_path(repo_dest, target)
150
218
  payload = {
151
219
  "hostPath": host_path,
152
220
  "configFile": {
@@ -157,7 +225,8 @@ def devcontainer_folder_uri(alias: str, repo_dest: str, target: DevTarget) -> st
157
225
  },
158
226
  }
159
227
  encoded = json.dumps(payload, separators=(",", ":")).encode().hex()
160
- return f"vscode-remote://dev-container+{encoded}@ssh-remote+{alias}/workspaces/{posixpath.basename(host_path)}"
228
+ folder = workspace_folder or f"/workspaces/{posixpath.basename(host_path)}"
229
+ return f"vscode-remote://dev-container+{encoded}@ssh-remote+{alias}{folder}"
161
230
 
162
231
 
163
232
  class DevContainerScanError(DevContainerError):
@@ -3231,8 +3231,10 @@ echo "Agent installation complete!"
3231
3231
  log.debug("Resume later with: rig attach (or --resume/--session %s)", session_id)
3232
3232
  return int(exit_code)
3233
3233
 
3234
- def _ssh_command(self, remote_cmd: str, *, tty: bool, connect_timeout: int | None = None) -> list[str]:
3235
- """SSH argv as the workspace user. ``tty`` allocates a terminal; otherwise the call is batch-mode."""
3234
+ def _ssh_command(
3235
+ self, remote_cmd: str, *, tty: bool, connect_timeout: int | None = None, user: str | None = None
3236
+ ) -> list[str]:
3237
+ """SSH argv as the workspace user (or ``user``). ``tty`` allocates a terminal; otherwise the call is batch-mode."""
3236
3238
  ssh_key_path = f"/tmp/{self.ssh_key_name}"
3237
3239
  cmd = ["ssh"]
3238
3240
  if tty:
@@ -3253,7 +3255,7 @@ echo "Agent installation complete!"
3253
3255
  cmd += ["-o", "BatchMode=yes"]
3254
3256
  if connect_timeout:
3255
3257
  cmd += ["-o", f"ConnectTimeout={int(connect_timeout)}"]
3256
- cmd += [f"{self.work_user}@{self.vm_ip}", remote_cmd]
3258
+ cmd += [f"{user or self.work_user}@{self.vm_ip}", remote_cmd]
3257
3259
  return cmd
3258
3260
 
3259
3261
  def _interactive_ssh_command(self, remote_cmd: str) -> list[str]:
@@ -3267,10 +3269,15 @@ echo "Agent installation complete!"
3267
3269
  input_text: str | None = None,
3268
3270
  timeout: int = 30,
3269
3271
  connect_timeout: int = 10,
3272
+ user: str | None = None,
3270
3273
  ) -> subprocess.CompletedProcess:
3271
- """Run one non-interactive command on the VM (stdin from ``input_text``)."""
3274
+ """Run one non-interactive command on the VM (stdin from ``input_text``).
3275
+
3276
+ Runs as the workspace user unless ``user`` is given. Before authorize has
3277
+ run, only root can log in: the workspace user's key is copied there.
3278
+ """
3272
3279
  return subprocess.run(
3273
- self._ssh_command(command, tty=False, connect_timeout=connect_timeout),
3280
+ self._ssh_command(command, tty=False, connect_timeout=connect_timeout, user=user),
3274
3281
  input=input_text,
3275
3282
  capture_output=True,
3276
3283
  text=True,
@@ -3286,7 +3293,8 @@ echo "Agent installation complete!"
3286
3293
  if not self.vm_ip:
3287
3294
  return False
3288
3295
  try:
3289
- result = self.run_remote("sync && sync", timeout=timeout, connect_timeout=15)
3296
+ # As root: this runs before authorize, when the workspace user can't log in yet.
3297
+ result = self.run_remote("sync && sync", timeout=timeout, connect_timeout=15, user="root")
3290
3298
  except (OSError, subprocess.SubprocessError) as exc:
3291
3299
  log.warning("Could not flush the disk of %s: %s", self.name, exc)
3292
3300
  return False
@@ -3632,9 +3640,11 @@ echo "Agent installation complete!"
3632
3640
  alias = self.ensure_ssh_config_host(ssh_config_path=ssh_config_path)
3633
3641
  folder_uri = f"vscode-remote://ssh-remote+{alias}{remote_path}"
3634
3642
  if dev_target is not None and repo_dest:
3635
- from cli.devcontainers import devcontainer_folder_uri
3643
+ from cli.devcontainers import devcontainer_folder_uri, read_workspace_folder
3636
3644
 
3637
- folder_uri = devcontainer_folder_uri(alias, repo_dest, dev_target)
3645
+ folder_uri = devcontainer_folder_uri(
3646
+ alias, repo_dest, dev_target, read_workspace_folder(self, repo_dest, dev_target)
3647
+ )
3638
3648
  remote_path = f"{dev_target.label} Dev Container"
3639
3649
  cmd = [editor_bin, "--folder-uri", folder_uri]
3640
3650
  log.info("Opening %s on %s (%s)", editor_bin, self.vm_ip, remote_path)
@@ -4383,6 +4393,19 @@ AUTHORIZE_PLAYBOOK = r"""---
4383
4393
  - /run/rig/agents
4384
4394
  - /var/log/rig
4385
4395
 
4396
+ # The agent runs as the workspace user: its hooks write state here and the
4397
+ # attach script writes the log. /run is a tmpfs, so this runs on every authorize.
4398
+ - name: Let the workspace user write live-agent state and logs
4399
+ file:
4400
+ path: "{{ item }}"
4401
+ state: directory
4402
+ owner: "{{ rig_user }}"
4403
+ group: "{{ rig_user }}"
4404
+ mode: "0755"
4405
+ loop:
4406
+ - /run/rig/agents
4407
+ - /var/log/rig
4408
+
4386
4409
  - name: Install the live-agent tmux configuration
4387
4410
  copy:
4388
4411
  src: "{{ rig_assets_dir }}/tmux.conf"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mystack-rig
3
- Version: 1.7.0
3
+ Version: 1.7.2
4
4
  Summary: Ephemeral remotes with full local parity for coding agents
5
5
  Author: mystack-cloud
6
6
  License-Expression: MIT
@@ -1,6 +1,7 @@
1
1
  .coveragerc
2
2
  .git-blame-ignore-revs
3
3
  .gitignore
4
+ CLAUDE.md
4
5
  CLI_STORAGE_SUMMARY.md
5
6
  Dockerfile
6
7
  GIT_CLONE_FEATURE.md
@@ -7,6 +7,7 @@
7
7
  ".gitignore",
8
8
  ".rig/playbooks/README.md",
9
9
  ".rig/playbooks/vpn-gateway.yml",
10
+ "CLAUDE.md",
10
11
  "CLI_STORAGE_SUMMARY.md",
11
12
  "Dockerfile",
12
13
  "GIT_CLONE_FEATURE.md",
@@ -0,0 +1,8 @@
1
+ {
2
+ "tag": "1.7.2",
3
+ "distance": 0,
4
+ "node": "g38e76953b1c24d8ab22c3bad8130888076500a63",
5
+ "dirty": false,
6
+ "branch": "HEAD",
7
+ "node_date": "2026-11-27"
8
+ }
@@ -198,6 +198,61 @@ def test_uri_for_subfolder_container_uses_that_folder_as_host_path():
198
198
  assert folder == "/workspaces/svc"
199
199
 
200
200
 
201
+ def test_uri_opens_the_workspace_folder_the_config_sets():
202
+ from cli.devcontainers import devcontainer_folder_uri
203
+
204
+ uri = devcontainer_folder_uri("rig-env1", "/workspace/ops-box", API_DEFAULT, "/workspace")
205
+ _payload, _host, folder = _decode_uri(uri)
206
+ assert folder == "/workspace"
207
+
208
+
209
+ JSONC = """{
210
+ // the compose file mounts the parent directory
211
+ "name": "ops", /* c */
212
+ "url": "http://x//y",
213
+ "workspaceFolder": "/workspace/${localWorkspaceFolderBasename}",
214
+ }"""
215
+
216
+
217
+ def test_parse_workspace_folder_handles_jsonc_and_variables():
218
+ from cli.devcontainers import parse_workspace_folder
219
+
220
+ assert parse_workspace_folder(JSONC, "/workspace/ops-box") == "/workspace/ops-box"
221
+ assert parse_workspace_folder('{"workspaceFolder": "${localWorkspaceFolder}/app"}', "/w/r") == "/w/r/app"
222
+
223
+
224
+ def test_parse_workspace_folder_ignores_unset_relative_unknown_and_broken():
225
+ from cli.devcontainers import parse_workspace_folder
226
+
227
+ for text in ("{}", '{"workspaceFolder": "rel"}', '{"workspaceFolder": "${containerEnv:X}"}', "nope", "[]"):
228
+ assert parse_workspace_folder(text, "/w/r") is None
229
+
230
+
231
+ def test_read_workspace_folder_reads_over_ssh_and_falls_back_on_failure():
232
+ import subprocess
233
+ from types import SimpleNamespace
234
+
235
+ from cli.devcontainers import read_workspace_folder
236
+
237
+ seen = []
238
+
239
+ def ok(cmd):
240
+ seen.append(cmd)
241
+ return subprocess.CompletedProcess(cmd, 0, stdout='{"workspaceFolder": "/workspace"}', stderr="")
242
+
243
+ assert read_workspace_folder(SimpleNamespace(run_remote=ok), "/workspace/api", API_DEFAULT) == "/workspace"
244
+ assert "/workspace/api/.devcontainer/devcontainer.json" in seen[0]
245
+
246
+ def bad(cmd):
247
+ return subprocess.CompletedProcess(cmd, 1, stdout="", stderr="no such file")
248
+
249
+ def boom(cmd):
250
+ raise OSError("ssh missing")
251
+
252
+ assert read_workspace_folder(SimpleNamespace(run_remote=bad), "/workspace/api", API_DEFAULT) is None
253
+ assert read_workspace_folder(SimpleNamespace(run_remote=boom), "/workspace/api", API_DEFAULT) is None
254
+
255
+
201
256
  # --- Docker in configure (ADR 0005) -----------------------------------------
202
257
 
203
258
 
@@ -612,3 +612,12 @@ def test_claude_as_root_needs_is_sandbox_to_use_bypass_mode():
612
612
  assert "export IS_SANDBOX=1; " in only_flag and "IS_SANDBOX" not in RemoteDevEnvironment.agent_remote_command(
613
613
  "claude"
614
614
  )
615
+
616
+
617
+ def test_authorize_hands_live_agent_state_and_log_dirs_to_the_workspace_user():
618
+ from cli.remote_dev import AUTHORIZE_PLAYBOOK
619
+
620
+ play = yaml.safe_load(AUTHORIZE_PLAYBOOK)[0]
621
+ task = next(t for t in play["tasks"] if t.get("name", "").startswith("Let the workspace user write live-agent"))
622
+ assert task["file"]["owner"] == "{{ rig_user }}"
623
+ assert task["loop"] == [la.STATE_DIR, la.LOG_DIR]
@@ -1221,3 +1221,16 @@ def test_environment_connects_as_the_configured_workspace_user():
1221
1221
  assert env.work_home == "/home/ops"
1222
1222
  assert env._ssh_command("true", tty=False)[-2] == "ops@203.0.113.9"
1223
1223
  assert "/home/ops/.claude/credentials.env" in env.agent_remote_command("claude", home=env.work_home)
1224
+
1225
+
1226
+ def test_flush_disk_connects_as_root_before_the_workspace_user_can_log_in():
1227
+ import subprocess
1228
+ from unittest.mock import patch
1229
+
1230
+ env = RemoteDevEnvironment(name="flush")
1231
+ env.vm_ip, env.ssh_key_name = "203.0.113.9", "k"
1232
+ with patch("cli.remote_dev.subprocess.run") as run:
1233
+ run.return_value = subprocess.CompletedProcess([], 0, "", "")
1234
+ assert env.flush_disk() is True
1235
+ assert "root@203.0.113.9" in run.call_args.args[0]
1236
+ assert "dev@203.0.113.9" in env._ssh_command("true", tty=False)
@@ -1,8 +0,0 @@
1
- {
2
- "tag": "1.7.0",
3
- "distance": 0,
4
- "node": "g3ef5a1e9fb3bf5ec791915cdf3186a9e558cbcb3",
5
- "dirty": false,
6
- "branch": "HEAD",
7
- "node_date": "2026-11-25"
8
- }
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