Skip to content

feat(cognigate): port reference/agents/auth_keys routers from external repo#99

Merged
vorionsys merged 2 commits intomainfrom
feat/cognigate-foundation-routers
Apr 11, 2026
Merged

feat(cognigate): port reference/agents/auth_keys routers from external repo#99
vorionsys merged 2 commits intomainfrom
feat/cognigate-foundation-routers

Conversation

@vorionsys
Copy link
Copy Markdown
Owner

Summary

Track 2 PR1 of the cognigate cherry-pick plan. Ports the three lowest-risk, zero-dependency routers from the external standalone cognigate repo into `cognigate-api/`, restoring 3 of the 4 missing resource categories that `packages/n8n-nodes-cognigate` expects.

The problem

Cognigate was partially migrated from `c:/voriongit/cognigate/` into the monorepo as `cognigate-api/`. The external repo had 9 routers that never made it across. The monorepo's `cognigate-api` only registered 6 routers (health, intent, enforce, proof, admin, integrity) while the n8n community node (packages/n8n-nodes-cognigate) dispatches to 8 resource categories. Result: point the n8n node at the monorepo and ~50% of operations 404.

What this PR ships

Three routers with near-zero transitive dependencies:

  • reference — read-only lookups: tiers, capabilities, error codes, rate limits, versions, products, domains
  • agents — CRUD for agent registration with observation-tier-based initial scores and ceilings
  • auth_keys — API key CRUD behind `X-API-Key` with IA-5(1) strength validation

Files added

File LOC Purpose
`app/constants_bridge.py` 1268 Shared constants (TIER_THRESHOLDS, CAPABILITIES, RATE_LIMITS, etc). Pure stdlib leaf, no transitive deps.
`app/routers/reference.py` 303 12 GET endpoints
`app/routers/agents.py` 217 POST/GET/PATCH/DELETE `/v1/agents`
`app/routers/auth_keys.py` 122 POST/GET/DELETE `/v1/auth/keys`
`tests/test_reference.py` 19 tests Smoke + filter + 404 paths
`tests/test_agents.py` 14 tests All 5 observation tiers, conflict, tier filter, update, revoke
`tests/test_auth_keys.py` 13 tests Auth enforcement, create/list/delete, hash-not-raw, strength validation

Files modified

  • app/core/auth.py — add `verify_api_key` (X-API-Key Security dependency) and `validate_api_key_strength` (IA-5(1): length ≥ 32, known-weak rejection, weak-pattern detection, character-class diversity). Upgrade `generate_api_key` to re-validate with `max_attempts` defense-in-depth.
  • app/config.py — add `api_key: str` setting for pipeline endpoints
  • app/main.py — import + register the 3 new routers with `api_prefix`

Test result

```
cd cognigate-api && pytest
============================= 191 passed in 2.37s =============================
```
+46 new tests over the previous 145. All existing tests still green. Black + ruff clean on changed files.

Deep Space exclusion (load-bearing)

Did not port `verify_deepspace_key`, `tmr_consensus`, `monte_carlo`, `self_healing`, or `deepspace.py`. Per external commit `46613a3 feat(security): isolate deep space proprietary algorithms with separate authentication`, these are intentionally excluded from the OSS monorepo. Their absence prevents accidental wiring.

What's next in the cherry-pick sequence

  • PR2: alembic bootstrap against existing schema + CI drift check (prerequisite for PR3)
  • PR3: `trust` router + `trust_decay.py` + `TrustStateDB`/`TrustSignalDB` + migration 0002
  • PR4: `compliance` router + `control_health.py` (after signatures/velocity API drift check)
  • PR5: `gateway` router + `upstream_client.py` (cognigate.dev unified developer entry point)

After PR5 lands, the n8n node should exercise all 8 resources successfully against the monorepo. Full plan in `C:\Users\racas.claude\plans\radiant-honking-puddle.md`.

Test plan

  • cognigate-api pytest → 191 passed (145 existing + 46 new)
  • Start cognigate-api locally, hit `GET /v1/reference/tiers` → 200 with 8 tiers
  • Hit `POST /v1/agents` with `{"name": "test"}` → 201 with GRAY_BOX defaults
  • Hit `POST /v1/auth/keys` without `X-API-Key` → 401
  • With valid `X-API-Key` → 201 and raw key returned once
  • n8n-nodes-cognigate `reference`, `agent`, and `auth_keys` operations succeed against local cognigate-api

@vorionsys vorionsys force-pushed the feat/cognigate-foundation-routers branch 2 times, most recently from be0d903 to 1190db9 Compare April 11, 2026 21:28
chunkstar and others added 2 commits April 11, 2026 17:46
…l repo

Cognigate was partially migrated from the standalone c:/voriongit/cognigate
repo into the monorepo as cognigate-api/. The external repo had 9 routers
that never made it across; 3 of them are low-risk, zero-dependency ports
that restore the n8n-nodes-cognigate package's API contract:

- reference — read-only lookups (tiers, capabilities, error codes, rate
  limits, versions, products, domains) — thin projection over
  constants_bridge.py
- agents — CRUD for agent registration (in-memory store, observation
  tiers BLACK_BOX..VERIFIED_BOX with score-based ceilings)
- auth_keys — API key CRUD behind X-API-Key auth with IA-5(1) strength
  validation

## Port contents

Added files:
- app/constants_bridge.py (1268 LOC) — shared constants source used by
  the 3 new routers; pure stdlib leaf, no transitive deps
- app/routers/reference.py, agents.py, auth_keys.py
- tests/test_reference.py (19 tests)
- tests/test_agents.py (14 tests)
- tests/test_auth_keys.py (13 tests)

Modified:
- app/core/auth.py — add verify_api_key (X-API-Key header) and
  validate_api_key_strength (IA-5(1) — length, weak-pattern detection,
  known-weak rejection, character class diversity). Upgrade
  generate_api_key to re-validate generated keys with max_attempts
  defense-in-depth. Do NOT port verify_deepspace_key — its absence is
  load-bearing per external commit 46613a3 (proprietary isolation).
- app/config.py — add api_key: str setting for pipeline endpoints
- app/main.py — import + register the 3 new routers with api_prefix

## Test result

pytest: 191 passed (was 145 — added 46 new tests)
- 19 reference tests covering tiers/capabilities/errors/rate-limits/
  versions/products/domains, filter parameters, and 404 paths
- 14 agents tests covering register (all 5 observation tiers), list,
  get, update, delete, duplicate conflict
- 13 auth_keys tests covering missing/wrong X-API-Key, create/list/
  delete, hash-not-raw storage, plus unit-level validate_api_key_strength
  cases (empty, too-short, known-weak, all-zeros, no-diversity, strong)

## Why this matters

packages/n8n-nodes-cognigate (870 LOC, 46 jest tests) dispatches to
resources: intent, enforce, proof, agent, trust, health, reference,
compliance. The monorepo's cognigate-api only exposed intent/enforce/
proof/health/admin/integrity before this PR. Pointing the n8n node at
the monorepo meant ~50% of operations 404'd. This PR restores 3 of the
4 missing resource categories (reference, agent, plus auth_keys).
Remaining: trust (PR3), compliance (PR4), gateway (PR5).

## What's explicitly NOT in this PR

- Deep Space modules (tmr_consensus, monte_carlo, self_healing,
  deepspace router, verify_deepspace_key) — intentionally isolated as
  proprietary per external commit 46613a3
- theme.py and documentation/tools routers — UI theming not used by
  n8n node
- TOTP MFA (verify_admin_key_with_mfa) — can be ported later as its
  own admin UX improvement
- Alembic bootstrap — PR2 (prerequisite for PR3 trust tables)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Ruff fixes on the new files I introduced in PR1:
- auto-fix I001 import sorting in test files + router files
- UP045 type annotations: replace Optional[X] with X | None
- N815: add targeted noqa for camelCase API-shape fields (agentId,
  observationTier) that must stay camelCase to match the n8n node
  contract
- E501: wrap long docstring lines in reference.py

constants_bridge.py is a mechanical port from
@vorionsys/shared-constants. Its (str, Enum) classes and data
dictionary line widths are intentional API-shape mirrors of the
TypeScript source. Added a file-level ruff noqa for UP042/I001/E501
rather than mutating the generated mirror; also sorted the Enum
import within it.

Tests: 191 passed (unchanged). Ruff clean on the 8 PR1 files.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vorionsys vorionsys force-pushed the feat/cognigate-foundation-routers branch from 1190db9 to 1f2956a Compare April 11, 2026 21:46
@vorionsys vorionsys merged commit a6eb61d into main Apr 11, 2026
47 of 53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants