host P0.4: canonical seam activity shape + RA marshaller (LIVE-VERIFIED) — P0 COMPLETE

host/blog--publish-activity now emits the CANONICAL seam shape {:verb :actor :object <cid>
:object-type :slug :category :delta :id}: :object is a content-addressed REFERENCE (the CID, not an
inlined dict), :id the dedup identity, :slug+:category the domain fields the DAG reads. Consumers
reconciled — the on-publish trigger matches :verb+:object-type; publish-ctx reads top-level
:category+:slug. Added host/blog--activity->erl: marshals the canonical activity → next/'s Erlang
proplist for the Erlang runner adapter (RA) — defined + tested, unused until RA so the reconcile is
complete and RA's bridge is ready. (:ts/:prev omitted — no clock primitive in the host; deferred.)

LIVE PROOF: published on blog.rose-ash.com → /flows fired validate+notify with the canonical
activity. blog 209/209, full host conformance 597/597.

P0 COMPLETE: the synchronous publish workflow runs end-to-end on the live host through the
substrate-agnostic seam, durably, in the canonical shape, with the RA marshaller staged. RA (Erlang
runner) + TA (fed-sx transport) plug in next without touching the DAG or the wiring.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-02 15:07:58 +00:00
parent 5b6a5e4f19
commit 77e89a9965
3 changed files with 66 additions and 23 deletions

View File

@@ -108,11 +108,13 @@
nil (host/blog-slugs))))
;; ── business logic as federated composition-flows (plans/business-logic-fed-flows.md) ──
;; P0.1: the PUBLISH-ACTIVITY contract. A published post is described as a fed-sx activity —
;; the same shape next/'s trigger machinery consumes ({:type verb :actor :id CID :object …}).
;; The trigger (on-publish → a flow, e.g. blog_publish_digest) fires on a matching activity.
;; category (drives the flow's branch: newsletter suspends, urgent fires now, else skip) comes
;; from the post's "category" field-value, else its first tag, else "urgent" (fires the demo).
;; P0.1/P0.4: the PUBLISH-ACTIVITY contract, in the CANONICAL SEAM SHAPE
;; {:verb :actor :object <cid> :object-type :slug :category :delta :id} — :object is a
;; content-addressed REFERENCE (the CID), not an inlined dict; :id is the dedup identity; :slug +
;; :category are the domain fields the publish-DAG's ctx reads. Each runner adapter MARSHALS this
;; to its substrate (host/blog--activity->erl → next/'s proplist for the Erlang runner, RA).
;; category (the DAG's branch: newsletter/urgent/else) comes from the "category" field-value, else
;; the first tag, else "urgent".
(define host/blog--post-category
(fn (slug)
(let ((fc (get (host/blog-field-values-of slug) "category")))
@@ -123,11 +125,24 @@
(fn (slug)
(let ((r (host/blog-get slug)))
(if (nil? r) nil
{:type "create" ;; publishing = the article enters the fed world
:actor "site" ;; P0: a fixed site actor; per-author later
:id (host/blog-cid slug) ;; the object's content CID
:object {:type "article" :slug slug
:category (host/blog--post-category slug)}}))))
(let ((cid (host/blog-cid slug)))
{:verb "create" ;; the transition (draft→published = create)
:actor "site" ;; P0: a fixed site actor; per-author later
:object cid ;; content-addressed REFERENCE (the CID)
:object-type "article"
:slug slug ;; the handle the publish-DAG's ctx reads
:category (host/blog--post-category slug) ;; the field the DAG branches on
:delta "published" ;; what changed
:id cid}))))) ;; dedup identity (the object CID)
;; MARSHAL the canonical activity → next/'s Erlang proplist shape, for the Erlang runner adapter
;; (RA). The seam activity is canonical; each runner adapter maps it to its substrate. Unused until
;; RA, defined + tested here so the reconcile is complete and RA has its bridge ready.
(define host/blog--activity->erl
(fn (a)
{:type (get a :verb)
:actor (get a :actor)
:id (get a :id)
:object {:type (get a :object-type) :slug (get a :slug) :category (get a :category)}}))
;; P0.2: the publish WORKFLOW as an EXECUTE-FOLD composition (host/execute.sx) — the SYNCHRONOUS
;; business flow. Validate, then BRANCH on category (newsletter → build a digest, urgent → notify
;; now, else skip). Content flow (effect/alt), NOT dataflow — so it's the execute-fold, not artdag.
@@ -142,8 +157,9 @@
(when (eq "category" "urgent") (effect notify (field "slug")))
(else (effect skip))))))
;; the ctx a publish activity presents to the publish-DAG (string keys — preds read ctx by key).
;; Reads the canonical activity's top-level :category + :slug (P0.4).
(define host/blog--publish-ctx
(fn (activity) (let ((o (get activity :object))) {"category" (get o :category) "slug" (get o :slug)})))
(fn (activity) {"category" (get activity :category) "slug" (get activity :slug)}))
;; ── P0.3: the seam WIRED on the live host ──────────────────────────────
;; The publish ENGINE = the execute-fold runner (flows.sx) + a local-SX on-publish trigger registry
@@ -159,7 +175,7 @@
:deliver (fn () (list))}) ;; nothing inbound yet — P0 is synchronous
(define host/blog--triggers
{:register! (fn (spec dag hint) nil)
:match (fn (a) (if (and (= (get a :type) "create") (= (get (get a :object) :type) "article"))
:match (fn (a) (if (and (= (get a :verb) "create") (= (get a :object-type) "article"))
(list {:dag host/blog--publish-dag}) (list)))})
;; P0.3b: the flow log is DURABLE — string-keyed records (dodge the keyword/persist top-level split),
;; persisted to the blog store under one key, so /flows survives a restart. Boot-loaded via

View File

@@ -1163,25 +1163,34 @@
;; ── P0.1: business-logic fed-flows — the publish-activity contract ──
;; a published post is described as a fed-sx create activity that next/'s trigger machinery
;; consumes; category (drives the flow branch) comes from a field-value, else a tag, else urgent.
(host-bl-test "publish-activity describes a published post as a fed-sx create activity"
(host-bl-test "P0.4: publish-activity is the CANONICAL seam shape (:verb :object=cid :object-type :slug :category :id)"
(begin
(host/blog-put! "pub1" "Pub One" "(article (h1 \"P\"))" "published")
(host/blog--set-field-values! "pub1" {"category" "newsletter"})
(let ((a (host/blog--publish-activity "pub1")))
(list (get a :type) (get (get a :object) :type) (get (get a :object) :category)
(get (get a :object) :slug) (not (nil? (get a :id))))))
(list "create" "article" "newsletter" "pub1" true))
(list (get a :verb) (get a :object-type) (get a :category) (get a :slug)
(= (get a :object) (get a :id)) (not (nil? (get a :id))))))
(list "create" "article" "newsletter" "pub1" true true))
(host-bl-test "publish-activity category falls back to a tag, else urgent"
(begin
(host/blog-put! "pub2" "Pub Two" "(article (h1 \"Q\"))" "published")
(host/blog-seed! "urgent" "Urgent" "(article (h1 \"u\"))" "published")
(host/blog-relate! "pub2" "urgent" "tagged")
(host/blog-put! "pub3" "Pub Three" "(article (h1 \"R\"))" "published") ;; no field, no tag
(list (get (get (host/blog--publish-activity "pub2") :object) :category)
(get (get (host/blog--publish-activity "pub3") :object) :category)))
(list (get (host/blog--publish-activity "pub2") :category)
(get (host/blog--publish-activity "pub3") :category)))
(list "urgent" "urgent"))
(host-bl-test "publish-activity of a missing post is nil"
(host/blog--publish-activity "nope-nope-nope") nil)
;; P0.4: the marshaller maps the canonical shape → next/'s Erlang proplist (for the RA runner).
(host-bl-test "activity->erl marshals canonical → next/ proplist ({type,object:{type,slug,category}})"
(begin
(host/blog-put! "pub4" "P4" "(article (h1 \"m\"))" "published")
(host/blog--set-field-values! "pub4" {"category" "newsletter"})
(let ((e (host/blog--activity->erl (host/blog--publish-activity "pub4"))))
(list (get e :type) (get (get e :object) :type)
(get (get e :object) :slug) (get (get e :object) :category))))
(list "create" "article" "pub4" "newsletter"))
;; P0.2: the publish WORKFLOW as an execute-fold DAG — branches on category, needs {effect,branch},
;; binds to the synchronous execute-fold runner (derived, not chosen).
(host-bl-test "publish-DAG: category branch (newsletter→digest) via the execute-fold"