Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/AI_Brain / daemon/seed_common.py |
| Date | Not specified in source |
| Repository | Janady13/AI_Brain |
| Revision | 11aa50ef5d7692e8abd1b8d74ae31c5c29201b14 |
| Branch | codex/build-online-github-ani-irqa7y |
| Path or archive member | daemon/seed_common.py |
| Original SHA-256 | 576868ebf65bbd39b48a5bac6ed08a4139e840f041fe0b2f759223034a516673 |
| Git blob SHA | 1f6ee9a2344564024f98df3057924985806051f0 |
| Reading-copy SHA-256 | 576868ebf65bbd39b48a5bac6ed08a4139e840f041fe0b2f759223034a516673 |
Every recorded occurrence
These 23 records contain identical original source bytes. Their paths and revisions remain part of the archive.
| Original record | Branch or archive | Revision / identifier | Original location |
|---|---|---|---|
| Janady13/AI_Brain / daemon/seed_common.py | codex/build-online-github-ani-irqa7y | 11aa50ef5d7692e8abd1b8d74ae31c5c29201b14 | Open original |
| Janady13/AI_Brain / daemon/seed_common.py | codex/build-online-github-ani-hr4y0z | 366ab848896ae49159cfb3f6c201b8c5a731e9c8 | Open original |
| Janady13/AI_Brain / daemon/seed_common.py | codex/build-online-github-ani-i3cigl | 3a6e002311c48c27ffd41ef4a2a31c63947128cd | Open original |
| Janady13/AI_Brain / daemon/seed_common.py | codex/build-online-github-ani | 49db80a641b10ab62d16cc7643bd0b367f93951c | Open original |
| Janady13/AI_Brain / daemon/seed_common.py | codex/build-online-github-ani-hrtsoc | 50285aff347685f043e7a72e4d72891eebaa6cd6 | Open original |
| Janady13/AI_Brain / daemon/seed_common.py | codex/build-online-github-ani-7v4kug | 5cd0bbf744b0aee9445913337e852889d9a8098e | Open original |
| Janady13/AI_Brain / daemon/seed_common.py | codex/build-online-github-ani-nbgsix | 840945d70b88674d8f40d330001cc63d871dc8e2 | Open original |
| Janady13/AI_Brain / daemon/seed_common.py | copilot/vscode1760283895982 | 9e1c1a5b171addb5bb4a83b2ea7dede50c1cc81e | Open original |
| Janady13/AI_Brain / daemon/seed_common.py | codex/build-online-github-ani-jf5olo | c6653627c453ab428d665226167fa5f4aa05e9a5 | Open original |
| Janady13/AI_Brain / daemon/seed_common.py | feature/seeder-engine-tests | cdb497ece2d1a770ca8c83eb1de8923cfaa9eceb | Open original |
| Janady13/AI_Brain / daemon/seed_common.py | codex/build-online-github-ani-7nmb21 | d0f50071c85cddaaebbf9c4dd1313bd7676986da | Open original |
| Janady13/AI_Brain / daemon/seed_common.py | codex/build-online-github-ani-0etkns | e250b19d446bdffd542c9eea31cead12e30800d6 | Open original |
| Janady13/AI_Brain / daemon/seed_common.py | codex/build-online-github-ani-hr4y0z | 366ab848896ae49159cfb3f6c201b8c5a731e9c8 | Open original |
| Janady13/AI_Brain / daemon/seed_common.py | codex/build-online-github-ani-irqa7y | 11aa50ef5d7692e8abd1b8d74ae31c5c29201b14 | Open original |
| Janady13/AI_Brain / daemon/seed_common.py | codex/build-online-github-ani-i3cigl | 3a6e002311c48c27ffd41ef4a2a31c63947128cd | Open original |
| Janady13/AI_Brain / daemon/seed_common.py | codex/build-online-github-ani-7v4kug | 5cd0bbf744b0aee9445913337e852889d9a8098e | Open original |
| Janady13/AI_Brain / daemon/seed_common.py | codex/build-online-github-ani-nbgsix | 840945d70b88674d8f40d330001cc63d871dc8e2 | Open original |
| Janady13/AI_Brain / daemon/seed_common.py | copilot/vscode1760283895982 | 9e1c1a5b171addb5bb4a83b2ea7dede50c1cc81e | Open original |
| Janady13/AI_Brain / daemon/seed_common.py | codex/build-online-github-ani-7nmb21 | d0f50071c85cddaaebbf9c4dd1313bd7676986da | Open original |
| Janady13/AI_Brain / daemon/seed_common.py | feature/seeder-engine-tests | cdb497ece2d1a770ca8c83eb1de8923cfaa9eceb | Open original |
| Janady13/AI_Brain / daemon/seed_common.py | codex/build-online-github-ani | 49db80a641b10ab62d16cc7643bd0b367f93951c | Open original |
| Janady13/AI_Brain / daemon/seed_common.py | codex/build-online-github-ani-jf5olo | c6653627c453ab428d665226167fa5f4aa05e9a5 | Open original |
| Janady13/AI_Brain / daemon/seed_common.py | codex/build-online-github-ani-hrtsoc | 50285aff347685f043e7a72e4d72891eebaa6cd6 | Open original |
Recovered source transcript
Download complete source text ↓124 lines · 3.9 KB
#!/usr/bin/env python3
# Local seeding utilities following 12-factor config
from __future__ import annotations
import os, sys, hashlib, time
from typing import Iterable, Tuple, Callable, List
from pathlib import Path
# Lazy import psycopg2 only when needed
try:
import psycopg2 # type: ignore
except Exception: # pragma: no cover
psycopg2 = None # allow dry-run without dependency
DEFAULT_DB = os.getenv("PGDATABASE", os.getenv("DB_NAME", "brain_atomic"))
DEFAULT_USER = os.getenv("PGUSER", os.getenv("DB_USER", "postgres"))
# Prefer Brain volume sockets if present, then External, then home dir, else localhost
DEFAULT_HOST = (
os.getenv("PGHOST")
or os.getenv("DB_HOST")
or next(
(
c
for c in [
"/Volumes/Brain/AI_Brain/pg",
"/Volumes/Brain/HiveExpansion/pg",
"/Volumes/External/AI_Brain/pg",
str(Path.home() / "AI_Brain" / "pg"),
]
if Path(c).exists()
),
"localhost",
)
)
DEFAULT_PORT = int(os.getenv("PGPORT", os.getenv("DB_PORT", "5432")))
DRY_RUN = os.getenv("DRY_RUN", "0").lower() in {"1", "true", "yes", "on"}
SOURCE_TAG = os.getenv("SEED_SOURCE", "Hive500Expansion")
def compute_hash(sentence: str) -> str:
# Atomic uniqueness across identical sentences (global), as specified
return hashlib.sha256(sentence.encode("utf-8")).hexdigest()
def connect_db():
if DRY_RUN:
return None
if psycopg2 is None:
sys.stderr.write(
"psycopg2 not installed. Install with: pip install psycopg2-binary\n"
)
sys.exit(1)
return psycopg2.connect(dbname=DEFAULT_DB, user=DEFAULT_USER, host=DEFAULT_HOST, port=DEFAULT_PORT)
INSERT_SQL = (
"INSERT INTO atomic_facts (hash, sentence, category, source, created_at) "
"VALUES (%s, %s, %s, %s, now()) ON CONFLICT (hash) DO NOTHING;"
)
def insert_many(category: str, items: Iterable[str]) -> Tuple[int, int]:
"""Insert items; returns (attempted, inserted_estimate)."""
attempted = 0
inserted = 0
conn = connect_db()
cur = conn.cursor() if conn is not None else None
try:
for s in items:
sentence = s.strip()
if not sentence:
continue
if not sentence.endswith("."):
sentence = f"{sentence}."
h = compute_hash(sentence)
attempted += 1
if DRY_RUN:
inserted += 1
continue
cur.execute(INSERT_SQL, (h, sentence, category, SOURCE_TAG))
if conn is not None:
conn.commit()
finally:
if cur is not None:
cur.close()
if conn is not None:
conn.close()
return attempted, (inserted if DRY_RUN else attempted)
def read_file_lines(path: str, limit: int) -> List[str]:
seen = set()
out: List[str] = []
with open(path, "r", encoding="utf-8") as f:
for raw in f:
line = raw.strip()
if not line:
continue
if line in seen:
continue
seen.add(line)
out.append(line)
if len(out) >= limit:
break
return out
def run_seed(category: str, generator: Callable[[int], Iterable[str]], limit: int = 500) -> None:
start = time.time()
cat_upper = category.upper()
file_override = os.getenv(f"SEED_FILE_{cat_upper}") or os.getenv("SEED_FILE")
if file_override and os.path.isfile(file_override):
items = read_file_lines(file_override, limit)
mode_detail = f"FILE:{file_override}"
else:
items = list(generator(limit))
mode_detail = "GENERATOR"
attempted, inserted = insert_many(category, items)
dur = time.time() - start
mode = "DRY_RUN" if DRY_RUN else "LIVE"
print(
f"✅ {mode} seeded category='{category}' source={mode_detail} attempted={attempted} inserted~={inserted} in {dur:.2f}s"
)