Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .claude/guardrails/write-scope.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ every item filled from live detection, not placeholders:
1. the exact instance: project path, container name and `containerPrefix`/runner, hosting profile;
2. the version pair (and hop plan, if one exists);
3. the routine commands about to run, listed individually (for example the `next-steps` helper,
`bin/magento --version`, the UCT probe/scan, normalization, `composer_probe.py`);
`bin/magento --version`, the UCT probe/scan, normalization, `composer_probe.py`; for scans run inside
the container also the helper's own `mutagen sync list` and `mutagen sync flush <session>`);
4. the ambient developer mounts the environment reports (for example Warden's host `~/.composer`,
the SSH volume, `ssh-auth.sock`), with the statement that they will not be read;
5. the standing profile: local/dev non-production, no production credentials or access;
Expand Down
46 changes: 46 additions & 0 deletions .claude/scripts/capture_uct.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import hashlib
import json
import os
import re
import secrets
import stat
import subprocess
Expand Down Expand Up @@ -55,6 +56,33 @@ def read_capture(descriptor):
return raw


def mutagen_flush(root):
"""Flush the one Mutagen session that syncs this project root so container writes reach the host.

Returns False (nothing to do) when Mutagen is not installed or no active session syncs the root,
so the flag is safe to pass on every container-run scan."""
try:
listing = subprocess.run(["mutagen", "sync", "list", "--template", "{{json .}}"],
stdin=subprocess.DEVNULL, capture_output=True, timeout=60, check=False)
except FileNotFoundError:
return False
if listing.returncode != 0:
raise ValueError("mutagen session list failed")
sessions = json.loads(listing.stdout or b"[]")
matches = [item.get("identifier") for item in sessions
if os.path.realpath(item.get("alpha", {}).get("path", "")) == os.path.realpath(root)
and not item.get("paused")]
if not matches:
return False
if len(matches) != 1 or not re.fullmatch(r"sync_[A-Za-z0-9]{10,64}", str(matches[0])):
raise ValueError("expected exactly one active mutagen session for the project root")
flushed = subprocess.run(["mutagen", "sync", "flush", matches[0]], stdin=subprocess.DEVNULL,
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=300, check=False)
if flushed.returncode != 0:
raise ValueError("mutagen sync flush failed")
return True


def raw_state(directory):
try:
metadata = os.stat(REPORT, dir_fd=directory, follow_symlinks=False)
Expand Down Expand Up @@ -86,6 +114,10 @@ def main():
parser.add_argument("--project-root", default=".")
parser.add_argument("--agent", choices=("claude-code", "github-copilot"), required=True)
parser.add_argument("--mode", choices=("stdout", "file"), required=True)
parser.add_argument("--mutagen-flush", action="store_true",
help="after a file-mode scan run in a container, flush the project's Mutagen sync "
"session and adopt the synced capture file (no-follow, regular, single link); "
"does nothing when Mutagen is not installed or no session syncs the project")
parser.add_argument("command", nargs=argparse.REMAINDER)
args = parser.parse_args()
descriptors = []
Expand All @@ -99,6 +131,8 @@ def main():
if not command:
raise ValueError("missing approved command argv")
outputs = [arg for arg in command if arg.startswith("--json-output-path")]
if args.mutagen_flush and args.mode != "file":
raise ValueError("--mutagen-flush applies to file mode only")
if outputs != ([PLACEHOLDER] if args.mode == "file" else []):
raise ValueError("only the private output placeholder is permitted")
root = os.path.abspath(args.project_root)
Expand Down Expand Up @@ -127,6 +161,13 @@ def main():
if result.returncode != 0:
print("UCT command exit status: " + str(result.returncode), file=sys.stderr)
raise ValueError("scan command failed")
if args.mutagen_flush:
phase = "sync flush"
if mutagen_flush(root):
# Mutagen replaces the file with a new inode; re-open it no-follow inside the private
# 0700 directory and validate it as a regular single-link file instead of the old descriptor.
capture_fd = os.open("report.json", os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK, dir_fd=temporary_fd)
descriptors.append(capture_fd)
phase = "capture validation"
current = os.stat("report.json", dir_fd=temporary_fd, follow_symlinks=False)
if not stat.S_ISREG(current.st_mode) or identity(current) != identity(os.fstat(capture_fd)):
Expand Down Expand Up @@ -161,6 +202,11 @@ def main():
except (OSError, ValueError, RecursionError):
print("UCT capture failed during " + phase + ". Stop; do not consume a previous report.",
file=sys.stderr)
if phase == "capture validation" and args.mode == "file":
print("If UCT ran in a container with a file-sync tool such as Mutagen, the sync may "
"have replaced the capture file (new inode) or not delivered it yet (empty report). "
"Retry with --mutagen-flush, exclude " + context + "/.uct-capture-* from sync, or run UCT "
"through uct_runner.py on the host; the check is intentional and is not bypassed.", file=sys.stderr)
if private and not published:
print("Private audit capture retained for human review: " + private, file=sys.stderr)
if published:
Expand Down
19 changes: 17 additions & 2 deletions .claude/skills/uct-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ python3 .claude/scripts/capture_uct.py --project-root . --agent claude-code --mo
**Composer mode** (use the live-reviewed `bin-dir` path if it differs from `vendor/bin`):

```bash
python3 .claude/scripts/capture_uct.py --project-root . --agent claude-code --mode file -- \
python3 .claude/scripts/capture_uct.py --project-root . --agent claude-code --mode file --mutagen-flush -- \
{containerPrefix} php -d memory_limit=-1 vendor/bin/uct upgrade:check . \
--current-version={installedVersion} \
--coming-version={resolvedTargetVersion} \
Expand Down Expand Up @@ -322,7 +322,7 @@ edition is inferred automatically from the target directory's own installed pack
branch needs no separate cloud/enterprise/community handling):

```bash
python3 .claude/scripts/capture_uct.py --project-root . --agent claude-code --mode file -- \
python3 .claude/scripts/capture_uct.py --project-root . --agent claude-code --mode file --mutagen-flush -- \
{containerPrefix} php -d memory_limit=-1 {uctStandalonePath}/bin/uct upgrade:check . \
--current-version={installedVersion} \
--coming-version={resolvedTargetVersion} \
Expand Down Expand Up @@ -358,6 +358,21 @@ The helper creates a private no-follow capture, rejects unsafe final destination
launch, and atomically publishes only after rechecking them. Unrecognized prior raw artifacts
require human archival before retry. Failed captures retain private audit files for human
review; never consume a stale report. Exit 0 means capture completed, not a clean UCT scan.
**Mutagen sync:** when UCT runs inside the container in file mode, Mutagen replaces the
container-written capture file on the host. The helper then fails in "capture validation" with
"capture path changed" (new inode) or "empty UCT report" (sync not yet delivered), even though the
scan succeeded. Every file-mode command that runs UCT inside the container (Composer mode and
Standalone fallback mode, i.e. the `{containerPrefix}` modes) therefore passes `--mutagen-flush`: after the
scan the helper flushes the single active Mutagen session whose alpha path is the project root
(`mutagen sync list` / `mutagen sync flush`), then re-opens the synced capture file no-follow inside its
private 0700 folder and validates it as a regular single-link file. When Mutagen is not installed or no
session syncs the project, the flag does nothing and the strict descriptor check applies unchanged, so keep
it in those commands for every Docker type. Always include it exactly as shown; omitting it reproduces the
failure on Mutagen-synced projects (Warden). Stdout mode (in-project `bin/magento`) and External runner mode
write directly on the host and do not need it. Alternative: keep `.claude/context/.uct-capture-*`
(or `.github/context/...`) out of Mutagen sync. Never bypass or weaken the capture check otherwise.
Name `mutagen sync list` and `mutagen sync flush` (run by the helper itself, read-only/forced sync cycle,
no config change) in the live approval's routine command list for these modes.
The helper executes approved argv without a shell; it is not a sandbox or consent mechanism
and cannot restrict filesystem authority of malicious project code or same-user attackers.

Expand Down
3 changes: 2 additions & 1 deletion .github/instructions/write-scope.instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ every item filled from live detection, not placeholders:
1. the exact instance: project path, container name and `containerPrefix`/runner, hosting profile;
2. the version pair (and hop plan, if one exists);
3. the routine commands about to run, listed individually (for example the `next-steps` helper,
`bin/magento --version`, the UCT probe/scan, normalization, `composer_probe.py`);
`bin/magento --version`, the UCT probe/scan, normalization, `composer_probe.py`; for scans run inside
the container also the helper's own `mutagen sync list` and `mutagen sync flush <session>`);
4. the ambient developer mounts the environment reports (for example Warden's host `~/.composer`,
the SSH volume, `ssh-auth.sock`), with the statement that they will not be read;
5. the standing profile: local/dev non-production, no production credentials or access;
Expand Down
46 changes: 46 additions & 0 deletions .github/scripts/capture_uct.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import hashlib
import json
import os
import re
import secrets
import stat
import subprocess
Expand Down Expand Up @@ -55,6 +56,33 @@ def read_capture(descriptor):
return raw


def mutagen_flush(root):
"""Flush the one Mutagen session that syncs this project root so container writes reach the host.

Returns False (nothing to do) when Mutagen is not installed or no active session syncs the root,
so the flag is safe to pass on every container-run scan."""
try:
listing = subprocess.run(["mutagen", "sync", "list", "--template", "{{json .}}"],
stdin=subprocess.DEVNULL, capture_output=True, timeout=60, check=False)
except FileNotFoundError:
return False
if listing.returncode != 0:
raise ValueError("mutagen session list failed")
sessions = json.loads(listing.stdout or b"[]")
matches = [item.get("identifier") for item in sessions
if os.path.realpath(item.get("alpha", {}).get("path", "")) == os.path.realpath(root)
and not item.get("paused")]
if not matches:
return False
if len(matches) != 1 or not re.fullmatch(r"sync_[A-Za-z0-9]{10,64}", str(matches[0])):
raise ValueError("expected exactly one active mutagen session for the project root")
flushed = subprocess.run(["mutagen", "sync", "flush", matches[0]], stdin=subprocess.DEVNULL,
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=300, check=False)
if flushed.returncode != 0:
raise ValueError("mutagen sync flush failed")
return True


def raw_state(directory):
try:
metadata = os.stat(REPORT, dir_fd=directory, follow_symlinks=False)
Expand Down Expand Up @@ -86,6 +114,10 @@ def main():
parser.add_argument("--project-root", default=".")
parser.add_argument("--agent", choices=("claude-code", "github-copilot"), required=True)
parser.add_argument("--mode", choices=("stdout", "file"), required=True)
parser.add_argument("--mutagen-flush", action="store_true",
help="after a file-mode scan run in a container, flush the project's Mutagen sync "
"session and adopt the synced capture file (no-follow, regular, single link); "
"does nothing when Mutagen is not installed or no session syncs the project")
parser.add_argument("command", nargs=argparse.REMAINDER)
args = parser.parse_args()
descriptors = []
Expand All @@ -99,6 +131,8 @@ def main():
if not command:
raise ValueError("missing approved command argv")
outputs = [arg for arg in command if arg.startswith("--json-output-path")]
if args.mutagen_flush and args.mode != "file":
raise ValueError("--mutagen-flush applies to file mode only")
if outputs != ([PLACEHOLDER] if args.mode == "file" else []):
raise ValueError("only the private output placeholder is permitted")
root = os.path.abspath(args.project_root)
Expand Down Expand Up @@ -127,6 +161,13 @@ def main():
if result.returncode != 0:
print("UCT command exit status: " + str(result.returncode), file=sys.stderr)
raise ValueError("scan command failed")
if args.mutagen_flush:
phase = "sync flush"
if mutagen_flush(root):
# Mutagen replaces the file with a new inode; re-open it no-follow inside the private
# 0700 directory and validate it as a regular single-link file instead of the old descriptor.
capture_fd = os.open("report.json", os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK, dir_fd=temporary_fd)
descriptors.append(capture_fd)
phase = "capture validation"
current = os.stat("report.json", dir_fd=temporary_fd, follow_symlinks=False)
if not stat.S_ISREG(current.st_mode) or identity(current) != identity(os.fstat(capture_fd)):
Expand Down Expand Up @@ -161,6 +202,11 @@ def main():
except (OSError, ValueError, RecursionError):
print("UCT capture failed during " + phase + ". Stop; do not consume a previous report.",
file=sys.stderr)
if phase == "capture validation" and args.mode == "file":
print("If UCT ran in a container with a file-sync tool such as Mutagen, the sync may "
"have replaced the capture file (new inode) or not delivered it yet (empty report). "
"Retry with --mutagen-flush, exclude " + context + "/.uct-capture-* from sync, or run UCT "
"through uct_runner.py on the host; the check is intentional and is not bypassed.", file=sys.stderr)
if private and not published:
print("Private audit capture retained for human review: " + private, file=sys.stderr)
if published:
Expand Down
19 changes: 17 additions & 2 deletions .github/skills/uct-install/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ python3 .github/scripts/capture_uct.py --project-root . --agent github-copilot -
**Composer mode** (use the live-reviewed `bin-dir` path if it differs from `vendor/bin`):

```bash
python3 .github/scripts/capture_uct.py --project-root . --agent github-copilot --mode file -- \
python3 .github/scripts/capture_uct.py --project-root . --agent github-copilot --mode file --mutagen-flush -- \
{containerPrefix} php -d memory_limit=-1 vendor/bin/uct upgrade:check . \
--current-version={installedVersion} \
--coming-version={resolvedTargetVersion} \
Expand Down Expand Up @@ -327,7 +327,7 @@ edition is inferred automatically from the target directory's own installed pack
branch needs no separate cloud/enterprise/community handling):

```bash
python3 .github/scripts/capture_uct.py --project-root . --agent github-copilot --mode file -- \
python3 .github/scripts/capture_uct.py --project-root . --agent github-copilot --mode file --mutagen-flush -- \
{containerPrefix} php -d memory_limit=-1 {uctStandalonePath}/bin/uct upgrade:check . \
--current-version={installedVersion} \
--coming-version={resolvedTargetVersion} \
Expand Down Expand Up @@ -363,6 +363,21 @@ The helper creates a private no-follow capture, rejects unsafe final destination
launch, and atomically publishes only after rechecking them. Unrecognized prior raw artifacts
require human archival before retry. Failed captures retain private audit files for human
review; never consume a stale report. Exit 0 means capture completed, not a clean UCT scan.
**Mutagen sync:** when UCT runs inside the container in file mode, Mutagen replaces the
container-written capture file on the host. The helper then fails in "capture validation" with
"capture path changed" (new inode) or "empty UCT report" (sync not yet delivered), even though the
scan succeeded. Every file-mode command that runs UCT inside the container (Composer mode and
Standalone fallback mode, i.e. the `{containerPrefix}` modes) therefore passes `--mutagen-flush`: after the
scan the helper flushes the single active Mutagen session whose alpha path is the project root
(`mutagen sync list` / `mutagen sync flush`), then re-opens the synced capture file no-follow inside its
private 0700 folder and validates it as a regular single-link file. When Mutagen is not installed or no
session syncs the project, the flag does nothing and the strict descriptor check applies unchanged, so keep
it in those commands for every Docker type. Always include it exactly as shown; omitting it reproduces the
failure on Mutagen-synced projects (Warden). Stdout mode (in-project `bin/magento`) and External runner mode
write directly on the host and do not need it. Alternative: keep `.github/context/.uct-capture-*`
(or `.github/context/...`) out of Mutagen sync. Never bypass or weaken the capture check otherwise.
Name `mutagen sync list` and `mutagen sync flush` (run by the helper itself, read-only/forced sync cycle,
no config change) in the live approval's routine command list for these modes.
The helper executes approved argv without a shell; it is not a sandbox or consent mechanism
and cannot restrict filesystem authority of malicious project code or same-user attackers.

Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ Release history for `@adobe/commerce-upgrade-toolkit`.
- Assessment tables use the full available width (fluid container, scrollable wrapper, no-wrap short columns); the Third-Party chapter shows Composer, Commerce (UCT) and PHP as separate columns.
- Unchanged: exact-diff approval for code edits, security review, encryption human gates, quarantine blockers, explicit approval for the UCT install.

## [1.0.13]

- Fix `capture_uct.py` rejecting a valid UCT report when UCT runs inside the project container on a Mutagen-synced project. Mutagen replaces the container-written capture file on the host (new inode, or not yet delivered), so the helper failed in "capture validation" with "capture path changed" or "empty UCT report" although the scan succeeded.
- Add an opt-in `--mutagen-flush` flag (file mode only): after the scan the helper flushes the single active Mutagen session whose alpha path is the project root (`mutagen sync list` / `mutagen sync flush`), then re-opens the synced capture file no-follow inside its private 0700 folder and validates it as a regular single-link file. When Mutagen is not installed or no session syncs the project, the flag does nothing and the strict descriptor/inode check applies unchanged. Without the flag the strict check is unchanged.
- The `uct-install` Composer and Standalone fallback commands (the modes that run UCT inside the container) now pass `--mutagen-flush`, so `/upgrade-hop` and `/upgrade-assess` get the fix automatically; stdout and external-runner modes do not need it. The approval's routine command list names the two `mutagen sync` commands the helper runs for container scans.
- Failures in the capture-validation phase now print an actionable hint (retry with `--mutagen-flush`, exclude the capture folder from sync, or run UCT through `uct_runner.py`). `uct-install` documents the Mutagen behaviour and options.
- Add tests for the flush path (fake `mutagen`) and for rejecting the flag outside file mode.
- No change to approval, write-scope, encryption or sensitive-action gates.

## [1.0.12]

- Consolidate `/upgrade-assess`, the `upgrade-assessment` skill and the assessment workflow into a single `/upgrade-assessment` command. The assessment report is now HTML only: the Markdown twin, the human-run PDF/DOCX runbook and `scripts/export-assessment.mjs` (`npm run export:assessment`) are removed. The `/upgrade-hop` pre-hop client PDF is unchanged.
Expand Down
Loading