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
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ jobs:
--python "$wheel_python" --expected-version "$expected"
python "$GITHUB_WORKSPACE/scripts/run_cursor_coverage_demo.py" \
--python "$wheel_python" --output "$RUNNER_TEMP/cursor-coverage-demo.json"
python "$GITHUB_WORKSPACE/scripts/run_approval_demo.py" \
--python "$wheel_python" --output-dir "$RUNNER_TEMP/approval-demo"
- name: Retain the deletion approval replay
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: approval-demo-${{ matrix.os }}
path: ${{ runner.temp }}/approval-demo/
if-no-files-found: error
retention-days: 7
- name: Retain the installed coverage demo evidence
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ decisions. No model API or runtime dependencies are needed.

[Setup demo](#quick-start) · [Workflow diagram](#what-it-helps-you-review) · [Score history demo](#score-history-demo) · [Visual gallery](https://github.com/LE0-Lin/AgentConfigScore/blob/main/docs/visual-tour.md)

[Deletion approval prototype](https://github.com/LE0-Lin/AgentConfigScore/blob/main/docs/ai-safety-challenge.md):
replay a lost approval requirement, repair its coverage, and try a separate
approval-gated executor on disposable files. Includes scripted cases and explicit host trust boundaries.

The demo uses v0.24.0 on a local fixture. Adding a remote-shell instruction
lowers the score from 100 to 82, identifies `AGENTS.md:5`, and fails the
new-error gate. The gallery also includes an instruction move drawn from a
Expand Down
2 changes: 2 additions & 0 deletions README.simplified.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

[安装演示](#快速开始) · [分数历史演示](#分数历史演示) · [完整演示图集](docs/visual-tour.md)

[删除审批原型](docs/ai-safety-challenge.md):复跑审批要求失去覆盖、修复覆盖的配置检查,再体验独立示例执行器对临时文件的审批与删除。包含脚本化案例和明确的宿主信任边界。

演示使用 v0.24.0 扫描本地样例。新增远程脚本指令后,分数从 100 降到 82,工具定位到 `AGENTS.md:5`,新增错误门禁返回 1。图集还保留了取材自已合并 PR 的文件迁移演示,展示前后同为 100 分时的路径复核。[复跑精简 PR 案例](examples/instruction-move/README.md)。

AgentConfigScore 检查 `AGENTS.md`、`CLAUDE.md`、Cursor、Copilot、Gemini 等配置,并比较改动前后的基线,回答一个具体问题:**这次改动是否引入了已知规则能检测到的风险?**
Expand Down
2 changes: 2 additions & 0 deletions README.traditional.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

[安裝示範](#快速開始) · [分數歷史示範](#分數歷史示範) · [完整示範圖集](docs/visual-tour.md)

[刪除審批原型](docs/ai-safety-challenge.md):重現審批要求失去涵蓋、修復涵蓋的設定檢查,再體驗獨立範例執行器對暫存檔案的審批與刪除。包含指令碼化案例與明確的主機信任邊界。

示範使用 v0.24.0 掃描本機範例。新增遠端指令碼指令後,分數從 100 降到 82,工具定位到 `AGENTS.md:5`,新增錯誤閘門回傳 1。圖集也保留了取材自已合併 PR 的檔案移動示範,展示前後同為 100 分時的路徑審閱。[重現精簡 PR 範例](examples/instruction-move/README.md)。

AgentConfigScore 檢查 `AGENTS.md`、`CLAUDE.md`、Cursor、Copilot、Gemini 等設定,並與改動前的基準比較,回答一個具體問題:**這次改動是否引入了已知規則能偵測到的風險?**
Expand Down
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ read the result, and troubleshoot a failing gate.
- [Maintainer setup, actionable next steps and PR results](maintainer-workflow.md) (v0.24.0+)
- [Unscored instruction-file best-practice checklist](best-practices.md)
- [Visual tour](visual-tour.md)
- [Deletion approval prototype: configuration review and a separate host gate](ai-safety-challenge.md)
- [Instruction templates](../examples/README.md)
- [Opt-in deletion safeguard review and completion](guardrail-suggestions.md) (v0.24.0+)
- [Cursor rule activation for declared file context](cursor-scope.md) (v0.25.0+, unscored)
Expand Down
89 changes: 89 additions & 0 deletions docs/ai-safety-challenge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Preserve a deletion approval requirement across a change

**A reproducible prototype for reviewing a configuration regression and refusing
an unapproved tool operation.** The example combines the released ACS static
checker with a small, separate host executor operating on real disposable files.

```mermaid
flowchart LR
A[Rule glob changes] --> B[Installed ACS comparison]
B --> C[Lost active directive: review fails]
C --> D[Restore target coverage: review passes]
E[Agent delete_file request] --> F[Host approval gate]
G[Trusted operator issues scoped approval] --> F
F --> H[Missing or invalid approval: refuse]
F --> I[Matching approval: delete one temporary file]
```

## 1. Catch the configuration regression

The baseline rule is `.cursor/rules/deletion.mdc`:

```markdown
---
globs: "workspace/**"
alwaysApply: false
---
Never delete files without approval.
```

The candidate changes only line 2 to `globs: "docs/**"`. The instruction still
exists, and both scans score 100, but it no longer covers the declared target
`workspace/obsolete.txt`. Installed ACS v0.26.1 reports one recognized active
directive lost, with the original source at line 5, and exits 1 under the
explicit `--fail-on-lost-directives --fail-on-unknown` review policy. Restoring
coverage exits 0. This is a bounded attachment prediction, not an observation of
the model's context or a claim that the model will comply.

## 2. Gate the tool operation before its effect

The host owns a temporary workspace and exposes one operation: `delete_file`.
A separate operator interface issues an opaque, expiring, single-use approval
bound to the exact relative path and reviewed file state. The agent cannot
authorize itself by adding `approved: true`. It can present an issued token;
the host looks up the grant and validates it before calling single-file unlink.

The console lets a person approve or refuse a disposable-file deletion. The
automated replay simulates the operator with a trusted harness and exercises
12 scripted tool-request scenarios. It verifies real filesystem outcomes,
including a valid deletion, refused repetition and preservation of unrelated
files. These are known development cases, not live-agent or independent
accuracy measurements.

## Run and inspect

Clone [the repository](https://github.com/LE0-Lin/AgentConfigScore), then:

```bash
python -m pip install agent-config-score==0.26.1
python scripts/run_approval_demo.py --output-dir approval-demo-result
python examples/approval-gate/try_gate.py
```

The output directory must be new. The first command sequence produces full JSON
and Markdown evidence. The last command opens the local operator console;
only freshly created demo files can be deleted. Normal temporary-directory
cleanup follows either an approved operation or refusal.

- [Retained replay with installed source identity](../examples/approval-gate/recorded/result.md)
- [Full JSON: static source lines, execution decisions and input hashes](../examples/approval-gate/recorded/result.json)
- [Executor, API contract, tests and trust boundary](../examples/approval-gate/README.md)
- [Gate regression tests](../tests/test_approval_gate_demo.py)
- [Cross-platform installed-wheel CI](../.github/workflows/ci.yml)

## Scope of the prototype

The contribution is a reviewable link between an existing configuration
regression check and a minimal approval-gated operation, with failure and repair
controls. ACS remains a static CLI and CI gate. The executor is separate
repository example code; installing ACS does not intercept agent actions.

The host must keep the workspace stable and deny the agent other filesystem or
code-execution channels. This is not an OS sandbox or a defense against a
concurrent attacker changing paths between checks and unlink. Operator
authentication and a secure approval interface belong to the real host. Only
one regular file up to 1 MiB is supported; approval state is process-local.

The existing [native Cursor smoke test](../benchmarks/cursor-native-v1/README.md)
is separate evidence about selected rule-marker behavior. It does not validate
this executor or turn these scripted scenarios into real-world safety results.
5 changes: 5 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Copy-ready instruction examples

For an approval-gated operation alongside configuration review, try the
[deletion approval prototype](approval-gate/README.md). Its separate host
executor operates only on disposable files in the demo; it does not add runtime
interception to the ACS package.

For a runnable explanation of the regression gate rather than an instruction
template, see the [design lab](regression-lab/README.md). It compares five known
synthetic before/after scenarios under three explicitly defined gate settings;
Expand Down
112 changes: 112 additions & 0 deletions examples/approval-gate/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Deletion approval: configuration review and execution

This prototype pairs two separately enforced checks:

1. Installed **ACS v0.26.1** reviews a Cursor rule change. Narrowing the glob
stops the declared deletion-approval instruction from covering the selected
target. Both standalone scores remain 100; the opt-in review exits 1.
2. The independent example host executor in [gate.py](gate.py) refuses a
`delete_file` request until it has matching operator approval. It checks the
actual filesystem after each scripted request.

The runnable example uses local temporary files, no model API, no network and
no new runtime dependencies. See the [challenge walkthrough](../../docs/ai-safety-challenge.md)
and [recorded replay](recorded/result.md).

## Try the operator console

From a checkout of this repository, using Python 3.10+:

```bash
python examples/approval-gate/try_gate.py
```

The first request is refused. The console then shows the disposable file and
asks the operator to type `DELETE`. Refusal leaves the file present until normal
temporary-workspace cleanup. Approval actually deletes that one file. Existing
user paths cannot be supplied to this console. The operator console must remain
outside the agent's tool access.

## Reproduce both layers

Install ACS in your selected Python environment, then run from the checkout:

```bash
python -m pip install agent-config-score==0.26.1
python scripts/run_approval_demo.py --output-dir approval-demo-result
```

`approval-demo-result` must not exist. Use `--python /absolute/path/to/python`
when ACS is installed in another environment. The subprocess uses isolated
Python from a temporary working directory, so repository sources cannot silently
replace the installed ACS. It is offline after installation. The example and
runner are repository files, separate from the installed wheel.

Completion writes `result.json` with installed source identity, normalized-text
SHA-256 input hashes, full static comparisons and execution decisions, plus
`result.md` for reading. Exit 0 means the registered synthetic scenarios and
their filesystem postconditions matched; exit 2 means replay or output failed.
Do not treat a partial output directory after failure as completed evidence.

The 12 scripted execution scenarios cover missing approval, self-approval,
invented tokens, expiry, target mismatch, changed content, file replacement,
different sessions, traversal, unregistered tools, authorized deletion and replay.
Approvals in this replay come from the **trusted test harness**, not a human or
a live agent. Two files are actually deleted: the authorized case and the replay
setup. Every scenario checks that unrelated sentinels are preserved.

```bash
python -m unittest discover -s tests -p test_approval_gate_demo.py -v
```

Additional tests cover root/parent replacement, hard links, symbolic links when
permitted, invalid lifetimes, size limits and filesystem failure. A filesystem
error returns `error` with `executed: null` (outcome requires inspection), not a
successful refusal. Once execution is attempted, that grant is consumed even on
an I/O error; another attempt requires fresh approval.

## Approval contract

The trusted host obtains separate operator and tool handles:

```python
operator, delete_file = create_session(disposable_workspace)
# Operator reviews the proposed relative path and file content outside agent access.
token = operator.approve("obsolete.txt", ttl_seconds=30)
result = delete_file({"tool": "delete_file", "path": "obsolete.txt", "approval": token})
```

Only `delete_file` belongs in the agent registry. `Operator.approve` is the
trusted issuance API; it does not itself authenticate a human. The host must
perform that authentication/review before calling it. `approved: true` is
rejected. An opaque token is bound to the session, exact portable relative path,
parent identities, file identity, size, modification time, content digest,
host-clock expiry (maximum 60 seconds) and one attempt. POSIX ctime is also
checked; Python 3.12 exposes differing legacy ctime semantics on Windows, so
Windows uses the other recorded signals. No raw token is written to reports.

## Trust boundary and limitations

- **Exclusively owned, stable local workspace.** No other process may mutate
files or ancestors during approval/execution. Python checks followed by unlink
are not an atomic defense against hostile concurrent filesystem changes.
The lock serializes this example's own operations only.
- **Tool-only agent access.** The agent cannot execute arbitrary Python, run a
shell, access host filesystem APIs, inspect operator state or call another
deletion channel. In-process Python handles are not a security isolation
boundary. A real deployment must enforce this separation outside agent control.
- **One regular file.** The gate refuses directories, recursive deletion,
symlinks/reparse points, hard links, nonportable paths and files above 1 MiB.
It is intentionally unsuitable as a general file-management API.
- **Process-local grants.** Restart forgets approvals. Persistent identity,
distributed execution, signed audit storage, approval UI security, OS sandboxing
and adversarial races are not implemented.
- **Separate layers.** Static ACS predicts declared instruction availability;
it does not inspect these calls or prove the agent followed the instruction.
This example enforces approval only for its registered operation. Rule text
is never evaluated as executable policy. The wrapper is not a shipped ACS
runtime capability.

These are development controls, not independent accuracy evidence or a claim
that arbitrary irreversible actions are prevented. Production adoption needs
review of the host, its tools, approver authentication and execution boundary.
5 changes: 5 additions & 0 deletions examples/approval-gate/config/base/.cursor/rules/deletion.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
globs: "workspace/**"
alwaysApply: false
---
Never delete files without approval.
1 change: 1 addition & 0 deletions examples/approval-gate/config/base/workspace/obsolete.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Disposable fixture content. The static comparison does not delete this file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
globs: "docs/**"
alwaysApply: false
---
Never delete files without approval.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Disposable fixture content. The static comparison does not delete this file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
globs: "workspace/**"
alwaysApply: false
---
Never delete files without approval.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Disposable fixture content. The static comparison does not delete this file.
Loading
Loading