Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions apps/id-graph-poc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# id-graph-poc: PoC 1 (Rummager-like organising)

Slice 1 of #14037, built on the D3 record
(`doc/2026-11-24_design_id-graph-layer-typed-links-verbs/D3-graph-layer.md`).

Run the done check from the repo root:

python3 -I apps/id-graph-poc/check.py

## What it shows

- A curator (`ed25519:dddd4444curator`) who authored none of the D3 fixture
objects collects them into `coll-meetup-2026-11-22` with `collect` links.
- Discovery over verb links: backlinks (`what links here`), neighbourhood
(`what is this near`), and recent changes.

## Model gap: `collect` is provisional

D3 v1 has no collection kind and no `collect` verb. This PoC admits `collect`
provisionally so that organising has a link to carry it. It is not an
admission under D3 §5: it has no create/traverse rule, rendering hint, or
second implementation yet. Per the build-on-system principle the gap is
recorded for D3 (#13885) to decide, not patched app-locally. PoC 2 and the
live app are out of scope here.
83 changes: 83 additions & 0 deletions apps/id-graph-poc/check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
"""Done check for PoC 1 (#14037 slice 1): python3 apps/id-graph-poc/check.py"""
import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent))

from organise import ( # noqa: E402
CURATOR,
COLLECTION_ID,
POC_VERBS,
backlinks,
build_graph,
collect,
collection_members,
neighbourhood,
recent_changes,
verbs_in,
)

failures = []


def expect(cond, msg):
if cond:
print(f"OK: {msg}")
else:
failures.append(msg)
print(f"FAIL: {msg}")


objects, links = build_graph()
members = sorted(objects)
objects, links = collect(objects, links, members, "2026-11-24T02:00:00Z")

authors = {o["author"] for o in objects.values() if o["kind"] != "collection"}
expect(CURATOR not in authors, "curator authored none of the collected objects")
expect(
collection_members(links, COLLECTION_ID) == sorted(members),
"collection holds every D3 fixture object via collect links",
)
expect(verbs_in(links) <= POC_VERBS, "every link verb is in the D3 registry plus the provisional collect verb")
expect(
all(l["author"] == CURATOR for l in links.values() if l["verb"] == "collect"),
"collect links are authored by the curator, not by the members' authors",
)

replies = backlinks(links, "post-meetup-thread", "reply")
expect(
[l["source"] for l in replies] == ["msg-photo-answer"],
"backlinks: what replies to the forum thread (cross-app chat reply)",
)
photo_in = {(l["verb"], l["source"]) for l in backlinks(links, "img-group-photo")}
expect(
photo_in == {("attach", "post-photo-published"), ("mention", "msg-photo-answer"), ("collect", COLLECTION_ID)},
"backlinks: the photo is attached in the forum post, mentioned by the chat answer, and collected",
)

near = neighbourhood(objects, links, "msg-photo-answer")
expect(
("reply", "out", "post-meetup-thread") in near and ("nest", "out", "post-meetup-thread") in near,
"neighbourhood: the chat answer's reply and nest links out to the thread",
)
expect(
("mention", "out", "img-group-photo") in near,
"neighbourhood: the chat answer mentions the photo without containing it",
)
expect(
("quote", "in", "lnk-quote-chat-ask") not in near,
"neighbourhood excludes links that do not touch the object",
)

recent = recent_changes(objects, links, limit=len(members) + 1)
expect(
recent[0].startswith("lnk-collect-") and COLLECTION_ID in objects,
"recent changes: the newest change is one of the curator's collect links",
)
expect(
recent == sorted(recent, key=lambda i: (objects.get(i, links.get(i))["created_claim"], i), reverse=True),
"recent changes are ordered newest first by (created_claim, object_id)",
)

print(f"\n{len(failures)} failure(s).")
sys.exit(1 if failures else 0)
108 changes: 108 additions & 0 deletions apps/id-graph-poc/organise.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
"""PoC 1 (#14037): Rummager-like organising over the D3 ID graph (stdlib only).

Loads the D3 cross-app fixtures, lets a curator who authored none of them
collect them into a collection object, and answers discovery queries over
verb links: backlinks, neighbourhood, recent changes.

Model gap: D3 v1 has no collection kind and no collect verb. The PoC admits
`collect` provisionally (see README.md) and records the gap on #13885.
"""
import json
from pathlib import Path

REPO = Path(__file__).resolve().parents[2]
FIXTURES = REPO / "doc" / "2026-11-24_design_id-graph-layer-typed-links-verbs" / "fixtures"

CONTENT_FILES = [
"chat-message.json",
"forum-post.json",
"image.json",
"cross-app-chat-answer.json",
"cross-app-forum-published.json",
]
LINK_FILES = [
"link-reply-chat-to-forum.json",
"link-attach-photo.json",
"link-quote-chat-ask.json",
"link-nest-thread-in-board.json",
"link-mention-photo.json",
]

CURATOR = "ed25519:dddd4444curator"
COLLECTION_ID = "coll-meetup-2026-11-22"
D3_VERBS = {"reply", "mention", "quote", "attach", "supersede", "nest"}
POC_VERBS = D3_VERBS | {"collect"}


def load(name):
with open(FIXTURES / name, encoding="utf-8") as f:
return json.load(f)


def build_graph():
objects = {}
links = {}
for name in CONTENT_FILES:
o = load(name)
objects[o["object_id"]] = o
for name in LINK_FILES:
o = load(name)
links[o["object_id"]] = o
return objects, links


def collect(objects, links, member_ids, created_claim):
"""Curator-owned collection: a collection object plus one `collect` link per member."""
objects[COLLECTION_ID] = {
"object_id": COLLECTION_ID,
"author": CURATOR,
"created_claim": created_claim,
"kind": "collection",
"body": {"title": "Saturday meetup, all in one place"},
"schema_version": 1,
}
for mid in member_ids:
lid = f"lnk-collect-{mid}"
links[lid] = {
"object_id": lid,
"author": CURATOR,
"created_claim": created_claim,
"verb": "collect",
"source": COLLECTION_ID,
"target": mid,
"schema_version": 1,
}
return objects, links


def backlinks(links, target_id, verb=None):
"""Derived index: links whose target is target_id (what links here)."""
return sorted(
(l for l in links.values() if l["target"] == target_id and (verb is None or l["verb"] == verb)),
key=lambda l: l["object_id"],
)


def neighbourhood(objects, links, object_id):
"""Everything one hop away over any verb, in either direction."""
out = []
for l in links.values():
if l["source"] == object_id:
out.append((l["verb"], "out", l["target"]))
elif l["target"] == object_id:
out.append((l["verb"], "in", l["source"]))
return sorted(out)


def recent_changes(objects, links, limit=10):
items = list(objects.values()) + list(links.values())
items.sort(key=lambda o: (o["created_claim"], o["object_id"]), reverse=True)
return [o["object_id"] for o in items[:limit]]


def collection_members(links, collection_id):
return sorted(l["target"] for l in links.values() if l["verb"] == "collect" and l["source"] == collection_id)


def verbs_in(links):
return {l["verb"] for l in links.values()}