Skip to content

Commit 8ba001b

Browse files
committed
move to tool
1 parent a93ecd5 commit 8ba001b

25 files changed

Lines changed: 32 additions & 28 deletions

docs/mkdocs/en/tool_safety_guard.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ permissions, and runtime resource limits.
6262

6363
```bash
6464
python scripts/tool_safety_check.py \
65-
--policy examples/tool_safety/tool_safety_policy.yaml \
65+
--policy tool/safety/examples/tool_safety_policy.yaml \
6666
--language python \
67-
--script-file examples/tool_safety/samples/03_dangerous_delete.py \
67+
--script-file tool/safety/examples/samples/03_dangerous_delete.py \
6868
--output tool_safety_report.json \
6969
--audit-file tool_safety_audit.jsonl
7070
echo $? # 0=allow, 2=deny, 3=review, 4=input/policy error
@@ -74,10 +74,10 @@ Run the manifest to scan all 14 public samples:
7474

7575
```bash
7676
python scripts/tool_safety_check.py \
77-
--policy examples/tool_safety/tool_safety_policy.yaml \
78-
--manifest examples/tool_safety/samples/manifest.yaml \
79-
--manifest-output examples/tool_safety/manifest_run.json \
80-
--audit-file examples/tool_safety/tool_safety_audit.jsonl
77+
--policy tool/safety/examples/tool_safety_policy.yaml \
78+
--manifest tool/safety/examples/samples/manifest.yaml \
79+
--manifest-output tool/safety/examples/manifest_run.json \
80+
--audit-file tool/safety/examples/tool_safety_audit.jsonl
8181
```
8282

8383
## Programmatic usage
@@ -90,7 +90,7 @@ from tool.safety import (
9090
ScriptLanguage,
9191
)
9292

93-
policy = load_safety_policy("examples/tool_safety/tool_safety_policy.yaml")
93+
policy = load_safety_policy("tool/safety/examples/tool_safety_policy.yaml")
9494
guard = ToolSafetyGuard(policy)
9595

9696
request = SafetyScanRequest(
@@ -397,7 +397,7 @@ tool/
397397
scripts/
398398
tool_safety_check.py # CLI
399399
tests/tool_safety/ # safety guard tests
400-
examples/tool_safety/
400+
tool/safety/examples/
401401
tool_safety_policy.yaml # sample policy
402402
samples/ # 14 public samples + manifest
403403
tool_safety_report.json # generated report

docs/mkdocs/zh/tool_safety_guard.zh_CN.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ span 属性/指标输出。
5353

5454
```bash
5555
python scripts/tool_safety_check.py \
56-
--policy examples/tool_safety/tool_safety_policy.yaml \
56+
--policy tool/safety/examples/tool_safety_policy.yaml \
5757
--language python \
58-
--script-file examples/tool_safety/samples/03_dangerous_delete.py \
58+
--script-file tool/safety/examples/samples/03_dangerous_delete.py \
5959
--output tool_safety_report.json \
6060
--audit-file tool_safety_audit.jsonl
6161
echo $? # 0=allow, 2=deny, 3=review, 4=输入/策略/必需审计错误
@@ -65,10 +65,10 @@ echo $? # 0=allow, 2=deny, 3=review, 4=输入/策略/必需审计错误
6565

6666
```bash
6767
python scripts/tool_safety_check.py \
68-
--policy examples/tool_safety/tool_safety_policy.yaml \
69-
--manifest examples/tool_safety/samples/manifest.yaml \
70-
--manifest-output examples/tool_safety/manifest_run.json \
71-
--audit-file examples/tool_safety/tool_safety_audit.jsonl
68+
--policy tool/safety/examples/tool_safety_policy.yaml \
69+
--manifest tool/safety/examples/samples/manifest.yaml \
70+
--manifest-output tool/safety/examples/manifest_run.json \
71+
--audit-file tool/safety/examples/tool_safety_audit.jsonl
7272
```
7373

7474
## 作为库使用
@@ -81,7 +81,7 @@ from tool.safety import (
8181
ScriptLanguage,
8282
)
8383

84-
policy = load_safety_policy("examples/tool_safety/tool_safety_policy.yaml")
84+
policy = load_safety_policy("tool/safety/examples/tool_safety_policy.yaml")
8585
guard = ToolSafetyGuard(policy)
8686

8787
request = SafetyScanRequest(
@@ -351,7 +351,7 @@ tool/
351351
scripts/
352352
tool_safety_check.py # CLI
353353
tests/tool_safety/ # 安全检查器测试
354-
examples/tool_safety/ # 策略、14 个样例、报告和审计样例
354+
tool/safety/examples/ # 策略、14 个样例、报告和审计样例
355355
docs/
356356
tool_safety_guard.md # English version
357357
tool_safety_guard.zh_CN.md # 本文

scripts/tool_safety_check.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Usage::
44
55
python scripts/tool_safety_check.py \\
6-
--policy examples/tool_safety/tool_safety_policy.yaml \\
6+
--policy tool/safety/examples/tool_safety_policy.yaml \\
77
--language python \\
88
--script-file path/to/script.py \\
99
--tool-name demo

tests/tool_safety/test_cli.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
REPO_ROOT = Path(__file__).resolve().parents[2]
1313
CLI = REPO_ROOT / "scripts" / "tool_safety_check.py"
14-
POLICY = REPO_ROOT / "examples" / "tool_safety" / "tool_safety_policy.yaml"
14+
POLICY = REPO_ROOT / "tool" / "safety" / "examples" / "tool_safety_policy.yaml"
1515

1616

1717
def _run_cli(*args: str) -> tuple[int, str, str]:
@@ -52,11 +52,15 @@ def test_review_exit_3():
5252

5353

5454
def test_invalid_policy_exit_4(tmp_path):
55-
cmd = [sys.executable, str(CLI), "--policy",
56-
str(tmp_path / "missing.yaml"), "--script", "print(1)"]
55+
missing_policy = tmp_path / "missing.yaml"
56+
cmd = [sys.executable, str(CLI), "--policy", str(missing_policy),
57+
"--script", "print(1)"]
5758
proc = subprocess.run(cmd, capture_output=True, text=True,
5859
cwd=str(REPO_ROOT))
5960
assert proc.returncode == 4
61+
assert "policy error:" in proc.stderr
62+
assert str(missing_policy) in proc.stderr
63+
assert proc.stdout == ""
6064

6165

6266
def test_required_audit_failure_exits_4(tmp_path):
@@ -70,7 +74,7 @@ def test_required_audit_failure_exits_4(tmp_path):
7074

7175

7276
def test_manifest_writes_output(tmp_path):
73-
manifest = REPO_ROOT / "examples" / "tool_safety" / "samples" / "manifest.yaml"
77+
manifest = REPO_ROOT / "tool" / "safety" / "examples" / "samples" / "manifest.yaml"
7478
output = tmp_path / "out.json"
7579
audit = tmp_path / "audit.jsonl"
7680
cmd = [sys.executable, str(CLI), "--policy", str(POLICY),

tests/tool_safety/test_integration.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Integration tests: manifest samples must match expected decisions.
22
33
These tests verify the public manifest in
4-
``examples/tool_safety/samples/manifest.yaml``. Per the issue acceptance
4+
``tool/safety/examples/samples/manifest.yaml``. Per the issue acceptance
55
criteria: every sample must produce a structured report, high-risk
66
detection must be >= 90%, safe false positives <= 10%, and the
77
key-credential-delete-non-allowlist categories must be 100%.
@@ -20,8 +20,8 @@
2020

2121

2222
REPO_ROOT = Path(__file__).resolve().parents[2]
23-
POLICY_PATH = REPO_ROOT / "examples" / "tool_safety" / "tool_safety_policy.yaml"
24-
MANIFEST_PATH = REPO_ROOT / "examples" / "tool_safety" / "samples" / "manifest.yaml"
23+
POLICY_PATH = REPO_ROOT / "tool" / "safety" / "examples" / "tool_safety_policy.yaml"
24+
MANIFEST_PATH = REPO_ROOT / "tool" / "safety" / "examples" / "samples" / "manifest.yaml"
2525

2626

2727
@pytest.fixture(scope="module")
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ and the generated report / audit outputs.
3131

3232
```bash
3333
# Single sample
34-
python ../../scripts/tool_safety_check.py \
34+
python ../../../scripts/tool_safety_check.py \
3535
--policy tool_safety_policy.yaml \
3636
--language python \
3737
--script-file samples/03_dangerous_delete.py \
@@ -40,7 +40,7 @@ python ../../scripts/tool_safety_check.py \
4040
echo $? # 0=allow, 2=deny, 3=review, 4=input/policy error
4141

4242
# All 14 samples
43-
python ../../scripts/tool_safety_check.py \
43+
python ../../../scripts/tool_safety_check.py \
4444
--policy tool_safety_policy.yaml \
4545
--manifest samples/manifest.yaml \
4646
--manifest-output manifest_run.json \
@@ -58,5 +58,5 @@ python ../../scripts/tool_safety_check.py \
5858
samples.
5959

6060
See the full design document in
61-
[English](../../docs/tool_safety_guard.md) or
62-
[中文](../../docs/tool_safety_guard.zh_CN.md).
61+
[English](../../../docs/mkdocs/en/tool_safety_guard.md) or
62+
[中文](../../../docs/mkdocs/zh/tool_safety_guard.zh_CN.md).
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)