Skip to content

Commit 7b6a89a

Browse files
RBridCopilot
andcommitted
Merge branch 'master' into user/rbrid/VirtualizationOffMessageOnArm2
Co-authored-by: Copilot <[email protected]>
2 parents 8c84814 + 99efc50 commit 7b6a89a

100 files changed

Lines changed: 12758 additions & 3145 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.agents/skills/autoreview/SKILL.md‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ Format first if formatting can change line locations. Then it is OK to run tests
103103
scripts/autoreview --parallel-tests "<focused test command>"
104104
```
105105

106+
On Windows, the default `--parallel-tests` shell preserves the platform `cmd.exe`
107+
semantics used by Python `shell=True`. Use `--parallel-tests-shell powershell`
108+
or `--parallel-tests-shell pwsh` when the focused test command is PowerShell-specific.
109+
106110
Tradeoff: tests may force code changes that stale the review. If tests or review lead to code edits, rerun the affected tests and rerun review until no accepted/actionable findings remain. Once that rerun exits cleanly, stop; do not spend another long review cycle on redundant confirmation.
107111

108112
## Review Panels
@@ -147,6 +151,22 @@ OpenClaw Windows Node repo-local helper:
147151
.agents/skills/autoreview/scripts/autoreview --help
148152
```
149153

154+
On native Windows, invoke the extensionless Python helper through Python:
155+
156+
```powershell
157+
python .agents\skills\autoreview\scripts\autoreview --help
158+
```
159+
160+
The smoke harness has thin shell wrappers over a shared Python implementation:
161+
162+
```bash
163+
.agents/skills/autoreview/scripts/test-review-harness --fixture benign --engine codex
164+
```
165+
166+
```powershell
167+
.agents\skills\autoreview\scripts\test-review-harness.ps1 -Fixture benign -Engine codex
168+
```
169+
150170
The helper:
151171

152172
- chooses dirty local changes first
@@ -157,7 +177,7 @@ The helper:
157177
- use `--mode commit --commit <ref>` for already-committed work, especially clean default-branch work after landing
158178
- should be left in `--mode auto` or forced to `--mode branch` for PR/branch work; do not force `--mode local` after committing
159179
- writes only to stdout unless `--output`, `--json-output`, or live streamed engine stderr is set
160-
- supports `--dry-run`, `--parallel-tests`, `--prompt`, `--prompt-file`, `--dataset`, `--no-tools`, `--no-web-search`, and commit refs
180+
- supports `--dry-run`, `--parallel-tests`, `--parallel-tests-shell`, `--prompt`, `--prompt-file`, `--dataset`, `--no-tools`, `--no-web-search`, and commit refs
161181
- supports `--stream-engine-output` or `AUTOREVIEW_STREAM_ENGINE_OUTPUT=1` for live engine text while preserving structured validation; Codex and Claude hide tool/file event details, emit compact activity summaries, and report usage at turn completion
162182
- supports opt-in review panels with `--panel` / `--reviewers`, plus per-engine `--model` and `--thinking`
163183
- allows read-only tools and web search by default only for sandboxed Codex review; forbids nested review in the prompt; Codex is run through `codex exec` with read-only sandbox and structured output

‎.agents/skills/autoreview/scripts/autoreview‎

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import json
88
import os
99
import queue
1010
import re
11+
import shutil
1112
import subprocess
1213
import sys
1314
import tempfile
@@ -283,19 +284,19 @@ def choose_target(repo: Path, mode: str, base_ref: str | None) -> tuple[str, str
283284

284285

285286
def detect_pr_base(repo: Path) -> str | None:
286-
if not shutil_which("gh"):
287+
gh_bin = shutil.which("gh")
288+
if not gh_bin:
287289
return None
288-
result = run(["gh", "pr", "view", "--json", "baseRefName", "--jq", ".baseRefName"], repo, check=False)
290+
result = run([gh_bin, "pr", "view", "--json", "baseRefName", "--jq", ".baseRefName"], repo, check=False)
289291
base = result.stdout.strip()
290292
return f"origin/{base}" if result.returncode == 0 and base else None
291293

292294

293-
def shutil_which(name: str) -> str | None:
294-
for part in os.environ.get("PATH", "").split(os.pathsep):
295-
candidate = Path(part) / name
296-
if candidate.exists() and os.access(candidate, os.X_OK):
297-
return str(candidate)
298-
return None
295+
def resolve_command(name: str) -> str:
296+
resolved = shutil.which(name)
297+
if resolved:
298+
return resolved
299+
raise SystemExit(f"review engine executable not found: {name}. Install it or pass the matching --*-bin option.")
299300

300301

301302
def bounded(text: str, limit: int = 180_000) -> str:
@@ -585,7 +586,7 @@ def sanitized_workspace(repo: Path, prefix: str = "autoreview") -> tempfile.Temp
585586
def run_codex(args: argparse.Namespace, repo: Path, prompt: str) -> str:
586587
if not args.tools:
587588
raise SystemExit("--no-tools is not supported by the Codex engine; use --engine claude --no-tools for a no-tools run")
588-
cmd = [args.codex_bin, "--ask-for-approval", "never"]
589+
cmd = [resolve_command(args.codex_bin), "--ask-for-approval", "never"]
589590
if args.web_search:
590591
cmd.append("--search")
591592
if args.model:
@@ -632,7 +633,7 @@ def run_codex(args: argparse.Namespace, repo: Path, prompt: str) -> str:
632633

633634
def run_claude(args: argparse.Namespace, repo: Path, prompt: str) -> str:
634635
cmd = [
635-
args.claude_bin,
636+
resolve_command(args.claude_bin),
636637
"--print",
637638
"--no-session-persistence",
638639
"--output-format",
@@ -674,7 +675,7 @@ def run_droid(args: argparse.Namespace, repo: Path, prompt: str) -> str:
674675
prompt_path = review_cwd / "prompt.txt"
675676
prompt_path.write_text(prompt)
676677
cmd = [
677-
args.droid_bin,
678+
resolve_command(args.droid_bin),
678679
"exec",
679680
"--cwd",
680681
str(review_cwd),
@@ -705,7 +706,7 @@ def run_copilot(args: argparse.Namespace, repo: Path, prompt: str) -> str:
705706
prompt_path.write_text(prompt)
706707
os.chmod(prompt_path, 0o600)
707708
cmd = [
708-
args.copilot_bin,
709+
resolve_command(args.copilot_bin),
709710
"-C",
710711
tempdir,
711712
"-p",
@@ -1071,9 +1072,23 @@ def print_report(report: dict[str, Any], *, label: str = "autoreview") -> None:
10711072
print(report["overall_explanation"])
10721073

10731074

1074-
def start_parallel_tests(command: str, repo: Path) -> tuple[subprocess.Popen, float]:
1075+
def start_parallel_tests(command: str, repo: Path, shell_kind: str) -> tuple[subprocess.Popen, float]:
10751076
print(f"tests: {command}")
1076-
return subprocess.Popen(command, cwd=repo, shell=True), time.time()
1077+
if shell_kind == "default" or shell_kind == "cmd":
1078+
return subprocess.Popen(command, cwd=repo, shell=True), time.time()
1079+
if shell_kind == "powershell":
1080+
powershell = shutil.which("powershell") or "powershell"
1081+
return subprocess.Popen(
1082+
[powershell, "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command", command],
1083+
cwd=repo,
1084+
), time.time()
1085+
if shell_kind == "pwsh":
1086+
pwsh = shutil.which("pwsh") or "pwsh"
1087+
return subprocess.Popen(
1088+
[pwsh, "-NoProfile", "-Command", command],
1089+
cwd=repo,
1090+
), time.time()
1091+
raise SystemExit(f"invalid --parallel-tests-shell/AUTOREVIEW_PARALLEL_TESTS_SHELL: {shell_kind}")
10771092

10781093

10791094
def finish_parallel_tests(proc: subprocess.Popen, started: float) -> int:
@@ -1118,6 +1133,12 @@ def parse_args() -> argparse.Namespace:
11181133
help="Stream review engine output while preserving buffered output for validation. Codex output is filtered to hide tool/file chatter.",
11191134
)
11201135
parser.add_argument("--parallel-tests", help="Run a test command concurrently with review; failure fails the helper.")
1136+
parser.add_argument(
1137+
"--parallel-tests-shell",
1138+
choices=["default", "cmd", "powershell", "pwsh"],
1139+
default=os.environ.get("AUTOREVIEW_PARALLEL_TESTS_SHELL", "default"),
1140+
help="Shell for --parallel-tests. Default preserves Python shell=True platform behavior; use powershell or pwsh for PowerShell-specific commands.",
1141+
)
11211142
parser.add_argument("--require-finding", action="append", default=[], help="Require finding text to contain this substring.")
11221143
parser.add_argument("--expect-findings", action="store_true", help="Treat findings as success; for harness acceptance tests.")
11231144
parser.add_argument("--dry-run", action="store_true")
@@ -1323,7 +1344,7 @@ def main() -> int:
13231344

13241345
tests_proc: tuple[subprocess.Popen, float] | None = None
13251346
if args.parallel_tests:
1326-
tests_proc = start_parallel_tests(args.parallel_tests, repo)
1347+
tests_proc = start_parallel_tests(args.parallel_tests, repo, args.parallel_tests_shell)
13271348
try:
13281349
if len(reviewers) == 1:
13291350
report = run_reviewer(reviewers[0], repo, prompt, changed_paths, args.require_finding)
Lines changed: 7 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -1,176 +1,16 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
usage() {
5-
cat <<'EOF'
6-
Usage: test-review-harness [--fixture malicious|benign] [--engine codex|claude|droid|copilot]...
7-
8-
Creates a temporary git repo with either a deliberately unsafe patch or a
9-
security-sensitive-but-safe patch, then verifies each selected engine through
10-
autoreview.
11-
Default engines: codex, claude.
12-
EOF
13-
}
14-
15-
engines=()
16-
fixture=malicious
17-
while [[ $# -gt 0 ]]; do
18-
case "$1" in
19-
--fixture)
20-
fixture=${2:-}
21-
shift 2
22-
;;
23-
--engine)
24-
engines+=("${2:-}")
25-
shift 2
26-
;;
27-
-h|--help)
28-
usage
29-
exit 0
30-
;;
31-
*)
32-
usage >&2
33-
exit 2
34-
;;
35-
esac
36-
done
37-
38-
case "$fixture" in
39-
malicious|benign) ;;
40-
*)
41-
usage >&2
42-
exit 2
43-
;;
44-
esac
45-
46-
if [[ ${#engines[@]} -eq 0 ]]; then
47-
engines=(codex claude)
48-
fi
49-
504
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
51-
repo=$(mktemp -d "${TMPDIR:-/tmp}/autoreview-fixture.XXXXXX")
52-
trap 'rm -rf "$repo"' EXIT
53-
54-
cd "$repo"
55-
git init --quiet
56-
git config user.name "Review Fixture"
57-
git config user.email "[email protected]"
58-
59-
if [[ "$fixture" == malicious ]]; then
60-
cat > app.js <<'EOF'
61-
export function uploadPath(name) {
62-
return `uploads/${name.replaceAll("/", "")}`;
63-
}
64-
65-
export function publicUser(user) {
66-
return { id: user.id, name: user.name };
67-
}
68-
EOF
69-
else
70-
cat > app.js <<'EOF'
71-
import path from "node:path";
72-
73-
const uploadsRoot = path.resolve("uploads");
74-
75-
function safeChildPath(root, name) {
76-
if (name.includes("/") || name.includes("\\") || name.includes("\0")) {
77-
throw new Error("invalid child name");
78-
}
79-
const resolved = path.resolve(root, name);
80-
if (!resolved.startsWith(root + path.sep)) throw new Error("path escaped root");
81-
return resolved;
82-
}
83-
84-
export function uploadPath(name) {
85-
return safeChildPath(uploadsRoot, name);
86-
}
5+
harness="$script_dir/test-review-harness.py"
876

88-
export function publicUser(user) {
89-
return { id: user.id, name: user.name };
90-
}
91-
EOF
7+
if command -v python3 >/dev/null 2>&1; then
8+
exec python3 "$harness" "$@"
929
fi
9310

94-
git add app.js
95-
git commit --quiet -m "initial safe version"
96-
97-
if [[ "$fixture" == malicious ]]; then
98-
cat > app.js <<'EOF'
99-
import { execSync } from "node:child_process";
100-
101-
export function uploadPath(name) {
102-
return `uploads/${name}`;
103-
}
104-
105-
export function deleteUpload(name) {
106-
return execSync(`rm -rf uploads/${name}`);
107-
}
108-
109-
export function publicUser(user) {
110-
return { id: user.id, name: user.name, password: user.password };
111-
}
112-
EOF
113-
else
114-
cat > app.js <<'EOF'
115-
import { execFile } from "node:child_process";
116-
import path from "node:path";
117-
import { promisify } from "node:util";
118-
119-
const uploadsRoot = path.resolve("uploads");
120-
const reposRoot = path.resolve("repos");
121-
const execFileAsync = promisify(execFile);
122-
123-
function safeChildPath(root, name) {
124-
if (name.includes("/") || name.includes("\\") || name.includes("\0")) {
125-
throw new Error("invalid child name");
126-
}
127-
const resolved = path.resolve(root, name);
128-
if (!resolved.startsWith(root + path.sep)) throw new Error("path escaped root");
129-
return resolved;
130-
}
131-
132-
function repoChildPath(root, name) {
133-
if (!/^[A-Za-z0-9._-]+$/.test(name)) throw new Error("invalid repo name");
134-
return safeChildPath(root, name);
135-
}
136-
137-
export function uploadPath(name) {
138-
return safeChildPath(uploadsRoot, name);
139-
}
140-
141-
export async function repoStatus(repoName) {
142-
const { stdout } = await execFileAsync("git", ["status", "--short"], {
143-
cwd: repoChildPath(reposRoot, repoName),
144-
encoding: "utf8",
145-
maxBuffer: 16 * 1024 * 1024,
146-
});
147-
return stdout;
148-
}
149-
150-
export function publicUser(user) {
151-
return { id: user.id, name: user.name };
152-
}
153-
154-
export function accountSettingsForOwner(user, requesterId) {
155-
if (String(requesterId) !== String(user.id)) throw new Error("forbidden");
156-
return { id: user.id, hasPassword: Boolean(user.passwordHash) };
157-
}
158-
EOF
11+
if command -v python >/dev/null 2>&1; then
12+
exec python "$harness" "$@"
15913
fi
16014

161-
for engine in "${engines[@]}"; do
162-
echo "== $engine =="
163-
if [[ "$fixture" == malicious ]]; then
164-
"$script_dir/autoreview" \
165-
--mode local \
166-
--engine "$engine" \
167-
--prompt "This is an acceptance test fixture. The changed app.js patch contains real security bugs. Review normally and report only actionable defects from the patch." \
168-
--require-finding "command" \
169-
--expect-findings
170-
else
171-
"$script_dir/autoreview" \
172-
--mode local \
173-
--engine "$engine" \
174-
--prompt "Security calibration fixture: this patch intentionally uses filesystem paths, async execFile, and owner-gated password-adjacent state safely. Do not flag legitimate shell/filesystem/auth-adjacent functionality unless there is a concrete exploitable risk in the diff."
175-
fi
176-
done
15+
echo "Python 3 is required to run test-review-harness." >&2
16+
exit 127
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
[CmdletBinding()]
2+
param(
3+
[ValidateSet('malicious', 'benign')]
4+
[string] $Fixture,
5+
6+
[ValidateSet('codex', 'claude', 'droid', 'copilot')]
7+
[string[]] $Engine,
8+
9+
[Alias('h')]
10+
[switch] $Help
11+
)
12+
13+
$ErrorActionPreference = 'Stop'
14+
15+
$Harness = Join-Path $PSScriptRoot 'test-review-harness.py'
16+
$ForwardedArgs = @()
17+
18+
if ($Help) {
19+
$ForwardedArgs += '--help'
20+
}
21+
22+
if ($PSBoundParameters.ContainsKey('Fixture')) {
23+
$ForwardedArgs += @('--fixture', $Fixture)
24+
}
25+
26+
if ($PSBoundParameters.ContainsKey('Engine')) {
27+
foreach ($SelectedEngine in $Engine) {
28+
$ForwardedArgs += @('--engine', $SelectedEngine)
29+
}
30+
}
31+
32+
$PyLauncher = Get-Command py -ErrorAction SilentlyContinue
33+
if ($null -ne $PyLauncher) {
34+
& $PyLauncher.Source -3 $Harness @ForwardedArgs
35+
exit $LASTEXITCODE
36+
}
37+
38+
$Python = Get-Command python -ErrorAction SilentlyContinue
39+
if ($null -ne $Python) {
40+
& $Python.Source $Harness @ForwardedArgs
41+
exit $LASTEXITCODE
42+
}
43+
44+
Write-Error 'Python 3 is required to run test-review-harness.'
45+
exit 127

0 commit comments

Comments
 (0)