Compare commits
6 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 38c2bd702a | |||
| a11f3a7abb | |||
| 4ac99403bd | |||
| 87f7ad0dc4 | |||
| 4c27cf4bd0 | |||
| 7d4a03fd79 |
15 changed files with 29 additions and 485 deletions
48
CHANGELOG.md
48
CHANGELOG.md
|
|
@ -6,54 +6,6 @@ Versions follow [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## [0.10.0] — 2026-04-12
|
|
||||||
|
|
||||||
### Added
|
|
||||||
|
|
||||||
**`circuitforge_core.community`** — shared community signal module (BSL 1.1, closes #44)
|
|
||||||
|
|
||||||
Provides the PostgreSQL-backed infrastructure for the cross-product community fine-tuning signal pipeline. Products write signals; the training pipeline reads them.
|
|
||||||
|
|
||||||
- `CommunityDB` — psycopg2 connection pool with `run_migrations()`. Picks up all `.sql` files from `circuitforge_core/community/migrations/` in filename order. Safe to call on every startup (idempotent `CREATE TABLE IF NOT EXISTS`).
|
|
||||||
- `CommunityPost` — frozen dataclass capturing a user-authored community post with a snapshot of the originating product item (`element_snapshot` as a tuple of key-value pairs for immutability).
|
|
||||||
- `SharedStore` — base class for product-specific community stores. Provides typed `pg_read()` and `pg_write()` helpers that products subclass without re-implementing connection management.
|
|
||||||
- Migration 001: `community_posts` schema (id, product, item_id, pseudonym, title, body, element_snapshot JSONB, created_at).
|
|
||||||
- Migration 002: `community_reactions` stub (post_id FK, pseudonym, reaction_type, created_at).
|
|
||||||
- `psycopg2-binary` added to `[community]` optional extras in `pyproject.toml`.
|
|
||||||
- All community classes exported from `circuitforge_core.community`.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## [0.9.0] — 2026-04-10
|
|
||||||
|
|
||||||
### Added
|
|
||||||
|
|
||||||
**`circuitforge_core.text`** — OpenAI-compatible `/v1/chat/completions` endpoint and pipeline crystallization engine.
|
|
||||||
|
|
||||||
**`circuitforge_core.pipeline`** — multimodal pipeline with staged output crystallization. Products queue draft outputs for human review before committing.
|
|
||||||
|
|
||||||
**`circuitforge_core.stt`** — speech-to-text module. `FasterWhisperBackend` for local transcription via `faster-whisper`. Managed FastAPI app mountable in any product.
|
|
||||||
|
|
||||||
**`circuitforge_core.tts`** — text-to-speech module. `ChatterboxTurbo` backend for local synthesis. Managed FastAPI app.
|
|
||||||
|
|
||||||
**Accessibility preferences** — `preferences` module extended with structured accessibility fields (motion reduction, high contrast, font size, focus highlight) under `accessibility.*` key path.
|
|
||||||
|
|
||||||
**LLM output corrections router** — `make_corrections_router()` for collecting LLM output corrections in any product. Stores corrections in product SQLite for future fine-tuning.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## [0.8.0] — 2026-04-08
|
|
||||||
|
|
||||||
### Added
|
|
||||||
|
|
||||||
**`circuitforge_core.vision`** — cf-vision managed service shim. Routes vision inference requests to a local cf-vision worker (moondream2 / SigLIP). Closes #43.
|
|
||||||
|
|
||||||
**`circuitforge_core.api.feedback`** — `make_feedback_router()` shared Forgejo issue-filing router. Products mount it under `/api/feedback`; requires `FORGEJO_API_TOKEN`. Closes #30.
|
|
||||||
|
|
||||||
**License validation** — `CF_LICENSE_KEY` validation via Heimdall REST API. Products call `validate_license(key, product)` to gate premium features. Closes #26.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## [0.7.0] — 2026-04-04
|
## [0.7.0] — 2026-04-04
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
||||||
21
LICENSE
21
LICENSE
|
|
@ -1,21 +0,0 @@
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2026 CircuitForge LLC
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
|
|
@ -1,8 +1,3 @@
|
||||||
__version__ = "0.10.0"
|
__version__ = "0.10.0"
|
||||||
|
|
||||||
try:
|
from circuitforge_core.community import CommunityDB, CommunityPost, SharedStore
|
||||||
from circuitforge_core.community import CommunityDB, CommunityPost, SharedStore
|
|
||||||
__all__ = ["CommunityDB", "CommunityPost", "SharedStore"]
|
|
||||||
except ImportError:
|
|
||||||
# psycopg2 not installed — install with: pip install circuitforge-core[community]
|
|
||||||
pass
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
# circuitforge_core/community/__init__.py
|
# circuitforge_core/community/__init__.py
|
||||||
# MIT License
|
# MIT License
|
||||||
|
|
||||||
from .models import CommunityPost
|
|
||||||
from .db import CommunityDB
|
from .db import CommunityDB
|
||||||
|
from .models import CommunityPost
|
||||||
from .store import SharedStore
|
from .store import SharedStore
|
||||||
from .snipe_store import SellerTrustSignal, SnipeCommunityStore
|
|
||||||
|
|
||||||
__all__ = ["CommunityDB", "CommunityPost", "SharedStore", "SellerTrustSignal", "SnipeCommunityStore"]
|
__all__ = ["CommunityDB", "CommunityPost", "SharedStore"]
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ CREATE TABLE IF NOT EXISTS community_posts (
|
||||||
allergen_flags JSONB NOT NULL DEFAULT '[]',
|
allergen_flags JSONB NOT NULL DEFAULT '[]',
|
||||||
flavor_molecules JSONB NOT NULL DEFAULT '[]',
|
flavor_molecules JSONB NOT NULL DEFAULT '[]',
|
||||||
|
|
||||||
-- USDA FDC macros
|
-- USDA FDC (Food Data Central) macros
|
||||||
fat_pct REAL,
|
fat_pct REAL,
|
||||||
protein_pct REAL,
|
protein_pct REAL,
|
||||||
moisture_pct REAL,
|
moisture_pct REAL,
|
||||||
|
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
-- Seller trust signals: confirmed scammer / confirmed legitimate outcomes from Snipe.
|
|
||||||
-- Separate table from community_posts (Kiwi-specific) — seller signals are a
|
|
||||||
-- structurally different domain and should not overload the recipe post schema.
|
|
||||||
-- Applies to: cf_community PostgreSQL database (hosted by cf-orch).
|
|
||||||
-- BSL boundary: table schema is MIT; signal ingestion route in cf-orch is BSL 1.1.
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS seller_trust_signals (
|
|
||||||
id BIGSERIAL PRIMARY KEY,
|
|
||||||
platform TEXT NOT NULL DEFAULT 'ebay',
|
|
||||||
platform_seller_id TEXT NOT NULL,
|
|
||||||
confirmed_scam BOOLEAN NOT NULL,
|
|
||||||
signal_source TEXT NOT NULL, -- 'blocklist_add' | 'community_vote' | 'resolved'
|
|
||||||
flags JSONB NOT NULL DEFAULT '[]', -- red flag keys at time of signal
|
|
||||||
source_product TEXT NOT NULL DEFAULT 'snipe',
|
|
||||||
recorded_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
||||||
);
|
|
||||||
|
|
||||||
-- No PII: platform_seller_id is the public eBay username or platform ID only.
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_seller_trust_platform_id
|
|
||||||
ON seller_trust_signals (platform, platform_seller_id);
|
|
||||||
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_seller_trust_confirmed
|
|
||||||
ON seller_trust_signals (confirmed_scam);
|
|
||||||
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_seller_trust_recorded
|
|
||||||
ON seller_trust_signals (recorded_at DESC);
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
-- 004_community_categories.sql
|
|
||||||
-- MIT License
|
|
||||||
-- Shared eBay category tree published by credentialed Snipe instances.
|
|
||||||
-- Credentialless instances pull from this table during refresh().
|
|
||||||
-- Privacy: only public eBay category metadata (IDs, names, paths) — no user data.
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS community_categories (
|
|
||||||
id SERIAL PRIMARY KEY,
|
|
||||||
platform TEXT NOT NULL DEFAULT 'ebay',
|
|
||||||
category_id TEXT NOT NULL,
|
|
||||||
name TEXT NOT NULL,
|
|
||||||
full_path TEXT NOT NULL,
|
|
||||||
source_product TEXT NOT NULL DEFAULT 'snipe',
|
|
||||||
published_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
||||||
UNIQUE (platform, category_id)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_community_cat_name
|
|
||||||
ON community_categories (platform, name);
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
# Community module migrations
|
|
||||||
# These SQL files are shipped with circuitforge-core so cf-orch can locate them via importlib.resources.
|
|
||||||
|
|
@ -61,25 +61,32 @@ class CommunityPost:
|
||||||
allergen_flags: tuple
|
allergen_flags: tuple
|
||||||
flavor_molecules: tuple
|
flavor_molecules: tuple
|
||||||
|
|
||||||
# USDA FDC macros (optional -- may not be available for all recipes)
|
# USDA FDC (Food Data Central) macros (optional -- may not be available for all recipes)
|
||||||
fat_pct: float | None
|
fat_pct: float | None
|
||||||
protein_pct: float | None
|
protein_pct: float | None
|
||||||
moisture_pct: float | None
|
moisture_pct: float | None
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
def __new__(cls, **kwargs):
|
||||||
# Coerce list fields to tuples (frozen dataclass: use object.__setattr__)
|
# Convert lists to tuples before frozen dataclass assignment
|
||||||
for key in ("slots", "dietary_tags", "allergen_flags", "flavor_molecules"):
|
for key in ("slots", "dietary_tags", "allergen_flags", "flavor_molecules"):
|
||||||
val = getattr(self, key)
|
if key in kwargs and isinstance(kwargs[key], list):
|
||||||
if isinstance(val, list):
|
kwargs[key] = tuple(kwargs[key])
|
||||||
object.__setattr__(self, key, tuple(val))
|
return object.__new__(cls)
|
||||||
|
|
||||||
# Validate post_type
|
def __init__(self, **kwargs):
|
||||||
|
# Convert lists to tuples
|
||||||
|
for key in ("slots", "dietary_tags", "allergen_flags", "flavor_molecules"):
|
||||||
|
if key in kwargs and isinstance(kwargs[key], list):
|
||||||
|
kwargs[key] = tuple(kwargs[key])
|
||||||
|
for f in self.__dataclass_fields__:
|
||||||
|
object.__setattr__(self, f, kwargs[f])
|
||||||
|
self.__post_init__()
|
||||||
|
|
||||||
|
def __post_init__(self) -> None:
|
||||||
if self.post_type not in _VALID_POST_TYPES:
|
if self.post_type not in _VALID_POST_TYPES:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"post_type must be one of {sorted(_VALID_POST_TYPES)}, got {self.post_type!r}"
|
f"post_type must be one of {sorted(_VALID_POST_TYPES)}, got {self.post_type!r}"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Validate scores
|
|
||||||
for score_name in (
|
for score_name in (
|
||||||
"seasoning_score", "richness_score", "brightness_score",
|
"seasoning_score", "richness_score", "brightness_score",
|
||||||
"depth_score", "aroma_score", "structure_score",
|
"depth_score", "aroma_score", "structure_score",
|
||||||
|
|
|
||||||
|
|
@ -1,253 +0,0 @@
|
||||||
# circuitforge_core/community/snipe_store.py
|
|
||||||
# MIT License
|
|
||||||
"""Snipe community store — publishes seller trust signals to the shared community DB.
|
|
||||||
|
|
||||||
Snipe products subclass SharedStore here to write seller trust signals
|
|
||||||
(confirmed scammer / confirmed legitimate) to the cf_community PostgreSQL.
|
|
||||||
These signals aggregate across all Snipe users to power the cross-user
|
|
||||||
seller trust classifier fine-tuning corpus.
|
|
||||||
|
|
||||||
Privacy: only platform_seller_id (public eBay username/ID) and flag keys
|
|
||||||
are written. No PII is stored.
|
|
||||||
|
|
||||||
Usage:
|
|
||||||
from circuitforge_core.community import CommunityDB
|
|
||||||
from circuitforge_core.community.snipe_store import SnipeCommunityStore
|
|
||||||
|
|
||||||
db = CommunityDB.from_env()
|
|
||||||
store = SnipeCommunityStore(db, source_product="snipe")
|
|
||||||
store.publish_seller_signal(
|
|
||||||
platform_seller_id="ebay-username",
|
|
||||||
confirmed_scam=True,
|
|
||||||
signal_source="blocklist_add",
|
|
||||||
flags=["new_account", "suspicious_price"],
|
|
||||||
)
|
|
||||||
"""
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import json
|
|
||||||
import logging
|
|
||||||
from dataclasses import dataclass
|
|
||||||
from datetime import datetime, timezone
|
|
||||||
|
|
||||||
from .store import SharedStore
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
|
||||||
class SellerTrustSignal:
|
|
||||||
"""Immutable snapshot of a recorded seller trust signal."""
|
|
||||||
id: int
|
|
||||||
platform: str
|
|
||||||
platform_seller_id: str
|
|
||||||
confirmed_scam: bool
|
|
||||||
signal_source: str
|
|
||||||
flags: tuple
|
|
||||||
source_product: str
|
|
||||||
recorded_at: datetime
|
|
||||||
|
|
||||||
|
|
||||||
class SnipeCommunityStore(SharedStore):
|
|
||||||
"""Community store for Snipe — seller trust signal publishing and querying."""
|
|
||||||
|
|
||||||
def __init__(self, db, source_product: str = "snipe") -> None:
|
|
||||||
super().__init__(db, source_product=source_product)
|
|
||||||
|
|
||||||
def publish_seller_signal(
|
|
||||||
self,
|
|
||||||
platform_seller_id: str,
|
|
||||||
confirmed_scam: bool,
|
|
||||||
signal_source: str,
|
|
||||||
flags: list[str] | None = None,
|
|
||||||
platform: str = "ebay",
|
|
||||||
) -> SellerTrustSignal:
|
|
||||||
"""Record a seller trust outcome in the shared community DB.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
platform_seller_id: Public eBay username or platform ID (no PII).
|
|
||||||
confirmed_scam: True = confirmed bad actor; False = confirmed legitimate.
|
|
||||||
signal_source: Origin of the signal.
|
|
||||||
'blocklist_add' — user explicitly added to local blocklist
|
|
||||||
'community_vote' — consensus threshold reached from multiple reports
|
|
||||||
'resolved' — seller resolved as legitimate over time
|
|
||||||
flags: List of red-flag keys active at signal time (e.g. ["new_account"]).
|
|
||||||
platform: Source auction platform (default "ebay").
|
|
||||||
|
|
||||||
Returns the inserted SellerTrustSignal.
|
|
||||||
"""
|
|
||||||
flags = flags or []
|
|
||||||
conn = self._db.getconn()
|
|
||||||
try:
|
|
||||||
with conn.cursor() as cur:
|
|
||||||
cur.execute(
|
|
||||||
"""
|
|
||||||
INSERT INTO seller_trust_signals
|
|
||||||
(platform, platform_seller_id, confirmed_scam,
|
|
||||||
signal_source, flags, source_product)
|
|
||||||
VALUES (%s, %s, %s, %s, %s::jsonb, %s)
|
|
||||||
RETURNING id, recorded_at
|
|
||||||
""",
|
|
||||||
(
|
|
||||||
platform,
|
|
||||||
platform_seller_id,
|
|
||||||
confirmed_scam,
|
|
||||||
signal_source,
|
|
||||||
json.dumps(flags),
|
|
||||||
self._source_product,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
row = cur.fetchone()
|
|
||||||
conn.commit()
|
|
||||||
return SellerTrustSignal(
|
|
||||||
id=row[0],
|
|
||||||
platform=platform,
|
|
||||||
platform_seller_id=platform_seller_id,
|
|
||||||
confirmed_scam=confirmed_scam,
|
|
||||||
signal_source=signal_source,
|
|
||||||
flags=tuple(flags),
|
|
||||||
source_product=self._source_product,
|
|
||||||
recorded_at=row[1],
|
|
||||||
)
|
|
||||||
except Exception:
|
|
||||||
conn.rollback()
|
|
||||||
log.warning(
|
|
||||||
"Failed to publish seller signal for %s (%s)",
|
|
||||||
platform_seller_id, signal_source, exc_info=True,
|
|
||||||
)
|
|
||||||
raise
|
|
||||||
finally:
|
|
||||||
self._db.putconn(conn)
|
|
||||||
|
|
||||||
def list_signals_for_seller(
|
|
||||||
self,
|
|
||||||
platform_seller_id: str,
|
|
||||||
platform: str = "ebay",
|
|
||||||
limit: int = 50,
|
|
||||||
) -> list[SellerTrustSignal]:
|
|
||||||
"""Return recent trust signals for a specific seller."""
|
|
||||||
conn = self._db.getconn()
|
|
||||||
try:
|
|
||||||
with conn.cursor() as cur:
|
|
||||||
cur.execute(
|
|
||||||
"""
|
|
||||||
SELECT id, platform, platform_seller_id, confirmed_scam,
|
|
||||||
signal_source, flags, source_product, recorded_at
|
|
||||||
FROM seller_trust_signals
|
|
||||||
WHERE platform = %s AND platform_seller_id = %s
|
|
||||||
ORDER BY recorded_at DESC
|
|
||||||
LIMIT %s
|
|
||||||
""",
|
|
||||||
(platform, platform_seller_id, limit),
|
|
||||||
)
|
|
||||||
rows = cur.fetchall()
|
|
||||||
return [
|
|
||||||
SellerTrustSignal(
|
|
||||||
id=r[0], platform=r[1], platform_seller_id=r[2],
|
|
||||||
confirmed_scam=r[3], signal_source=r[4],
|
|
||||||
flags=tuple(json.loads(r[5]) if isinstance(r[5], str) else r[5] or []),
|
|
||||||
source_product=r[6], recorded_at=r[7],
|
|
||||||
)
|
|
||||||
for r in rows
|
|
||||||
]
|
|
||||||
finally:
|
|
||||||
self._db.putconn(conn)
|
|
||||||
|
|
||||||
def scam_signal_count(self, platform_seller_id: str, platform: str = "ebay") -> int:
|
|
||||||
"""Return the number of confirmed_scam=True signals for a seller.
|
|
||||||
|
|
||||||
Used to determine if a seller has crossed the community consensus threshold
|
|
||||||
for appearing in the shared blocklist.
|
|
||||||
"""
|
|
||||||
conn = self._db.getconn()
|
|
||||||
try:
|
|
||||||
with conn.cursor() as cur:
|
|
||||||
cur.execute(
|
|
||||||
"""
|
|
||||||
SELECT COUNT(*) FROM seller_trust_signals
|
|
||||||
WHERE platform = %s AND platform_seller_id = %s AND confirmed_scam = TRUE
|
|
||||||
""",
|
|
||||||
(platform, platform_seller_id),
|
|
||||||
)
|
|
||||||
return cur.fetchone()[0]
|
|
||||||
finally:
|
|
||||||
self._db.putconn(conn)
|
|
||||||
|
|
||||||
def publish_categories(
|
|
||||||
self,
|
|
||||||
categories: list[tuple[str, str, str]],
|
|
||||||
platform: str = "ebay",
|
|
||||||
) -> int:
|
|
||||||
"""Upsert a batch of eBay leaf categories into the shared community table.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
categories: List of (category_id, name, full_path) tuples.
|
|
||||||
platform: Source auction platform (default "ebay").
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Number of rows upserted.
|
|
||||||
"""
|
|
||||||
if not categories:
|
|
||||||
return 0
|
|
||||||
conn = self._db.getconn()
|
|
||||||
try:
|
|
||||||
with conn.cursor() as cur:
|
|
||||||
cur.executemany(
|
|
||||||
"""
|
|
||||||
INSERT INTO community_categories
|
|
||||||
(platform, category_id, name, full_path, source_product)
|
|
||||||
VALUES (%s, %s, %s, %s, %s)
|
|
||||||
ON CONFLICT (platform, category_id)
|
|
||||||
DO UPDATE SET
|
|
||||||
name = EXCLUDED.name,
|
|
||||||
full_path = EXCLUDED.full_path,
|
|
||||||
source_product = EXCLUDED.source_product,
|
|
||||||
published_at = NOW()
|
|
||||||
""",
|
|
||||||
[
|
|
||||||
(platform, cid, name, path, self._source_product)
|
|
||||||
for cid, name, path in categories
|
|
||||||
],
|
|
||||||
)
|
|
||||||
conn.commit()
|
|
||||||
return len(categories)
|
|
||||||
except Exception:
|
|
||||||
conn.rollback()
|
|
||||||
log.warning(
|
|
||||||
"Failed to publish %d categories to community store",
|
|
||||||
len(categories), exc_info=True,
|
|
||||||
)
|
|
||||||
raise
|
|
||||||
finally:
|
|
||||||
self._db.putconn(conn)
|
|
||||||
|
|
||||||
def fetch_categories(
|
|
||||||
self,
|
|
||||||
platform: str = "ebay",
|
|
||||||
limit: int = 500,
|
|
||||||
) -> list[tuple[str, str, str]]:
|
|
||||||
"""Fetch community-contributed eBay categories.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
platform: Source auction platform (default "ebay").
|
|
||||||
limit: Maximum rows to return.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
List of (category_id, name, full_path) tuples ordered by name.
|
|
||||||
"""
|
|
||||||
conn = self._db.getconn()
|
|
||||||
try:
|
|
||||||
with conn.cursor() as cur:
|
|
||||||
cur.execute(
|
|
||||||
"""
|
|
||||||
SELECT category_id, name, full_path
|
|
||||||
FROM community_categories
|
|
||||||
WHERE platform = %s
|
|
||||||
ORDER BY name
|
|
||||||
LIMIT %s
|
|
||||||
""",
|
|
||||||
(platform, limit),
|
|
||||||
)
|
|
||||||
return [(row[0], row[1], row[2]) for row in cur.fetchall()]
|
|
||||||
finally:
|
|
||||||
self._db.putconn(conn)
|
|
||||||
|
|
@ -18,7 +18,7 @@ def _row_to_post(row: dict) -> CommunityPost:
|
||||||
"""Convert a psycopg2 row dict to a CommunityPost.
|
"""Convert a psycopg2 row dict to a CommunityPost.
|
||||||
|
|
||||||
JSONB columns (slots, dietary_tags, allergen_flags, flavor_molecules) come
|
JSONB columns (slots, dietary_tags, allergen_flags, flavor_molecules) come
|
||||||
back from psycopg2 as Python lists already — no json.loads() needed.
|
back from psycopg2 as Python lists already -- no json.loads() needed.
|
||||||
"""
|
"""
|
||||||
return CommunityPost(
|
return CommunityPost(
|
||||||
slug=row["slug"],
|
slug=row["slug"],
|
||||||
|
|
@ -66,9 +66,8 @@ class SharedStore:
|
||||||
All methods return new objects (immutable pattern). Never mutate rows in-place.
|
All methods return new objects (immutable pattern). Never mutate rows in-place.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, db: "CommunityDB", source_product: str = "kiwi") -> None:
|
def __init__(self, db: "CommunityDB") -> None:
|
||||||
self._db = db
|
self._db = db
|
||||||
self._source_product = source_product
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# Reads
|
# Reads
|
||||||
|
|
@ -100,8 +99,8 @@ class SharedStore:
|
||||||
) -> list[CommunityPost]:
|
) -> list[CommunityPost]:
|
||||||
"""Paginated post list with optional filters.
|
"""Paginated post list with optional filters.
|
||||||
|
|
||||||
dietary_tags: JSONB containment — posts must include ALL listed tags.
|
dietary_tags: JSONB containment -- posts must include ALL listed tags.
|
||||||
allergen_exclude: JSONB overlap exclusion — posts must NOT include any listed flag.
|
allergen_exclude: JSONB overlap exclusion -- posts must NOT include any listed flag.
|
||||||
"""
|
"""
|
||||||
conn = self._db.getconn()
|
conn = self._db.getconn()
|
||||||
try:
|
try:
|
||||||
|
|
@ -142,7 +141,7 @@ class SharedStore:
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
def insert_post(self, post: CommunityPost) -> CommunityPost:
|
def insert_post(self, post: CommunityPost) -> CommunityPost:
|
||||||
"""Insert a new community post. Returns the inserted post (unchanged — slug is the key)."""
|
"""Insert a new community post. Returns the inserted post (unchanged -- slug is the key)."""
|
||||||
import json
|
import json
|
||||||
|
|
||||||
conn = self._db.getconn()
|
conn = self._db.getconn()
|
||||||
|
|
@ -177,7 +176,7 @@ class SharedStore:
|
||||||
json.dumps(list(post.allergen_flags)),
|
json.dumps(list(post.allergen_flags)),
|
||||||
json.dumps(list(post.flavor_molecules)),
|
json.dumps(list(post.flavor_molecules)),
|
||||||
post.fat_pct, post.protein_pct, post.moisture_pct,
|
post.fat_pct, post.protein_pct, post.moisture_pct,
|
||||||
self._source_product,
|
"kiwi",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
(function(){var s=document.createElement("script");s.defer=true;s.dataset.domain="docs.circuitforge.tech,circuitforge.tech";s.dataset.api="https://analytics.circuitforge.tech/api/event";s.src="https://analytics.circuitforge.tech/js/script.js";document.head.appendChild(s);})();
|
|
||||||
82
mkdocs.yml
82
mkdocs.yml
|
|
@ -1,82 +0,0 @@
|
||||||
site_name: circuitforge-core
|
|
||||||
site_description: Shared scaffold for CircuitForge products — modules, conventions, and developer reference.
|
|
||||||
site_author: Circuit Forge LLC
|
|
||||||
site_url: https://docs.circuitforge.tech/cf-core
|
|
||||||
repo_url: https://git.opensourcesolarpunk.com/Circuit-Forge/circuitforge-core
|
|
||||||
repo_name: Circuit-Forge/circuitforge-core
|
|
||||||
|
|
||||||
theme:
|
|
||||||
name: material
|
|
||||||
palette:
|
|
||||||
- scheme: default
|
|
||||||
primary: deep purple
|
|
||||||
accent: purple
|
|
||||||
toggle:
|
|
||||||
icon: material/brightness-7
|
|
||||||
name: Switch to dark mode
|
|
||||||
- scheme: slate
|
|
||||||
primary: deep purple
|
|
||||||
accent: purple
|
|
||||||
toggle:
|
|
||||||
icon: material/brightness-4
|
|
||||||
name: Switch to light mode
|
|
||||||
features:
|
|
||||||
- navigation.top
|
|
||||||
- navigation.sections
|
|
||||||
- search.suggest
|
|
||||||
- search.highlight
|
|
||||||
- content.code.copy
|
|
||||||
- content.code.annotate
|
|
||||||
|
|
||||||
markdown_extensions:
|
|
||||||
- admonition
|
|
||||||
- attr_list
|
|
||||||
- md_in_html
|
|
||||||
- pymdownx.details
|
|
||||||
- pymdownx.superfences:
|
|
||||||
custom_fences:
|
|
||||||
- name: mermaid
|
|
||||||
class: mermaid
|
|
||||||
format: !!python/name:pymdownx.superfences.fence_code_format
|
|
||||||
- pymdownx.emoji:
|
|
||||||
emoji_index: !!python/name:material.extensions.emoji.twemoji
|
|
||||||
emoji_generator: !!python/name:material.extensions.emoji.to_svg
|
|
||||||
- pymdownx.highlight:
|
|
||||||
anchor_linenums: true
|
|
||||||
- pymdownx.inlinehilite
|
|
||||||
- pymdownx.tabbed:
|
|
||||||
alternate_style: true
|
|
||||||
- toc:
|
|
||||||
permalink: true
|
|
||||||
|
|
||||||
nav:
|
|
||||||
- Home: index.md
|
|
||||||
- Getting Started:
|
|
||||||
- Installation: getting-started/installation.md
|
|
||||||
- Using in a Product: getting-started/using-in-product.md
|
|
||||||
- Module Reference:
|
|
||||||
- Overview: modules/index.md
|
|
||||||
- db: modules/db.md
|
|
||||||
- llm: modules/llm.md
|
|
||||||
- tiers: modules/tiers.md
|
|
||||||
- config: modules/config.md
|
|
||||||
- hardware: modules/hardware.md
|
|
||||||
- documents: modules/documents.md
|
|
||||||
- affiliates: modules/affiliates.md
|
|
||||||
- preferences: modules/preferences.md
|
|
||||||
- tasks: modules/tasks.md
|
|
||||||
- manage: modules/manage.md
|
|
||||||
- resources: modules/resources.md
|
|
||||||
- text: modules/text.md
|
|
||||||
- stt: modules/stt.md
|
|
||||||
- tts: modules/tts.md
|
|
||||||
- pipeline: modules/pipeline.md
|
|
||||||
- vision: modules/vision.md
|
|
||||||
- wizard: modules/wizard.md
|
|
||||||
- Developer Guide:
|
|
||||||
- Adding a Module: developer/adding-module.md
|
|
||||||
- Editable Install Pattern: developer/editable-install.md
|
|
||||||
- BSL vs MIT Boundaries: developer/licensing.md
|
|
||||||
|
|
||||||
extra_javascript:
|
|
||||||
- plausible.js
|
|
||||||
|
|
@ -11,12 +11,10 @@ dependencies = [
|
||||||
"pyyaml>=6.0",
|
"pyyaml>=6.0",
|
||||||
"requests>=2.31",
|
"requests>=2.31",
|
||||||
"openai>=1.0",
|
"openai>=1.0",
|
||||||
|
"psycopg2>=2.9",
|
||||||
]
|
]
|
||||||
|
|
||||||
[project.optional-dependencies]
|
[project.optional-dependencies]
|
||||||
community = [
|
|
||||||
"psycopg2>=2.9",
|
|
||||||
]
|
|
||||||
manage = [
|
manage = [
|
||||||
"platformdirs>=4.0",
|
"platformdirs>=4.0",
|
||||||
"typer[all]>=0.12",
|
"typer[all]>=0.12",
|
||||||
|
|
@ -86,9 +84,6 @@ cf-manage = "circuitforge_core.manage.cli:app"
|
||||||
where = ["."]
|
where = ["."]
|
||||||
include = ["circuitforge_core*"]
|
include = ["circuitforge_core*"]
|
||||||
|
|
||||||
[tool.setuptools.package-data]
|
|
||||||
"circuitforge_core.community.migrations" = ["*.sql"]
|
|
||||||
|
|
||||||
[tool.pytest.ini_options]
|
[tool.pytest.ini_options]
|
||||||
testpaths = ["tests"]
|
testpaths = ["tests"]
|
||||||
asyncio_mode = "auto"
|
asyncio_mode = "auto"
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
# tests/community/test_db.py
|
# tests/community/test_db.py
|
||||||
import os
|
import os
|
||||||
import pytest
|
import pytest
|
||||||
from unittest.mock import MagicMock, patch, call
|
from unittest.mock import MagicMock, patch
|
||||||
from circuitforge_core.community.db import CommunityDB
|
from circuitforge_core.community.db import CommunityDB
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -49,6 +49,7 @@ def test_community_db_run_migrations_executes_sql(mock_pool):
|
||||||
mock_cur = MagicMock()
|
mock_cur = MagicMock()
|
||||||
mock_instance.getconn.return_value = mock_conn
|
mock_instance.getconn.return_value = mock_conn
|
||||||
mock_conn.cursor.return_value.__enter__.return_value = mock_cur
|
mock_conn.cursor.return_value.__enter__.return_value = mock_cur
|
||||||
|
mock_cur.fetchone.return_value = None # no migrations applied yet
|
||||||
|
|
||||||
db = CommunityDB(dsn="postgresql://user:pass@localhost/cf_community")
|
db = CommunityDB(dsn="postgresql://user:pass@localhost/cf_community")
|
||||||
db.run_migrations()
|
db.run_migrations()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue