CI & Build / Plugin hooks (push) Successful in 13s
CI & Build / Python lint (push) Successful in 2s
CI & Build / TypeScript typecheck (push) Successful in 33s
CI & Build / Python tests (push) Failing after 1m41s
CI & Build / integration (push) Successful in 2m8s
CI & Build / Build & push image (push) Skipped
Each lesson can carry its situation: a moment of work (work.deliver, work.finish, ...) or a typed trigger on the act (path, command, tool, keyword, matched as rule triggers are). A pass proposes, a person judges: - lesson_situations (migration 0137): one row per lesson, kind and value, suggested / confirmed / rejected; `none` records that no situation fits; - MCP: lessons_to_situate, propose_lesson_situations, lesson_situation_proposals, judge_lesson_situations; - Settings > Moments lists waiting proposals with Apply / Not this / Apply all; a lesson page lists its situations and lets a writer add one or take one off (kept as rejected, never proposed again). Delivery: the moment doors (the plugin catch-all hook and MCP replies) add the lessons whose confirmed moment the act reached or whose trigger it matches. The plugin door shows each once per session, using the record ledger, and records it as pushed (source lesson_situation); the tool filter now includes the tools a lesson trigger listens on. The edit door no longer finds lessons by meaning: lesson leaves the work.change default kinds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
103 lines
5.6 KiB
Python
103 lines
5.6 KiB
Python
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
|
|
from sqlalchemy.orm import DeclarativeBase
|
|
|
|
from grimoire.config import Config
|
|
|
|
# Named rather than inlined so the deadline below is READABLE. SQLAlchemy
|
|
# captures `connect_args` in a closure and merges it at connect time, so an
|
|
# inline dict cannot be recovered from the engine — and a guard that cannot
|
|
# read the value it guards is a guard that passes forever.
|
|
_CONNECT_ARGS: dict = {
|
|
# A DEADLINE ON ESTABLISHING A CONNECTION.
|
|
#
|
|
# asyncpg's `timeout` bounds the CONNECT — the TCP handshake plus session
|
|
# setup — and nothing else. Against a host whose storage has wedged, that
|
|
# handshake does not fail, it waits, and without this the wait is
|
|
# asyncpg's own 60-second default: the entire lifespan budget spent before
|
|
# a single query is even sent. Ten seconds is far longer than a healthy
|
|
# local connect (single-digit milliseconds) and short enough to leave room
|
|
# to fail usefully rather than be killed.
|
|
#
|
|
# WHAT THIS DOES NOT COVER, said plainly so the next reader doesn't assume
|
|
# it does: a query on an already-open connection, which includes
|
|
# `pool_pre_ping`'s liveness check. Bounding those is `command_timeout`,
|
|
# and that is deliberately NOT set here — it would apply to every
|
|
# statement, and this app legitimately runs long ones (the embedding
|
|
# backfills, VACUUM ANALYZE). A blanket statement deadline would trade
|
|
# this failure mode for a worse one. Callers that must not hang — the
|
|
# lifespan hook above all — bound their own await instead; see
|
|
# `_STARTUP_READ_TIMEOUT` in services/db_maintenance_scheduler.py.
|
|
"timeout": 10,
|
|
}
|
|
|
|
engine = create_async_engine(
|
|
Config.DATABASE_URL,
|
|
echo=False,
|
|
pool_pre_ping=True,
|
|
pool_recycle=1800,
|
|
connect_args=_CONNECT_ARGS,
|
|
)
|
|
async_session = async_sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)
|
|
|
|
|
|
class Base(DeclarativeBase):
|
|
pass
|
|
|
|
|
|
from grimoire.models.base import CreatedAtMixin, TimestampMixin # noqa: E402, F401
|
|
|
|
|
|
from grimoire.models.note import Note, TaskPriority, TaskStatus # noqa: E402, F401
|
|
from grimoire.models.setting import Setting # noqa: E402, F401
|
|
from grimoire.models.user import User # noqa: E402, F401
|
|
from grimoire.models.app_log import AppLog # noqa: E402, F401
|
|
from grimoire.models.password_reset import PasswordResetToken # noqa: E402, F401
|
|
from grimoire.models.invitation import InvitationToken # noqa: E402, F401
|
|
from grimoire.models.embedding import ( # noqa: E402, F401
|
|
MilestoneEmbedding, NoteEmbedding, RuleEmbedding, SystemEmbedding,
|
|
)
|
|
from grimoire.models.retrieval_log import RetrievalLog # noqa: E402, F401
|
|
from grimoire.models.retrieval_tuning import RetrievalTuningEvent # noqa: E402, F401
|
|
from grimoire.models.note_usage import NoteUsageEvent # noqa: E402, F401
|
|
from grimoire.models.rule_usage import RuleUsageEvent # noqa: E402, F401
|
|
from grimoire.models.rule_delivery import RuleDelivery # noqa: E402, F401
|
|
from grimoire.models.rule_adherence import RuleAdherence # noqa: E402, F401
|
|
from grimoire.models.record_delivery import RecordDelivery # noqa: E402, F401
|
|
from grimoire.models.system_usage import SystemUsageEvent # noqa: E402, F401
|
|
from grimoire.models.retrieval_judgment import RetrievalJudgment # noqa: E402, F401
|
|
from grimoire.models.moment_mapping import MomentMapping # noqa: E402, F401
|
|
from grimoire.models.project import Project # noqa: E402, F401
|
|
from grimoire.models.milestone import Milestone # noqa: E402, F401
|
|
from grimoire.models.task_log import TaskLog # noqa: E402, F401
|
|
from grimoire.models.note_draft import NoteDraft # noqa: E402, F401
|
|
from grimoire.models.note_version import NoteVersion # noqa: E402, F401
|
|
from grimoire.models.rule_version import RuleVersion # noqa: E402, F401
|
|
from grimoire.models.note_supersession import NoteSupersession # noqa: E402, F401
|
|
from grimoire.models.group import Group, GroupMembership # noqa: E402, F401
|
|
from grimoire.models.share import NoteShare, ProjectShare # noqa: E402, F401
|
|
from grimoire.models.notification import Notification # noqa: E402, F401
|
|
from grimoire.models.api_key import ApiKey # noqa: E402, F401
|
|
# Imported before rulebook: rule_systems foreign-keys canonical_systems.
|
|
from grimoire.models.canonical_system import CanonicalSystem # noqa: E402, F401
|
|
from grimoire.models.rulebook import ( # noqa: E402, F401
|
|
Rulebook, RulebookTopic, Rule, RuleRelation, rule_moments, rule_systems,
|
|
)
|
|
# After notes and rules: it foreign-keys both.
|
|
from grimoire.models.lesson_rule_link import LessonNoRule, LessonRuleLink # noqa: E402, F401
|
|
from grimoire.models.lesson_situation import LessonSituation # noqa: E402, F401
|
|
# After rules: it foreign-keys them.
|
|
from grimoire.models.rule_moment_judgment import RuleMomentJudgment # noqa: E402, F401
|
|
from grimoire.models.rule_field_judgment import RuleFieldJudgment # noqa: E402, F401
|
|
from grimoire.models.repo_binding import RepoBinding # noqa: E402, F401
|
|
from grimoire.models.forge_connection import ForgeConnection # noqa: E402, F401
|
|
from grimoire.models.code_shape import CodeShape, CodeShapeConsumer, CodeShapeEvent, CodeShapeUse # noqa: E402, F401
|
|
from grimoire.models.system import System, RecordSystem # noqa: E402, F401
|
|
from grimoire.models.design_system import DesignSystem, DesignToken # noqa: E402, F401
|
|
# After notes, projects and rulebook topics: family canon foreign-keys all
|
|
# three.
|
|
from grimoire.models.family import ( # noqa: E402, F401
|
|
FamilyAdoption, FamilyDecision, FamilyIdea, FamilyIdeaPlatform,
|
|
FamilyIdeaReference, Platform, ProjectPlatform,
|
|
)
|
|
from grimoire.models.instance import InstanceIdentity # noqa: E402, F401
|