fix(8140): family triggers open only records that can carry an idea, and enter_project names a project's unevaluated candidates
CI & Build / Python lint (push) Successful in 7s
CI & Build / TypeScript typecheck (push) Successful in 43s
CI & Build / Plugin hooks (push) Successful in 49s
CI & Build / Python tests (push) Failing after 2m12s
CI & Build / integration (push) Successful in 2m41s
CI & Build / Build & push image (push) Skipped

Tasks, non-knowledge kinds and records titled for their own project are never
opened as candidates by the citation or repeat trigger; a lineage word inside
a quoted title no longer reads as lineage. The family line counts and names
this project's own candidates that only the system has decided on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-27 09:41:09 -05:00
co-authored by Claude Opus 5.5
parent 55f53de92d
commit de55b73075
7 changed files with 224 additions and 11 deletions
+4 -1
View File
@@ -140,7 +140,10 @@ async def enter_project(project_id: int) -> dict:
version (`needs_recheck`) — each with the list_family_adoptions call that
lists them. Answer an unassessed idea when your work reaches its area
(get_family_adoption, then assess_family_adoption, or classify the code
against it); the family-canon skill has the order.
against it); the family-canon skill has the order. It also counts this
project's own records that a trigger proposed as family ideas and nobody
has evaluated (`candidates`), naming them: this project's session holds
their context, so it is the one asked to promote or retire each.
`inception` appears ONLY when the project is yours and
nobody has decided what it inherits: it carries the current defaults
+93 -4
View File
@@ -115,6 +115,9 @@ _LINEAGE = re.compile(
)
# How far before a `#N` the lineage word may sit: the same clause, roughly.
_LINEAGE_WINDOW = 80
# A quoted title, straight or curly quotes, on one line. Bounded so a stray
# quote mark cannot blank a whole paragraph.
_QUOTED = re.compile(r'"[^"\n]{1,200}"|\u201c[^\u201d\n]{1,200}\u201d')
# Note kinds the repeat trigger compares: recorded knowledge and shapes, not
# the to-do list — and each only against its own kind. A repeat is the same
@@ -127,6 +130,38 @@ _LINEAGE_WINDOW = 80
# once the idea is canon.
_REPEAT_KINDS = ("snippet", "note")
def about_its_own_project(title: str | None, project_title: str | None) -> bool:
"""Whether a record's title opens with its own project's name.
"Storehouse: start here", "Torn Stars — Economy System": a record named
for its project describes that project — its overview, its founding
decisions, one system of one game — and cannot carry an idea every
project on a platform shares, however closely another project's
overview resembles it. The name must end at a word boundary, so a
project called "Sync" does not claim "Syncthing relay".
"""
t = (title or "").strip().casefold()
p = (project_title or "").strip().casefold()
if not p or not t.startswith(p):
return False
return len(t) == len(p) or not t[len(p)].isalnum()
def can_carry_idea(*, is_task: bool, note_type: str | None, title: str | None,
project_title: str | None) -> bool:
"""Whether a record is the kind a trigger may open as a family candidate.
A task is a unit of work in one project, so it is never the idea itself:
an idea it carries is written up as a note and proposed. Only recorded
knowledge and shapes (`_REPEAT_KINDS`) qualify, and not a record about
its own project (`about_its_own_project`). The triggers open candidates
without anyone reading them, so they hold to this; an agent who has read
a record may still propose it by hand."""
if is_task or (note_type or "note") not in _REPEAT_KINDS:
return False
return not about_its_own_project(title, project_title)
MEMBER_STATES = ("declared", "detected")
_IDEA_ACTIONS = ("propose", "promote", "revise", "retire")
@@ -862,9 +897,15 @@ def lineage_citations(text: str | None) -> list[int]:
from grimoire.services.record_refs import REF_RE
found: list[int] = []
for m in REF_RE.finditer(text or ""):
text = text or ""
# A quoted span is a record's TITLE, written beside its id by convention
# (#12 "Release parsing and matching"). Its words describe that record,
# not this one's lineage, so they are blanked before the window is read;
# blanked to the same length, so match positions stay valid.
bare = _QUOTED.sub(lambda q: " " * len(q.group(0)), text)
for m in REF_RE.finditer(text):
start = max(0, m.start() - _LINEAGE_WINDOW)
window = text[start:m.start()]
window = bare[start:m.start()]
window = re.split(r"[\n.;]", window)[-1]
if _LINEAGE.search(window):
n = int(m.group(1))
@@ -873,6 +914,41 @@ def lineage_citations(text: str | None) -> list[int]:
return found
async def _project_titles(session, project_ids: set[int]) -> dict[int, str]:
return dict((await session.execute(
select(Project.id, Project.title).where(Project.id.in_(project_ids))
)).all())
async def unevaluated_candidates(user_id: int, project_id: int, *, limit: int = 5) -> dict:
"""This project's own records that are family candidates nobody has
evaluated: every decision on them so far is the system's own proposal.
The triggers open candidates; nothing else asks anyone to evaluate one,
so without a reader they only accumulate. The project a candidate lives
in is where its context is, so its own sessions are asked, on entering.
{count, ideas: [{id, title}]}, oldest first, up to ``limit`` named."""
judged = select(FamilyDecision.idea_id).where(
FamilyDecision.idea_id == FamilyIdea.note_id,
FamilyDecision.decided_via != "system",
).exists()
where = (
FamilyIdea.status == "candidate", Note.project_id == project_id,
Note.deleted_at.is_(None), access.readable_notes_clause(user_id), ~judged,
)
async with async_session() as session:
count = (await session.execute(
select(func.count()).select_from(FamilyIdea)
.join(Note, Note.id == FamilyIdea.note_id).where(*where)
)).scalar() or 0
rows = (await session.execute(
select(Note.id, Note.title).select_from(FamilyIdea)
.join(Note, Note.id == FamilyIdea.note_id).where(*where)
.order_by(FamilyIdea.created_at.asc()).limit(limit)
)).all() if count else []
return {"count": int(count), "ideas": [{"id": i, "title": t} for i, t in rows]}
async def _member_platform_ids(session, project_id: int) -> set[int]:
return set((await session.execute(
select(ProjectPlatform.platform_id).where(
@@ -902,14 +978,20 @@ async def citation_trigger(user_id: int, note) -> str | None:
return None
async with async_session() as session:
rows = (await session.execute(
select(Note.id, Note.title, Note.project_id, Project.title)
select(Note.id, Note.title, Note.project_id, Project.title,
Note.status, Note.note_type)
.join(Project, Project.id == Note.project_id)
.where(
Note.id.in_(cited), Note.deleted_at.is_(None),
Note.project_id.is_not(None), Note.project_id != note.project_id,
)
)).all()
for source_id, source_title, _pid, project_title in sorted(rows, key=lambda r: cited.index(r[0])):
for source_id, source_title, _pid, project_title, status, note_type in sorted(
rows, key=lambda r: cited.index(r[0]),
):
if not can_carry_idea(is_task=status is not None, note_type=note_type,
title=source_title, project_title=project_title):
continue
if not await access.can_write_note(user_id, source_id):
continue
idea, created = await propose(
@@ -944,6 +1026,9 @@ async def repeat_trigger(user_id: int, note) -> str | None:
if not getattr(note, "project_id", None) or note.is_task or kind not in _REPEAT_KINDS:
return None
async with async_session() as session:
titles = await _project_titles(session, {note.project_id})
if about_its_own_project(note.title, titles.get(note.project_id)):
return None
mine = await _member_platform_ids(session, note.project_id)
if not mine:
return None
@@ -958,6 +1043,10 @@ async def repeat_trigger(user_id: int, note) -> str | None:
if (other.note_type or "note") != kind:
continue
async with async_session() as session:
other_project = (await _project_titles(session, {other.project_id})).get(other.project_id)
if not can_carry_idea(is_task=other.is_task, note_type=other.note_type,
title=other.title, project_title=other_project):
continue
shared = mine & await _member_platform_ids(session, other.project_id)
if not shared or not await access.can_write_note(user_id, other.id):
continue
+29 -6
View File
@@ -1222,10 +1222,13 @@ async def _shapes_follow(user_id: int, project_id: int, idea_id: int, outcome: s
# ideas themselves by retrieval, and the owed answers filed while a task was
# open, handed back when it closes.
def family_line(project_id: int, cells: list[dict]) -> dict | None:
def family_line(project_id: int, cells: list[dict],
candidates: dict | None = None) -> dict | None:
"""The `family` line enter_project carries: what this project has not
answered, owes, or answered against an older canon version. None when
all three are zero — the key is attached only when it asks something.
answered, owes, or answered against an older canon version — and which
of its own records are family candidates nobody has evaluated
(`family.unevaluated_candidates`). None when all are zero — the key is
attached only when it asks something.
Shown on EVERY entry (the step settled this), not only when a session
touches a platform: entering is when the agent chooses what to work on,
@@ -1234,7 +1237,9 @@ def family_line(project_id: int, cells: list[dict]) -> dict | None:
unassessed = sum(1 for c in cells if c["in_scope"] and c["status"] == "unassessed")
owed = sum(1 for c in cells if c["status"] == "owed")
recheck = sum(1 for c in cells if c["needs_recheck"])
if not (unassessed or owed or recheck):
candidates = candidates or {}
n_cand = int(candidates.get("count") or 0)
if not (unassessed or owed or recheck or n_cand):
return None
parts, calls = [], {}
if unassessed:
@@ -1246,9 +1251,23 @@ def family_line(project_id: int, cells: list[dict]) -> dict | None:
if recheck:
parts.append(f"{recheck} to recheck")
calls["needs_recheck"] = f"list_family_adoptions(project_id={project_id}, needs_recheck=true)"
if n_cand:
# Named by id: the list tool pages every project's ideas, and these
# are the few that this project's own session is placed to judge.
named = ", ".join(f"#{c['id']} \"{c['title']}\"" for c in candidates.get("ideas") or [])
more = n_cand - len(candidates.get("ideas") or [])
parts.append(f"{n_cand} of this project's own record{'s' if n_cand != 1 else ''} "
"proposed as family ideas, never evaluated")
calls["candidates"] = (
f"get_family_idea(id) for each — {named}"
+ (f", and {more} more (list_family_ideas(status=\"candidate\"))" if more > 0 else "")
+ "; then promote_family_idea if all three criteria hold, or "
"retire_family_idea if it is not an idea at all"
)
return {
"line": "family canon on this project's platforms: " + " · ".join(parts),
"unassessed": unassessed, "owed": owed, "needs_recheck": recheck,
"candidates": n_cand,
"calls": calls,
"answer_with": ("get_family_adoption(project_id, idea_id) reads one with its "
"precedents; assess_family_adoption answers it — or classify_shapes "
@@ -1257,8 +1276,11 @@ def family_line(project_id: int, cells: list[dict]) -> dict | None:
async def family_readout(user_id: int, project_id: int) -> dict | None:
from grimoire.services import family as family_svc
matrix = await adoption_matrix(user_id, project_id=project_id)
return family_line(project_id, matrix["cells"])
candidates = await family_svc.unevaluated_candidates(user_id, project_id)
return family_line(project_id, matrix["cells"], candidates)
# --- whether the line reached the project ---------------------------------------
@@ -1285,7 +1307,8 @@ async def record_entry(user_id: int, project_id: int, line: dict | None, *,
if failed:
details["readout_failed"] = True
if line:
details.update({k: int(line.get(k) or 0) for k in ("unassessed", "owed", "needs_recheck")})
details.update({k: int(line.get(k) or 0)
for k in ("unassessed", "owed", "needs_recheck", "candidates")})
try:
async with async_session() as session:
session.add(AppLog(