[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7ECNWE7QJWCHPY85HRZBXCM":3,"skill-same:01M7ECNWE7QJWCHPY85HRZBXCM":49},{"skillNo":4,"name":5,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":20,"frontMatter":21,"refName":22,"commitSha":23,"skillDirectory":24,"forksCount":13,"repositoryHtmlUrl":25,"repositoryHomepageUrl":6,"ownerHtmlUrl":26,"ownerBlogUrl":6,"ownerDescription":27,"updatedAt":28,"install":29,"resources":42},"01M7ECNWE7QJWCHPY85HRZBXCM","cortexcloud-api-dev",null,"jonahthan433\u002FCortexOS","jonahthan433","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F211465495?v=4","01M7ECH9HPHGA89DCXHHJBTS3C","jonah.ai","01M7ECH9JCEM45DZMWPT7148S1",0,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fjonahthan433\u002FCortexOS\u002Fblob\u002Fmain\u002Fskills\u002Fimported\u002Fcortexcloud-api-dev\u002Fcortexcloud-api-dev\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"# cortexcloud-api-dev\n\n# CortexCloud API Category Development\n\nCortexCloud (CortexCloudAPI repo) is an agent-native API platform. Each\ncapability (\"category\") is a FastAPI router behind a feature flag, with\nprovider abstraction, x402\u002FMPP payment, and a PostgreSQL usage ledger.\nThis skill captures the proven pattern for adding a category end-to-end and\nvalidating it on staging with **real paid USDC** before any production merge.\n\n## Architecture facts (verified this session)\n- **Repo \u002F deploy**: `CortexCloudAPI` on `192.168.1.15` (CT105), systemd\n  `cortexcloud.service` (API, :8000) + `cortexcloud-mcp.service` (MCP, :3100,\n  separate `\u002Fopt\u002Fcortexcloud-mcp\u002Fmcp-bundle.cjs`). Venv `\u002Fopt\u002Fcortexcloud-venv`.\n  Postgres `cortexcloud-db` docker on `127.0.0.1:5433` only (NOT public).\n  Redis on `127.0.0.1:6379` only. Production secrets in\n  `\u002Fetc\u002Fcortexcloud\u002Fcortexcloud.env` (mode 600; `EnvironmentFile=` in unit).\n  Staging = the test bed; production is the same host. NEVER merge\u002Fdeploy\n  without explicit approval. Build on a branch (e.g. `ml-api`), keep\n  `ML_ENABLED=false` etc. until validated.\n- **Feature flag**: routes self-gate via `settings.\u003CCAT>_ENABLED` → return\n  `503` when off. Router is always mounted; the flag only flips runtime\n  behavior. Mirror this exactly (do NOT gate router inclusion on the flag\n  in `main.py` — inclusion is unconditional; the route checks the flag).\n- **Provider abstraction**: primary + fallback (e.g. fal→Replicate for\n  images, Cohere→Jina for rerank). Each provider returns\n  `(status, data, provider_name, *rest)`; on primary failure fall through to\n  the next. Return a clean `502 {\"error\":\"upstream_\u003Ccat>\"}` on total failure\n  — never fake a 200.\n- **Pricing model (immutable rule)**: `price = max(floor, provider_cost ×\n  1.35 + 0.0015)`. Floors: data\u002Fimage-generate ~$0.004, rerank ~$0.006.\n  Keep customer price DERIVED from a provider-cost table; never hardcode a\n  price that can't be traced to a provider quote.\n- **MCP x402 settlement (separate service, separate repo `cortexcloud-mcp`)**:\n  served by `cortexcloud-mcp.service` on :3100 (cloudflared → `\u002Fmcp`). Source\n  `src\u002Findex.ts` is built to `mcp-bundle.cjs` (`npx tsc --noEmit && npx\n  --no-install esbuild src\u002Fhttp.ts --bundle --format=cjs --platform=node\n  --outfile=dist\u002Fmcp-bundle.cjs`), deployed to CT105\n  `\u002Fopt\u002Fcortexcloud-mcp\u002Fmcp-bundle.cjs`. Env in `\u002Fopt\u002Fcortexcloud-mcp\u002Fmcp.env`\n  (mode 600). **CRITICAL PITFALL (see below): the MCP server must NOT hold the\n  payer key or it pays on the operator's wallet — defeating agent-native x402.**\n  It is a DISCOVERY + FREE surface (estimate\u002Fbackends\u002Fjobs); paid solve runs\n  through REST\u002FSDK where the AGENT's wallet pays.\n- **x402 Bazaar auto-index**: set `\"discoverable\": true` in the `build_manifest()`\n  dict in `app\u002Fx402\u002Fdiscovery.py` (the `\u002F.well-known\u002Fx402.json` body). With it,\n  the CDP facilitator + x402 Bazaar catalog auto-list every endpoint — no API\n  submission. Free, high-leverage. (Separate from `bazaar.py` `_TOOLS`.)\n- **Ledger margin tracking**: set `request.state.provider_cost_usd` and\n  `request.state.category=\"\u003Ccat>\"` in the route, AND add a branch in the\n  middleware's pre-settle block (mirror the Data branch around line 507-563)\n  so the ledger captures cost\u002Fmargin even though the middleware records\n  before `call_next`. Without the middleware branch, the ledger stores\n  `None` for cost\u002Fmargin.\n\n## Per-endpoint gating (subset of a category ready, rest disabled)\nWhen only SOME endpoints in a category are production-ready (e.g. ML: rerank\nready, image-generate\u002Fimage-understand blocked on provider credits), do NOT\nflip the master `\u003CCAT>_ENABLED` flag — that would disable the ready one too.\nInstead add per-endpoint flags (`ML_RERANK_ENABLED`, `ML_IMAGE_GENERATE_ENABLED`,\n`ML_IMAGE_UNDERSTAND_ENABLED`, each defaulting `True`) and:\n- Route-level: `_disabled(endpoint)` checks the per-endpoint flag (not just\n  the master) and returns 503 `endpoint_disabled`.\n- **Middleware-level (critical)**: the x402 middleware runs BEFORE the route,\n  so the route's 503 is reached only AFTER the 402 payment challenge. To avoid\n  charging a customer for a disabled endpoint, add a gate in the middleware's\n  per-category branch (before the price\u002Fchallenge is built) that returns 503\n  `endpoint_disabled` immediately when the per-endpoint flag is false. Without\n  this, a disabled endpoint still emits a 402 and would settle-then-503.\n- Keep the provider fallback architecture (primary→fallback) untouched; only\n  the entry gate changes. This is exactly how ML shipped on `ml-api`.\n\n## Cost \u002F margin comparison for funding decisions\n`references\u002Fml-cost-comparison.md` has current (Aug 2026) per-call provider\ncosts (fal\u002FReplicate for image-gen, OpenRouter Gemini for vision, Cohere for\nrerank), the CortexCloud margin math, and the funding-vs-breakeven protocol.\n\n## Step-by-step (new category)\n1. `app\u002Fcore\u002Fconfig.py`: add `\u003CCAT>_ENABLED` + provider key fields.\n2. `app\u002Fx402\u002Fpricing.py`: add `\u003CCAT>_PROVIDERS`, `estimate_cost()`,\n   `price_usd()`, register routes in `ROUTE_PRICING`\u002F`ROUTE_DESCRIPTIONS`\u002F\n   `FREE_ROUTES`. Free\u002F`:free` provider models MUST return cost `$0` so\n   margin isn't overstated.\n3. `app\u002Fapi\u002F\u003Ccat>.py`: 3+ endpoints, `_disabled()` gate, `_need(key,...)`\n   prefix check, provider funcs, TTLCache for read\u002Frerank (not generate),\n   `request.state` set for ledger.\n4. `app\u002Fmain.py`: `include_router(\u003Ccat>_router)` unconditionally.\n5. `app\u002Fx402\u002Fbazaar.py`: add MCP tool entries in `_TOOLS`.\n6. `app\u002Fmiddleware\u002Fx402.py`: add the `\u003Ccat>` cost\u002Fcategory branch.\n7. `tests\u002Ftest_\u003Ccat>.py`: unit (pricing model, flag-gate 503, fallback\n   routing, cache) + guarded integration (real keys). Use the `client`\n   ASGI fixture for route-logic tests; set `X402_ENABLED=False` to bypass\n   payment in those tests, and use keys with the required prefixes\n   (`sk-or-` for OpenRouter, `fal-` for Fal, `co-` for Cohere) or `_need`\n   returns 503.\n8. `scripts\u002F\u003Ccat>_paid_smoke.py`: real x402 settlement per endpoint (reuse\n   the Data smoke pattern: 402 → sign → CDP settle → 200 → assert\n   cost\u002Fprice\u002Fmargin). Buyer key at `\u002Froot\u002Fbzcheck\u002Ftest_buyer.key`.\n\n## Validation on staging (REAL money)\n- Push branch, `git checkout` it on CT105 (move untracked smoke scripts\n  aside first — they block checkout). Add provider keys to the systemd\n  `Environment=` line (NOT a `.env`; staging has none). `systemctl restart`.\n- Run `pytest tests\u002Ftest_\u003Ccat>.py` ON STAGING (local venv lacks the ECDSA\n  key file `\u002Fopt\u002FCortexCloudAPI\u002Fserver_ecdsa.key` the middleware needs).\n- Run the paid smoke for every endpoint + every fallback path.\n- Regenerate `openapi.json` (see pitfall) and verify x402.json + Bazaar.\n- Confirm ledger rows have `category=\u003Ccat>`, correct `provider_cost_usd`,\n  `margin_usd`.\n\n## Switching auth modes: single-tenant (`PRIVATE_API_KEY`) ↔ public x402\nThe runtime has TWO modes, gated at boot by `enforce_secrets_in_production`\n(`app\u002Fcore\u002Fconfig.py`): with `PRIVATE_API_KEY` set, the validator only\nrequires `PRIVATE_API_KEY` itself (the static key replaces blockchain\nsettlement — `PRIVATE_API_KEY` global gate in middleware blocks every path\nexcept `\u002Fhealth`); with `X402_ENABLED=true` and `PRIVATE_API_KEY` UNSET,\nit demands `[WALLET_ADDRESS, CDP_WALLET_SECRET, X402_FACILITATOR_API_KEY_ID,\nX402_FACILITATOR_API_KEY_SECRET, AUTOMATION_WEBHOOK_SECRET]`. **Switching\nfrom single-tenant to public x402 is a credential-sourcing problem, not a\nconfig-flip problem** — prod was booted with only `WALLET_ADDRESS` and\n`AUTOMATION_WEBHOOK_SECRET`; the CDP trio is missing. Before flipping\n`X402_ENABLED=true`, decide where the CDP credentials come from (staging\n`.env`, AWS Secrets Manager, fresh Coinbase CDP dashboard). The boot\nvalidator fails FAST — `pydantic ValidationError [S7] ENV=production\nrequires CDP_WALLET_SECRET in environment` — and systemd restart-loops\nevery 5 s. Recovery = either source the creds, OR flip `X402_ENABLED=false`\nin env to fall back to single-tenant. Procedure + verification: see\n`references\u002Fmode-switch-x402-public.md`.\n\n## Pitfalls\n- **OpenAPI regen — use the SCRIPT, not the one-liner.** `main.py` overrides\n  `app.openapi()` to return the STATIC `openapi.json` (see below), so a manual\n  `create_app(override_openapi=False).openapi()` dump DOES NOT add the x402\n  `security`\u002F`x-payment-info` tags or the bazaar request bodies — it produced\n  a spec with 0 security tags and broke `test_openapi_spec_payments`. The\n  correct, idempotent regen is `scripts\u002Fupdate_openapi_v2.py` (run on staging\n  with unit env exported: `export $(grep '^Environment='\n  \u002Fetc\u002Fsystemd\u002Fsystem\u002Fcortexcloud.service | sed 's\u002F^Environment=\u002F\u002F'); export\n  ENV=production; python update_openapi_v2.py`). It reads `ROUTE_PRICING`\n  (for security+x-payment-info) and `INPUT_SCHEMAS` (for request bodies) and\n  writes `openapi.json`. After regen, **restart** so the running app re-reads\n  the file. Commit the regenerated `openapi.json` to the branch (scp the\n  staging file back if you regenerated on staging).\n- **INPUT_SCHEMAS + INPUT_EXAMPLES are REQUIRED per new route.** The x402\n  bazaar preflight validates every paid route against `INPUT_SCHEMAS[path]`\n  and `INPUT_EXAMPLES[path]`. If a route is missing from BOTH, the discovery\n  extension falls back to the OPTIMIZE\u002Fqubo body, so the 402 preflight fails\n  with `(root).input.body: \u003Cfield> is required` and the paid smoke can never\n  settle (402 loops forever). Add both dicts in `app\u002Fmiddleware\u002Fx402.py`\n  (spread pattern: `INPUT_SCHEMAS = {**INPUT_SCHEMAS, \"\u002Fv1\u002F\u003Ccat>\u002Fx\": {...}}`)\n  for EVERY paid route. Self-hosted categories (e.g. Automation) use\n  `provider_cost=0` and a flat floor price via `pegged_price(0.0, floor=X)`.\n- **llms.txt + agentsearch.txt are HARDCODED templates** in\n  `app\u002Fx402\u002Fdiscovery.py` (NOT auto-derived from routes). On every category\n  launch they go STALE — they claimed \"six categories including Automation\"\n  but listed zero Automation endpoints. After shipping, grep both for the new\n  category and add a concise section (endpoints, prices, examples, safety\n  notes). This is the recurring discovery-audit step — do it on every release.\n- **Durable drift guard (root cause of the \"old page keeps showing\" bug).**\n  `git pull` does NOT fail loudly — when the prod tree diverges it just\n  no-ops, so the box keeps serving stale files. Two divergence sources:\n  (1) the app regenerates `openapi.json` at runtime, dirtying the tree;\n  (2) a stray local commit\u002Funtracked script (e.g. probe scripts) makes a\n  fast-forward impossible. Symptom: you push + restart, but the OLD landing\n  or 404 routes persist. The one-off `git reset --hard origin\u002Fmain` fixes it\n  ONCE but drifts again. **Durable fix = a self-heal cron, NOT an\n  `ExecStartPre`.** An `ExecStartPre=\u002Fbin\u002Fbash -lc 'git fetch && git reset\n  --hard origin\u002Fmain'` fights systemd's StartLimitBurst (rapid restarts during\n  testing trip \"Start request repeated too quickly\" and the unit enters\n  failed state — a boot-loop risk) and can block startup if `git fetch` ever\n  fails offline. Instead run the same reset from a **separate scheduled job**\n  every 15 min (see `scripts\u002Fprod_selfheal.sh` + `references\u002Fprod-selfheal.md`).\n  It force-syncs prod to origin\u002Fmain continuously, cannot block startup, and\n  can't loop. Proven this session: injected stale `index.html` → cron reverted\n  it → live 200 with correct theme.\n- **Deploy step (manual, when you also restart):** `git fetch origin && git\n  reset --hard origin\u002Fmain`, remove untracked junk (`rm -f free_probe.py\n  run_*.sh *.bak`), then `systemctl restart`. Verify new routes return 402\n  (not 404) before enabling the feature flag. The self-heal cron makes this\n  idempotent but the manual reset is still the explicit deploy action.\n- **MCP `\u002Fmcp` needs an `initialize` handshake** before `tools\u002Flist`.\n  A bare `tools\u002Flist` POST returns `{\"error\":\"Server not initialized\"}` — that\n  is CORRECT protocol behavior, not a failure. The bazaar (`\u002F.well-known\u002Fbazaar`)\n  is the tool source-of-truth; confirm automation tools appear there. The\n  suite's `test_mcp_tools_list` is intentionally skipped (MCP served\n  out-of-band).\n- **systemd drop-in `mpp.conf`** under\n  `\u002Fetc\u002Fsystemd\u002Fsystem\u002Fcortexcloud.service.d\u002F` adds MPP\u002FAI\u002FRESEARCH env vars\n  and does NOT override the main unit's `Environment=`, so per-category flags\n  set in the main unit ARE picked up. Verify with `systemctl show -p\n  Environment` (merged) and the running process environ (`tr '\\0' '\\n' \u003C\n  \u002Fproc\u002F$(systemctl show -p MainPID | cut -d= -f2)\u002Fenviron | grep KEY=`).\n- **Plain `curl` to the public host can 403 (Cloudflare).** Simple curls\n  without a proper `User-Agent`\u002FAccept sometimes get `403 code 1010` or a\n  challenge HTML, which looks like a 5xx. Use the x402 SDK smoke script\n  (scripts\u002F\u003Ccat>_paid_smoke.py) or `curl -s` with a UA header for real\n  checks; don't trust a bare curl 403 as an app failure.\n- **NO-REFUND limitation (platform-wide, by design).** x402 v2 settles\n  USDC IRREVERSIBLY in the middleware BEFORE the route runs; if the upstream\n  provider then 5xx, the customer is charged with no automatic refund. There\n  is NO refund\u002Freverse code anywhere in the repo (only a `refund` enum value\n  in `billing.py`, no execution). A real refund would need a send-capable\n  merchant key + on-chain USDC transfer + idempotency — a separate\n  platform-wide feature. Do NOT add a per-category refund; document the\n  limitation. This is uniform across ALL categories (AI\u002FResearch\u002FData\u002F\n  Quantum\u002FML), so changing it for one category is inconsistent.\n- **systemd env editing**: a single `Environment=` line holds all vars.\n  `sed` edits can collide (duplicate keys, stray processes). After editing,\n  verify the KEY IS IN THE RUNNING PROCESS (`tr '\\0' '\\n' \u003C\n  \u002Fproc\u002F$(systemctl show -p MainPID --no-pager | cut -d= -f2)\u002Fenviron |\n  grep KEY=`), not just the unit file — `pgrep` may match stray SSH-session\n  uvicorn processes. Kill stray uvicorns from SSH runs.\n- **Free provider validation**: \"free\" tiers are often unreliable — OpenRouter\n  `:free` models are throttled at the provider (429) even with a BYOK key for\n  some backends (Google); Replicate needs actual CREDITS not just a payment\n  method (402 \"requires credit\"); fal accounts hit TOP_UP locks. Report\n  these as provider-account funding blockers, never fake a 200.\n- **Provider key prefix checks**: `_need(key, name, prefix)` enforces\n  prefixes (e.g. `sk-or-`). Test keys must match or the route 503s.\n- **Audit MUST probe runner completion, not just job acceptance.** A paid\n  job that is accepted (402→sign→settle→200, row in `opt_jobs`) but never\n  reaches `status=succeeded` \u002F `finished_at` is a SILENT FAILURE: the\n  customer is charged, no result is returned, and `asyncio.create_task`\n  swallows the exception (\"Task exception was never retrieved\"). The prior\n  audit caught a `Benchmark(...) TypeError` (`provider_cost_usd` kwarg\n  rejected by SQLAlchemy ORM even though the DB column exists — model\n  refactor on Aug 23 left `runner.py:200` calling a kwarg the ORM no longer\n  declares) that hung EVERY optimize job for 9 days. Audit procedure:\n  after running `verify_integration.py --mode all` (which only checks settle,\n  not completion), poll the returned `job_id` for 30s. If still\n  `status=running, backend=null, finished_at=null`, that is the smoking gun\n  for a runner crash. Then grep journalctl for `Task exception was never\n  retrieved` + `TypeError` — that pair is the canonical silent-fail\n  signature. Also grep `runner.py` for any unguarded ORM writes\n  (`db.add(ORMModel(... kwarg=...))`); every successful-completion path\n  should be wrapped or the crash halts the job silently.\n- **ORM\u002FDB drift pitfall (manifests as the audit gap above).** SQLAlchemy\n  ORM uses the model class, not the live DB schema. If the DB column exists\n  (e.g. from an older migration) but the ORM class no longer declares it,\n  `Model(**kwargs)` raises `TypeError: '\u003Ccol>' is an invalid keyword\n  argument`. This happens silently in `asyncio.create_task` and the job\n  hangs. After ANY model refactor that moves a column (e.g.\n  `provider_cost_usd` was moved from `Benchmark` to `Payment` in commit\n  `f90401e`), grep the codebase for callers that still pass the moved kwarg\n  to the OLD model. The fix is one of: (a) add the column to the model\n  class, (b) remove the kwarg from the caller, or (c) wrap the insert in\n  `try\u002Fexcept` so the job fails loudly instead of hanging.\n- **SAVEPOINT pattern for any runner write that can fail independently.**\n  Once you have the fix above, don't just `try\u002Fexcept: pass` — that swallows\n  the evidence. The correct root-cause-safe pattern is `async with\n  db.begin_nested(): db.add(Model(...))` so the failure only rolls back\n  that one row's SAVEPOINT, leaving the outer transaction (exec_row +\n  job.status + finished_at) intact. Then `except Exception: logger.exception\n  + alert(...)` on the outer try. A future ORM\u002FDB drift on this insert\n  logs loudly AND the job still completes with `status=succeeded` and\n  `finished_at` set. Verified pattern: `app\u002Foptimizer\u002Frunner.py` post-P0-1.\n- **Runner-side ledger write-back (post-solve cost).** When the x402\n  middleware records the `x402_payments` row at settle time, it can't know\n  the actual `provider_cost_usd` for `\u002Fv1\u002Foptimize` (the quantum cost is\n  only known after `pick_solver` runs). The cleanest fix: thread the\n  payer from the route handler through `create_job(payer=...)` into\n  `OptimizeJob.request[\"payer\"]`, then in the runner after `_cost_ledger()`\n  call a backfill helper that runs an UPDATE on `x402_payments` matching\n  `endpoint='\u002Fv1\u002Foptimize'` AND `payer=` AND `occurred_at` within a\n  tight window (`started_at - 2s` to `started_at + 30s`) AND\n  `provider_cost_usd IS NULL`, setting `provider_cost_usd` and\n  `margin_usd = amount_usd - provider_cost_usd`. Best-effort:\n  log+continue on failure. Worked for the test_buyer (single tenant);\n  upgrade to a real `payment_id` FK on `OptimizeJob` if multi-tenant\n  concurrent jobs become a concern.\n- **Pre-route SSRF guard (blocked targets must NEVER charge).** SSRF\n  validation in the route handler runs AFTER the x402 middleware has\n  settled — a customer paying for `http:\u002F\u002F169.254.169.254\u002F` is charged\n  and then gets the SSRF error. That's \"pay for nothing.\" The fix is to\n  move the `is_safe_url()` check into `InputValidationMiddleware` for\n  the two egress endpoints (`\u002Fv1\u002Fautomation\u002Fhttp-request` and\n  `\u002Fv1\u002Fautomation\u002Fwebhook`): parse the JSON body (the middleware reads it\n  for size\u002Fdepth anyway), pull `data[\"url\"]`, call `is_safe_url()`,\n  return 400 `ssrf_blocked: ...` if unsafe. The route handler keeps its\n  in-route check as defense in depth. After the fix, 0 ledger rows for\n  rejected requests — verified by querying `x402_payments` for the test\n  payer's calls in the last 5 min.\n- **Stray `\u002Fopt\u002FCortexCloudAPI\u002F.env` (RESOLVED 2026-09-01).** The prior\n  audit pitfall above described the duplicated secrets file. As of\n  2026-09-01 it has been deleted via `shred -u -n 3`, after consolidating\n  `POSTGRES_PASSWORD` into `\u002Fetc\u002Fcortexcloud\u002Fcortexcloud.env` and\n  updating both `\u002Froot\u002Fcc_backup.sh` AND `\u002Froot\u002Fcc_restore_test.sh` to\n  read the same file. The backup script now also `source`s the env at\n  start so cron runs work without external env setup. Before any future\n  rotation of `POSTGRES_PASSWORD`, edit ONLY `\u002Fetc\u002Fcortexcloud\u002Fcortexcloud.env`.\n- **Live paid-smoke scripts (canonical, verified Aug 2026).** Use these\n  names — `data_paid_smoke.py` and `research_paid_smoke.py` referenced\n  from older memory do NOT exist. The current set:\n  - `scripts\u002Fautomation_paid_smoke.py` — 5 endpoints + estimate; full\n    402→sign→CDP→200+ledger cycle. Default base: pass as `argv[1]`.\n  - `scripts\u002Fagent_smoke.py` — discovery + estimate + 402 challenge shape\n    (no real settle).\n  - `scripts\u002Fverify_integration.py` — `--mode public` (free checks),\n    `--mode private` (needs `--api-key`), `--mode all` (real settle\n    against `--base`).\n  Always pass the public base `https:\u002F\u002Fapi.cortexcloud.org` to verify the\n  Cloudflare-fronted production. Localhost `http:\u002F\u002F127.0.0.1:8000` fails\n  the CDP settle leg because the x402 challenge resource URL is built\n  from the incoming request URL and CDP requires `https:\u002F\u002F`.\n- **systemd inline `Environment=` is NOT authoritative for keys sourced\n  from `EnvironmentFile=`.** When the same key (e.g. `X402_ENABLED`)\n  appears in BOTH the unit's inline `Environment=` line AND\n  `\u002Fetc\u002Fcortexcloud\u002Fcortexcloud.env`, the running process picks up the\n  env-file value, not the unit-inline one — even when systemd's own\n  `systemctl show -p Environment` shows both. Always grep the live\n  process environ (`tr '\\0' '\\n' \u003C \u002Fproc\u002F$(systemctl show -p MainPID\n  --value)\u002Fenviron | grep KEY=`) to confirm what's actually loaded. If\n  you intend the unit-inline to win, REMOVE the key from the env file\n  (or the env-file value will keep winning in practice). The reasoning\n  is subtle and depends on systemd's parser treating `Environment=` as\n  one line of multiple pairs vs `EnvironmentFile=` lines; the empirical\n  rule is: trust only the running process, never just the file.\n- **`pct push \u003Cvmid> \u003Csrc> \u003Cdst>` over SSH silently no-ops when `\u003Csrc>`\n  is on the AGENT host, not the Proxmox host.** `pct push` resolves\n  `\u003Csrc>` on the host where pct itself runs (= the PVE host). Driving\n  it as `ssh ninyi \"pct push 105 \u002Ftmp\u002Fx.py \u002Fopt\u002Fx.py\"` with `\u002Ftmp\u002Fx.py`\n  existing only on the Hermes host reports \"pushed\" (exit 0) but\n  writes nothing. The reliable push for an agent-host-only file is the\n  stdin-tee pattern: `ssh -i ~\u002F.ssh\u002Fhermes_ninyi root@192.168.1.11 \"pct\n  exec 105 -- tee \u002Fopt\u002F...\u002Fx.py > \u002Fdev\u002Fnull\" \u003C \u002Flocal\u002Fx.py` followed by\n  a marker `grep` to confirm. For bulk edits to `\u002Fetc\u002Fcortexcloud\u002F...`\n  use `pct push` ONLY after `scp` to the PVE host first.\n\n## References\n- `references\u002Fstaging-validation.md` — exact commands for checkout, key\n  injection, openapi regen, paid-smoke run, ledger check.\n- `references\u002Fml-cost-comparison.md` — current provider per-call costs\n  (fal\u002FReplicate\u002FOpenRouter\u002FCohere), CortexCloud margin math, and the\n  funding-vs-breakeven protocol for gating endpoints on provider credits.\n- `references\u002Fbackup-restore-test.md` — the actual restore pattern (off-host\n  push via rclone + weekly cron that restores the latest dump into a fresh\n  Postgres DB and verifies 4 critical tables match live counts). Always\n  pair backup creation with a restore test; backup-only is theater.\n- `references\u002Fprod-selfheal.md` — why prod silently drifts (git divergence),\n  the self-heal cron pattern, and the ExecStartPre anti-pattern.\n- `scripts\u002Fprod_selfheal.sh` — SSH-to-prod `git fetch && reset --hard\n  origin\u002Fmain` self-heal (run on a 15-min schedule).\n",{},"main","38b32c99e7ed0b8e215d638e92cfa452c1ec3079","skills\u002Fimported\u002Fcortexcloud-api-dev\u002Fcortexcloud-api-dev","https:\u002F\u002Fgithub.com\u002Fjonahthan433\u002FCortexOS","https:\u002F\u002Fgithub.com\u002Fjonahthan433","AI Consultant","2026-10-24 05:13:39",{"source":7,"skillName":5,"commands":30,"prompt":40,"zipAvailable":41},[31,34,37],{"tool":32,"command":33},"npx","npx skills add jonahthan433\u002FCortexOS --skill cortexcloud-api-dev",{"tool":35,"command":36},"bunx","bunx skills add jonahthan433\u002FCortexOS --skill cortexcloud-api-dev",{"tool":38,"command":39},"pnpm","pnpm dlx skills add jonahthan433\u002FCortexOS --skill cortexcloud-api-dev","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fjonahthan433\u002FCortexOS\u002Fblob\u002Fmain\u002Fskills\u002Fimported\u002Fcortexcloud-api-dev\u002Fcortexcloud-api-dev\u002FSKILL.md",true,[43],{"path":44,"resourceType":45,"resourceTypeDesc":46,"sizeBytes":47,"sourceHtmlUrl":48},"skill.json","REFERENCE","参考文档",612,"https:\u002F\u002Fgithub.com\u002Fjonahthan433\u002FCortexOS\u002Fblob\u002Fmain\u002Fskills\u002Fimported\u002Fcortexcloud-api-dev\u002Fcortexcloud-api-dev\u002Fskill.json",[50,56,62,68,74,80],{"skillNo":51,"name":52,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":53,"categories":54,"keywords":55,"publishedAt":18},"01M7EDQZDQX3Q8Y7GCQX6KN9V7","opportunity-brief","https:\u002F\u002Fgithub.com\u002Fjonahthan433\u002FCortexOS\u002Fblob\u002Fmain\u002Fskills\u002Fsales\u002Fopportunity-brief\u002FSKILL.md",[],[],{"skillNo":57,"name":58,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":59,"categories":60,"keywords":61,"publishedAt":18},"01M7EDQYA0V9Y99VKBREJJ3MRT","morning-intel","https:\u002F\u002Fgithub.com\u002Fjonahthan433\u002FCortexOS\u002Fblob\u002Fmain\u002Fskills\u002Fresearch\u002Fmorning-intel\u002FSKILL.md",[],[],{"skillNo":63,"name":64,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":65,"categories":66,"keywords":67,"publishedAt":18},"01M7EDQVX1JVY0B6PDHKKGM19G","decision-brief","https:\u002F\u002Fgithub.com\u002Fjonahthan433\u002FCortexOS\u002Fblob\u002Fmain\u002Fskills\u002Fresearch\u002Fdecision-brief\u002FSKILL.md",[],[],{"skillNo":69,"name":70,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":71,"categories":72,"keywords":73,"publishedAt":18},"01M7EDQV1GENZAC2SZSD8KZ3GM","weekly-review","https:\u002F\u002Fgithub.com\u002Fjonahthan433\u002FCortexOS\u002Fblob\u002Fmain\u002Fskills\u002Fproductivity\u002Fweekly-review\u002FSKILL.md",[],[],{"skillNo":75,"name":76,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":77,"categories":78,"keywords":79,"publishedAt":18},"01M7EDQT2KETJ1Y3CGVN9EKW2J","system-health","https:\u002F\u002Fgithub.com\u002Fjonahthan433\u002FCortexOS\u002Fblob\u002Fmain\u002Fskills\u002Fops\u002Fsystem-health\u002FSKILL.md",[],[],{"skillNo":81,"name":82,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":83,"categories":84,"keywords":85,"publishedAt":18},"01M7EDQQN2JK3XPWMS1M4T0F3K","backup-restore","https:\u002F\u002Fgithub.com\u002Fjonahthan433\u002FCortexOS\u002Fblob\u002Fmain\u002Fskills\u002Fops\u002Fbackup-restore\u002FSKILL.md",[],[]]