Skip to content

Commit 9a045aa

Browse files
author
Sovereign-OS
committed
refactor: clean repo, rewrite README, remove demo artifacts
Made-with: Cursor
1 parent 8d37345 commit 9a045aa

Some content is hidden

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

57 files changed

+1950
-1372
lines changed

.env.example

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ SOVEREIGN_JOB_DB=./data/jobs.db
1616
SOVEREIGN_LEDGER_PATH=./data/ledger.jsonl
1717
SOVEREIGN_AUDIT_TRAIL_PATH=./data/audit.jsonl
1818

19+
# --- Optional: control API cost (avoid jobs running / 接单 non-stop) ---
20+
# Leave SOVEREIGN_AUTO_APPROVE_JOBS unset so new jobs need manual Approve in Dashboard.
21+
# Unset SOVEREIGN_INGEST_URL (or set SOVEREIGN_INGEST_ENABLED=false) to stop automatic intake.
22+
# Set SOVEREIGN_JOB_WORKER_ENABLED=false to pause all execution (no jobs run until true + restart).
23+
# For demo: pull from local JSON once, only a few jobs per start:
24+
# 1) Start demo orders server: python scripts/serve_demo_orders.py
25+
# 2) Set:
26+
# SOVEREIGN_INGEST_URL=http://localhost:8765/jobs?limit=3
27+
# SOVEREIGN_INGEST_ONCE=true
28+
# SOVEREIGN_AUTO_APPROVE_JOBS=true
29+
# SOVEREIGN_INGEST_URL=http://localhost:9000/jobs?take=true
30+
# SOVEREIGN_INGEST_ENABLED=false
31+
# SOVEREIGN_JOB_WORKER_ENABLED=false
32+
1933
# --- Optional: job completion webhook (Phase C) ---
2034
# SOVEREIGN_WEBHOOK_URL=https://your-server.com/webhook
2135
# SOVEREIGN_WEBHOOK_SECRET=your-secret-for-hmac

.gitignore

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,20 @@ build/
1818
.DS_Store
1919
Thumbs.db
2020

21-
# Ledger / local data
21+
# Runtime data — never commit
2222
data/
2323
*.jsonl
24+
*.db
25+
26+
# Environment — never commit
2427
.env
2528
.env.local
2629

27-
# Do not commit secrets
30+
# Secrets
2831
*.pem
2932
*.key
33+
34+
# Build artifacts
35+
sovereign_os.egg-info/
36+
dist/
37+
build/

Approve

Whitespace-only changes.

README.md

Lines changed: 282 additions & 120 deletions
Large diffs are not rendered by default.

charter.default.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ core_competencies:
2828
- name: write_post
2929
description: Draft social posts for platforms (X/LinkedIn/etc.) with variations and CTA
3030
priority: 6
31+
- name: help_docs
32+
description: "Help center and product docs: FAQ entries, in-app tooltips, getting started guides; tone helpful, no jargon"
33+
priority: 6
3134
- name: meeting_minutes
3235
description: "Turn transcripts into meeting minutes: decisions, action items, risks, open questions"
3336
priority: 6
@@ -56,17 +59,20 @@ core_competencies:
5659
description: Review code for issues, style, and best practices; output only, no execution
5760
priority: 6
5861

62+
# CFO profitability: reject jobs where estimated cost would exceed (1 - min_job_margin_ratio) of revenue.
63+
# 0.2 = 20% minimum gross margin (cost must be <= 80% of job price). Set to 0 to disable.
5964
fiscal_boundaries:
6065
daily_burn_max_usd: 50.00
6166
max_budget_usd: 2000.00
6267
currency: USD
68+
min_job_margin_ratio: 0.2
6369

6470
success_kpis:
6571
- name: task_completion_rate
6672
metric: tasks_verified_ok
6773
target_value: 0.95
6874
unit: ratio
69-
verification_prompt: "Did the output satisfy the task success criteria?"
75+
verification_prompt: "Is the output non-empty, on-topic, and a reasonable response to the task? Pass (true) unless the output is clearly off-topic, empty, or nonsensical."
7076
- name: cost_per_task
7177
metric: usd_cents_per_task
7278
target_value: 500

docs/CEO_CFO_PROFITABILITY.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# CEO & CFO: Economic Logic and Profitability
2+
3+
Sovereign-OS applies **top-company CEO/CFO practices** so the system has real economic discipline: it rejects unprofitable jobs and respects margin floors.
4+
5+
## Principles (from top-company practice)
6+
7+
- **Unit economics**: Every paid job has revenue (job price) and cost (estimated task execution). Gross margin = (revenue - cost) / revenue. Top companies (e.g. SaaS, hyperscalers) target high gross margins and enforce **minimum margin floors** so they do not accept loss-making deals.
8+
- **CFO guardrails**: CFOs use metrics like gross margin, runway, and burn rate. Here, the CFO enforces:
9+
- **Budget**: Balance and daily burn cap (existing behavior).
10+
- **Profitability**: For each paid job, estimated cost must not exceed `revenue × (1 - min_job_margin_ratio)`. So a 20% margin floor means cost ≤ 80% of revenue; otherwise the job is rejected.
11+
- **CEO–CFO alignment**: The CEO (Strategist) produces the plan and cost estimate; the CFO (Treasury) checks both liquidity and **per-job unit economics**. If the plan would make the job unprofitable, the CFO aborts before any spend.
12+
13+
## How it works in Sovereign-OS
14+
15+
1. **Charter** (`fiscal_boundaries.min_job_margin_ratio`): Optional, 0–1. Example: `0.2` = 20% minimum gross margin (cost must be ≤ 80% of job revenue). Set to `0` to disable (only balance/daily cap apply).
16+
2. **When a job runs**: The app passes `job.amount_cents` (revenue) into `run_mission_with_audit(..., job_revenue_cents=job.amount_cents)`.
17+
3. **After the CEO plan**: The engine sums `total_estimated_cents` (cost). The CFO then runs `approve_job_profitability(job_revenue_cents, total_estimated_cents)`. If `total_estimated_cents > job_revenue_cents × (1 - min_job_margin_ratio)`, it raises `UnprofitableJobError` and the job is not executed.
18+
4. **UI**: If the job is rejected for profitability, the Decision stream shows a CFO message and the job status is set to failed with a clear error.
19+
20+
## Configuration
21+
22+
In your Charter YAML (e.g. `charter.default.yaml`):
23+
24+
```yaml
25+
fiscal_boundaries:
26+
daily_burn_max_usd: 50.00
27+
max_budget_usd: 2000.00
28+
currency: USD
29+
min_job_margin_ratio: 0.2 # 20% min margin; reject job if cost > 80% of revenue
30+
```
31+
32+
- `min_job_margin_ratio: 0` — profitability check disabled; only balance and daily cap apply.
33+
- `min_job_margin_ratio: 0.2` — 20% margin floor (typical for many B2B / services).
34+
- `min_job_margin_ratio: 0.3` — 30% margin floor (stricter).
35+
36+
## Example
37+
38+
- Job price (revenue): $80 → 8000 cents.
39+
- CEO plan: 2 tasks, total estimated cost 7000 cents.
40+
- Margin = (8000 - 7000) / 8000 = 12.5%.
41+
- If `min_job_margin_ratio: 0.2`, then 12.5% < 20% → CFO rejects the job as unprofitable.
42+
43+
So the system **only runs paid jobs that meet the configured margin floor**, giving it a real “economic brain” aligned with how top-company CEOs and CFOs think about profitability.

docs/CONFIG.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ All optional unless noted. Set in the shell, `.env`, or your process manager (e.
1919
| `SOVEREIGN_JOB_RATE_LIMIT_PER_MIN` | If set (e.g. `60`), limits how many `POST /api/jobs` requests each client IP can make per minute; returns 429 when exceeded. |
2020
| `SOVEREIGN_JOB_MAX_RETRIES` | Max retries for a single job via `POST /api/jobs/{id}/retry` (default `2`). Only `failed` / `payment_failed` jobs are retryable. |
2121
| `SOVEREIGN_JOB_WORKER_CONCURRENCY` | Max jobs run in parallel by the worker (default `1`). Set to `2` or more for higher throughput. |
22+
| `SOVEREIGN_JOB_WORKER_ENABLED` | When set to `false` (or `0`/`off`/`no`), the job worker thread is **not** started. No jobs run until you set it back to `true` and restart. Use to pause execution and avoid API cost. Default `true`. |
2223
| `SOVEREIGN_JOB_IP_WHITELIST` | Optional. Comma-separated IPs allowed to call `POST /api/jobs` and `POST /api/jobs/batch`; others get 403. |
2324
| (none) | Web UI: `GET /` (dashboard), `GET /health`, `GET /docs` (FastAPI Swagger). Dashboard shows “Auto-approve ON” / “Compliance auto ON” when those env vars are set. |
2425

@@ -32,8 +33,11 @@ The Web process is designed for **24/7** operation: a background thread continuo
3233

3334
| Variable | Description |
3435
|----------|-------------|
35-
| `SOVEREIGN_INGEST_URL` | JSON URL to poll for new jobs. Response: array or `{ "jobs": [...] }` with `goal`, optional `charter`, `amount_cents`, `currency`. |
36-
| `SOVEREIGN_INGEST_INTERVAL_SEC` | Polling interval in seconds (default `60`). |
36+
| `SOVEREIGN_INGEST_URL` | JSON URL to poll for new jobs. Response: array or `{ "jobs": [...] }` with `goal`, optional `charter`, `amount_cents`, `currency`. For demo: run `python scripts/serve_demo_orders.py` and set `http://localhost:8765/jobs?limit=3` to pull only 3 jobs from `examples/ingest_demo_orders.json`. If unset, no automatic intake. |
37+
| `SOVEREIGN_INGEST_ENABLED` | When set to `false` (or `0`/`off`/`no`), the ingest poller is **not** started even if `SOVEREIGN_INGEST_URL` is set. Use to stop automatic "接单" and reduce API cost. Default `true` when URL is set. |
38+
| `SOVEREIGN_INGEST_ONCE` | When set to `true` (or `1`/`yes`), the poller **fetches once** and then stops (no repeated polling). Use for demo: one pull, no loop. |
39+
| `SOVEREIGN_INGEST_INTERVAL_SEC` | Polling interval in seconds (default `60`). Ignored when `SOVEREIGN_INGEST_ONCE=true`. |
40+
| `SOVEREIGN_INGEST_MAX_JOBS_PER_POLL` | If set (e.g. `1` or `2`), at most this many jobs are enqueued per poll. Use to cap token rate when the ingest URL returns many jobs (see [TOKEN_SPIKE_INVESTIGATION.md](TOKEN_SPIKE_INVESTIGATION.md)). Default `0` = no cap. |
3741
| `SOVEREIGN_INGEST_DEDUP_SEC` | If set (e.g. `300`), the ingest poller will not enqueue a job when one with the same `goal` and `amount_cents` was already created within this many seconds. Reduces duplicate jobs from repeated polling. |
3842

3943
## Audit trail (verifiable)
@@ -49,11 +53,21 @@ The Web process is designed for **24/7** operation: a background thread continuo
4953
| `SOVEREIGN_COMPLIANCE_SPEND_THRESHOLD_CENTS` | If set to a positive number, the Web UI engine uses `ThresholdComplianceHook`: when a task’s estimated cost (cents) is ≥ this value, the job is put back to `pending` with “Human approval required” until a second approval. See [MONETIZATION.md](MONETIZATION.md) and [PHASE6.md](PHASE6.md). |
5054
| `SOVEREIGN_COMPLIANCE_AUTO_PROCEED` | When set to `true` (or `1`/`yes`), the CFO does **not** require human approval when the compliance hook returns “request human approval” for spend above the threshold; the task is allowed to proceed (human-out-of-loop for high spend). Use only when you accept the risk. |
5155

56+
## Controlling API cost (avoid jobs running / 接单 non-stop)
57+
58+
To avoid high LLM/API usage:
59+
60+
1. **Turn off auto-approve** – Do **not** set `SOVEREIGN_AUTO_APPROVE_JOBS=true`. New jobs stay `pending` until you click Approve in the Dashboard, so you control when each job runs.
61+
2. **Stop automatic intake** – Unset `SOVEREIGN_INGEST_URL`, or set `SOVEREIGN_INGEST_ENABLED=false` so the ingest poller does not start. Otherwise the system keeps pulling jobs from the URL.
62+
3. **Pause all job execution** – Set `SOVEREIGN_JOB_WORKER_ENABLED=false`. The job worker thread will not start; no jobs run until you set it back to `true` and restart.
63+
64+
Startup logs will warn when auto-approve or ingest is on so you can adjust.
65+
5266
## Human out of loop
5367

5468
| Variable | Description |
5569
|----------|-------------|
56-
| `SOVEREIGN_AUTO_APPROVE_JOBS` | When set to `true` (or `1`/`yes`), every new job (from `POST /api/jobs` or ingest) is immediately set to `approved` so the worker runs it without a human clicking Approve. Full **human-out-of-loop**: ingest → auto-approve → run → charge → webhook. |
70+
| `SOVEREIGN_AUTO_APPROVE_JOBS` | When set to `true` (or `1`/`yes`), every new job (from `POST /api/jobs` or ingest) is immediately set to `approved` so the worker runs it without a human clicking Approve. Full **human-out-of-loop**: ingest → auto-approve → run → charge → webhook. **Leave unset/false to approve manually and control cost.** |
5771
| `SOVEREIGN_COMPLIANCE_AUTO_PROCEED` | See Compliance above. Together with `SOVEREIGN_AUTO_APPROVE_JOBS`, both gates can be automated. |
5872

5973
## Job completion webhook (delivery / proactive contact)
@@ -64,6 +78,9 @@ The Web process is designed for **24/7** operation: a background thread continuo
6478
| `SOVEREIGN_WEBHOOK_SECRET` | If set, the request body is signed with HMAC-SHA256 and sent in header `X-Sovereign-Signature: sha256=<hex>`. Receivers should verify this. |
6579
| `SOVEREIGN_WEBHOOK_LOG_PATH` | If set (default `data/webhook_log.jsonl` when logging is enabled), failed webhook deliveries (after all retries) are appended as one JSONL line per failure (url, job_id, status, error, ts). |
6680
| Per-job `callback_url` | In `POST /api/jobs` body you can pass `callback_url`; when that job completes, the webhook is sent to this URL instead of (or in addition to) the global `SOVEREIGN_WEBHOOK_URL`. |
81+
| Per-job `delivery_contact` | Optional. Dict e.g. `{"platform":"reddit","username":"x","post_id":"y","permalink":"/r/..."}`. When the job completes, the result can be posted back (e.g. Reddit comment on the post). See [DEMO_TASK_POSTS.md](DEMO_TASK_POSTS.md). |
82+
| `REDDIT_CLIENT_ID`, `REDDIT_CLIENT_SECRET`, `REDDIT_USER_AGENT` | Required for Reddit delivery (post comment with result). Same app as ingest or any Reddit app. |
83+
| `REDDIT_REFRESH_TOKEN` **or** `REDDIT_USERNAME` + `REDDIT_PASSWORD` | Reddit OAuth2 refresh token (preferred) or script-app credentials so the process can post the delivery comment. |
6784
| (payload) | Each job gets a `request_id` (trace id) at creation; it is included in the webhook payload when set, for correlating logs and delivery. |
6885

6986
Payload format and retries: see [OPEN_SOURCE_READY_PLAN.md](OPEN_SOURCE_READY_PLAN.md) (Webhook payload spec). Typical use: your backend receives the webhook and then notifies the customer (email, Slack, etc.).
@@ -104,6 +121,7 @@ For **real** orders from Reddit, scraped sites, or Shopify/WooCommerce, run the
104121
105122
- **Bridge:** `python -m sovereign_os.ingest_bridge` (optional deps: `pip install praw requests beautifulsoup4` or `pip install -e ".[bridge]"`).
106123
- **Sovereign-OS:** Set `SOVEREIGN_INGEST_URL=http://<bridge>:9000/jobs?take=true` and optional `SOVEREIGN_INGEST_INTERVAL_SEC`, `SOVEREIGN_AUTO_APPROVE_JOBS=true`.
124+
- **Bridge config:** Optional `BRIDGE_CONFIG_PATH` points to a YAML file to overlay env (see [INGEST_BRIDGE.md](INGEST_BRIDGE.md)).
107125

108126
## CLI
109127

docs/DEMO_AUTO_CONNECT_AND_EMAIL.md

Lines changed: 0 additions & 121 deletions
This file was deleted.

0 commit comments

Comments
 (0)