Skip to content

Commit 3a76de8

Browse files
committed
Implement proposal apply gate and validation command (Phase 6)
1 parent d265c59 commit 3a76de8

7 files changed

Lines changed: 467 additions & 7 deletions

File tree

PROJEKT.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ CompText CLI is an experimental terminal context client for building determinist
1919

2020
### Current State
2121
```text
22-
CURRENT_PHASE: 6
23-
CURRENT_TASK: Apply Gate
24-
LAST_GREEN_PHASE: 5
22+
CURRENT_PHASE: 7
23+
CURRENT_TASK: Provider Config Layer
24+
LAST_GREEN_PHASE: 6
2525
STATUS: active
2626
```
2727

@@ -80,8 +80,8 @@ git push
8080
| **Phase 4B** | Skill Registry Normalization | Normalize the local Antigravity skill structure and crystallize autonomy rules | **COMPLETE** |
8181
| **Phase 4C** | Long-Run Autonomy Hardening | Harden state machine progression rules and git safety boundaries | **COMPLETE** |
8282
| **Phase 5** | Proposal Mode | Implement `ctxt propose` to output changes as structured proposals | **COMPLETE** |
83-
| **Phase 6** | Apply Gate | Implement `ctxt apply` to confirm/apply changes and run verification | **ACTIVE** |
84-
| **Phase 7** | Provider Config Layer | Support dynamic provider profile switching and configurations | *QUEUED* |
83+
| **Phase 6** | Apply Gate | Implement `ctxt apply` to confirm/apply changes and run verification | **COMPLETE** |
84+
| **Phase 7** | Provider Config Layer | Support dynamic provider profile switching and configurations | **ACTIVE** |
8585
| **Phase 8** | OpenAI-Compatible Adapter | Implement OpenAI adapter skeleton | *QUEUED* |
8686
| **Phase 9** | Validate and Benchmark | Local validation, dry-runs, and deterministic benchmark flows | *QUEUED* |
8787

docs/APPLY_GATE.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Apply Gate (Phase 6)
2+
3+
The Apply Gate protects the repository from untrusted code mutations generated by provider LLMs. It defines a strict boundary where proposed modifications are checked, applied safely (avoiding forbidden pathways), and automatically validated.
4+
5+
## Commands
6+
7+
### ctxt apply
8+
9+
Applies a structured proposal to the workspace.
10+
11+
```bash
12+
ctxt apply [proposal_path] [--yes]
13+
```
14+
15+
* **`proposal_path`** (optional): The path to the proposal JSON to apply. Defaults to `proposals/proposal.latest.json` if not specified.
16+
* **`--yes` / `-y`** (optional): Bypasses the confirmation prompt. Recommended for automation and testing.
17+
18+
### ctxt validate
19+
20+
Runs the validation commands associated with the latest applied proposal to ensure that the codebase is healthy.
21+
22+
```bash
23+
ctxt validate
24+
```
25+
26+
## Security Guardrails
27+
28+
The Apply Gate enforces several security boundaries to satisfy the project constitution:
29+
30+
1. **Path-Traversal Prevention**: File paths within operations are parsed and blocked if they contain `..` or are absolute.
31+
2. **Directory Isolation**: Changes targeting system folders (like `.git/`, `.comptext/`, `target/`, or `reports/`) are rejected and trigger a security policy failure.
32+
3. **Secret Storage Isolation**: Changes modifying `.env` or files containing key/token suffixes (like `.key`, `.pem`, `.pfx`, `.p12`) are blocked.
33+
4. **Validation Loop**: Every successful apply operation is followed by executing the `validation_commands` declared inside the proposal. If validation fails, the process aborts.

proposals/proposal.latest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
{
1313
"op": "patch",
1414
"path": "src/cli.rs",
15-
"detail": "Mock patch generated by dummy provider: \"Mock LLM response from CompText Dummy Provider. Received prompt: \"Add context inspect\" Workspace context analyzed successfully: 54 files included. Dummy status: offline-test-provider ok.\""
15+
"detail": "Mock patch generated by dummy provider: \"Mock LLM response from CompText Dummy Provider. Received prompt: \"Add context inspect\" Workspace context analyzed successfully: 55 files included. Dummy status: offline-test-provider ok.\""
1616
}
1717
],
1818
"validation_commands": [

proposals/proposal_add_context_inspect.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
{
1313
"op": "patch",
1414
"path": "src/cli.rs",
15-
"detail": "Mock patch generated by dummy provider: \"Mock LLM response from CompText Dummy Provider. Received prompt: \"Add context inspect\" Workspace context analyzed successfully: 54 files included. Dummy status: offline-test-provider ok.\""
15+
"detail": "Mock patch generated by dummy provider: \"Mock LLM response from CompText Dummy Provider. Received prompt: \"Add context inspect\" Workspace context analyzed successfully: 55 files included. Dummy status: offline-test-provider ok.\""
1616
}
1717
],
1818
"validation_commands": [

reports/phase_6_status.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# CompText CLI — Phase 6 Status Report
2+
3+
## Standard Return Schema
4+
PHASE: Phase 6: Apply Gate
5+
STATUS: success
6+
FILES_CHANGED:
7+
- src/cli.rs
8+
- tests/cli_smoke.rs
9+
- docs/APPLY_GATE.md
10+
- reports/phase_6_status.md
11+
- PROJEKT.md
12+
COMMANDS_RUN:
13+
- `cargo fmt --all --check`
14+
- `cargo check`
15+
- `cargo test`
16+
- `cargo clippy -- -D warnings`
17+
VALIDATION:
18+
- Formatting verified clean with `cargo fmt --all --check`.
19+
- Project build checked and verified using `cargo check`.
20+
- 18 unit and integration tests successfully verified via `cargo test`.
21+
- Clippy completed cleanly with no warnings or errors.
22+
ARTIFACTS:
23+
- None (This phase implemented the execution engine and validation gates).
24+
GIT:
25+
- Stage, commit, and push pending.
26+
NETWORK:
27+
- offline-only (Dummy validations run completely offline).
28+
SECRETS:
29+
- verified-redacted (System files and credentials blocked from mutation path).
30+
POLICY_DECISIONS:
31+
- Apply security guardrails implemented: rejected traversing paths, absolute paths, system folders, and credentials.
32+
RISKS:
33+
- Handled parallel execution locks in test suites by substituting target files for mock integration test cases.
34+
SKILLS_USED:
35+
- `.agents/skills/ctxt-long-run-autonomy/SKILL.md`
36+
- `.agents/skills/ctxt-security/SKILL.md`
37+
- `.agents/skills/ctxt-provider-boundary/SKILL.md`
38+
- `.agents/skills/ctxt-context-pack/SKILL.md`
39+
- `.agent/skills/05_proposal_apply_gate.md`
40+
NEXT:
41+
- Phase 7: Provider Config Layer
42+
43+
---
44+
45+
## Detailed Notes & Output Samples
46+
47+
### Safety Validations
48+
`apply` parses the operations block of the Proposal, validates every path against the security rules, and blocks execution if any of the following rules are violated:
49+
- Path contains directory traversal (`..`)
50+
- Path is absolute
51+
- Path target lies in a system directory (`.git/`, `.comptext/`, `target/`, `reports/`)
52+
- Path targets secret files or credentials (`.env`, `.key`, `.pem`, `.pfx`, `.p12`)
53+
54+
If these checks pass, `apply` performs the simulated write (appending comments for `.rs` and `.md` mock operations to avoid compilation/parsing issues) and triggers all `validation_commands` listed in the proposal.

0 commit comments

Comments
 (0)