Spaces:
Running
Running
File size: 6,931 Bytes
412a75b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | # OpenOperator Hugging Face Space Deployment & Acceptance Contract
## 1. System Invariants
OpenOperator enforces a strict separation between immutable application code and persistent user/runtime state:
```text
green GitHub SHA
==
HF snapshot
==
/git/agent-zero
==
/a0 application code
```
while:
```text
/a0/usr
```
remains persistent, mutable user state containing settings, goals, workdirs, logs, and `usr/.env`.
---
## 2. Exact Application Code Synchronization
During container startup (`docker/run/fs/ins/copy_A0.sh`), exact application code is synchronized:
```bash
rsync -a --delete --no-owner --no-group --exclude='/usr' /git/agent-zero/ /a0/
```
- Application code in `/a0` is kept perfectly in sync with the build snapshot `/git/agent-zero`.
- Obsolete application files removed from newer commits are pruned from `/a0`.
- The user directory `/a0/usr` (and all subdirectories `/a0/usr/*`) is strictly excluded from deletion or overwrite.
---
## 3. Deployment Secret Mapping & Bridge
Hugging Face Space Secrets arrive as process environment variables. Upon application startup, `helpers/runtime_secrets.py` normalizes and bridges these secrets into `/a0/usr/.env` with strict `0600` permissions.
### Secret Mapping Table
| Space Secret Variable | Canonical Runtime Variable(s) | Purpose |
|---|---|---|
| `SPYNEL_AGENT_ZERO_API_KEY` | `SPYNEL_AGENT_ZERO_API_KEY` | Agent Zero internal API authentication (`X-API-KEY`) |
| `HUGGINGFACE_TOKEN` | `HF_TOKEN` | Hugging Face CLI (`hf`) & remote Hugging Face MCP authorization |
| `GITHUB_PAT` | `GH_TOKEN`, `GITHUB_TOKEN` | GitHub repository inspection, PR management & Git operations |
### Model Provider Secrets
| Environment Variable | Canonical Runtime Setting | Purpose |
|---|---|---|
| `COMPATIBLE_URL` | `chat.api_base` | OpenAI-compatible LLM endpoint URL |
| `COMPATIBLE_MODEL` | `chat.name` | OpenAI-compatible model name |
| `BLABLADOR_API_KEY` | `API_KEY_OTHER` | Model API key stored securely outside presets in `.env` |
### Critical Credential Distinctions
- `HF_TOKEN` (Hugging Face token) is **NOT** the LLM model API key.
- `HF_TOKEN` is **NOT** the Spynel API key (`SPYNEL_AGENT_ZERO_API_KEY`).
- `GITHUB_PAT` is **NOT** the Hugging Face token.
### Secret Hygiene & Rotation Rules
1. Space process environment variables override stale persisted values in `usr/.env` upon container restart.
2. Secret values are **NEVER** printed, logged, returned in `/health`, or exposed via settings APIs.
3. Diagnostic endpoints report boolean presence status only (`{"spynel_api_key": true, "hf_token": true, "github_token": true}`).
---
## 4. Deployed Source SHA Identity
Every deployment snapshot includes `/openoperator-build.json` containing:
```json
{
"source_sha": "<full-github-commit-sha>"
}
```
The application exposes this identity via:
- `GET /health` -> `{"status": "ok", "sha": "<full-github-commit-sha>"}`
Acceptance smoke testing compares `GET /health`'s reported SHA against the target green commit SHA.
---
## 5. Hugging Face MCP Client Integration
OpenOperator connects to Hugging Face's official remote MCP server as a client:
- **Endpoint**: `https://huggingface.co/mcp`
- **Transport**: Streamable HTTP (`type: "streamable-http"`)
- **Header Configuration**: `"Authorization": "Bearer ${ENV:HF_TOKEN}"`
### Safe Secret Interpolation
- `helpers/mcp_handler.py` substitutes `${ENV:VAR_NAME}` placeholders in memory at request time.
- Placeholders match `^[A-Z_][A-Z0-9_]*$` strictly. Arbitrary code execution or `eval` is prohibited.
- Serialized `settings.json`, UI outputs, and logs preserve the literal placeholder `${ENV:HF_TOKEN}` and never log expanded secret tokens.
- No local MCP daemon or additional listening port is executed (only public port `7860`).
---
## 6. Modern `hf` CLI Tooling
The modern `hf` CLI (`huggingface_hub[cli]`) is installed at image build time in `/opt/venv-a0/bin/hf`:
- Available on system `PATH`.
- Authenticates seamlessly via `HF_TOKEN` in environment.
- Commands utilized by OpenOperator:
- `hf auth whoami`
- `hf spaces info OWNER/SPACE`
- `hf spaces logs OWNER/SPACE`
- `hf spaces logs --build OWNER/SPACE`
- `hf spaces secrets list OWNER/SPACE`
---
## 7. Specialist Profile Organization
OpenOperator includes 19 native specialist profiles under `/a0/agents/`:
1. `developer` - Software architecture & master orchestration
2. `hacker` - Security research & parallel hypothesis testing
3. `spynel` - External API routing & task dispatch
4. `reviewer` - Read-only code & spec review
5. `tester` - Test suite execution & evidence verification
6. `tiny-coder` - Bounded 1-3 file patch implementation
7. `debugger` - Failure localization & falsifiable hypotheses
8. `integrator` - API contracts & protocol verification
9. `frontend-qa` - UI contrast & browser behavior verification
10. `evals` - Benchmark evaluation & performance metrics
11. `shipper` - Release preparation & production approval gate
12. `launch` - Launch storyboard & release notes
13. `performance` - Concurrency profiling & latency analysis
14. `security` - Surface security auditing & credential checks
15. `refactorer` - Structural changes & technical debt reduction
16. `maintainer` - Dependency updates & environment maintenance
17. `data-engineer` - Data pipeline & schema engineering
18. `docs` - Verified technical documentation
19. `repository-manager` - Git, GitHub PR, and Hugging Face Space management
### `repository-manager` Policy
- **Default Mode**: Read-only inspection (`git status`, `git log`, `git diff`, `hf spaces info`, `hf spaces logs`, `hf spaces secrets list`).
- **Mutation Policy**: Pushes, branch deletions, PR merges, Space variable changes, and deployments require explicit authorization.
---
## 8. Deployment & Acceptance Procedure
### Deployment Execution
To deploy a verified green GitHub commit SHA to Hugging Face Space `Leon4gr45/openoperator`:
```bash
export HF_TOKEN="<write-scoped-hf-token>"
python3 scripts/deploy_hf_space.py --space Leon4gr45/openoperator --sha <green-commit-sha>
```
### Live Acceptance Verification
Once the Space rebuilds, run the acceptance smoke test:
```bash
export SPYNEL_AGENT_ZERO_API_KEY="<deployment-secret>"
export EXPECTED_OPENOPERATOR_SHA="<green-commit-sha>"
python3 scripts/smoke_hf_openoperator.py --mode full --expected-sha <green-commit-sha>
```
Required Live Verification Checklist:
- [x] Health status == PASS (`GET /health`)
- [x] Deployed SHA matches expected GitHub commit SHA
- [x] Specialist Profiles == PASS (all 19 profiles discoverable)
- [x] Required Skills == PASS (all 23 skills present)
- [x] Spynel Routing == PASS (`@repository-manager`, `@reviewer`, etc.)
- [x] Goal Delegation == PASS (`/goal` execution with specialist profile)
- [x] Unknown Profile Safety == PASS (404 on unknown profiles)
- [x] API Token Masking == PASS (`mcp_server_token == "************"`)
|