Imports:
  - Types:
      - HookRegistry
      - wrap_context
      - build_hook_arguments
      - emit_hook_event
      - declared_actions
    Usages:
      - declaring-actions
      - per-tool-delivery
      - registering-hooks
    From: goga/hooks
  - Types:
      - WorkflowDocument
      - WorkflowGates
      - ResolvedProfile
      - render_contribution
    From: goga/pipeline/workflow

Usages:
  convention: .goga/usages/conventions.md

Annotations: |
  The `convention` practice is used for:
  - Working with the codebase
  - Organizing the REPL development cycle
  - Debugging and testing
  - Organizing the test infrastructure
  - Understanding the general principles and rules of development and
    testing in the project

  This cell owns the hooks zone of the pipeline domain: the fact
  vocabulary of the run events, the read-and-contribute amendment
  context with its per-tool staged commit, the authored-wins workflow
  overlay, and the checkpoint surface that delivers the amendment and
  emits the two run notifications over the platform facade. The zone
  additionally carries the bridged mid-run events: the passthrough run
  and stage contexts of the run interior and their soft emission over
  the same facade — a short-lived process composes the contexts, one
  event per process, and the surface emits them; the curated filtering
  and the vocabulary mapping stay with the caller. One registry per run
  carries every checkpoint of a command — and one registry per event
  process serves a bridged emission; the checkpoints never multiply the
  package enumeration. Every context is built from the operation data
  the caller passes — no repository reads happen here. The amendment
  action is hard: the first failing tool stops the command with a clean
  error naming the tool and the action, and the tool's whole
  contribution is discarded. The notifications are soft — a failing
  hook warns naming the tool, the action, and the reason, and the
  command's exit code is unaffected. Tools are mutually blind — every
  amendment view reads the original authored workflow and the same
  resolved profile fact, never a staged state.
  The amendment is profile-aware: every tool's view carries the
  operation's already-resolved active contributor profile as a read-only
  fact — identical for every tool, absent without activation — and a
  tool's committed contribution renders field-level with that profile's
  content at its commit moment, inside the walk, before the
  presence-based empty-contribution check: every string leaf and every
  string mapping key of the contributed document is a template surface,
  and `render_contribution` renders them under the fixed workflow
  rendering semantics. A render failure is disciplinarily a hook failure
  — one hard pre-run error in the amendment-failure format carrying the
  template cause; the first failing tool stops the walk, later tools'
  hooks never run, and the tool's whole contribution is discarded. A
  contribution without template syntax composes byte-identically with or
  without an active profile.
  The overlay merge preserves the collaboration instructions of the
  workflow model. The merge maintains the assistant-namespace invariant
  end to end: each name appears at most once across the merged catalog
  and every inline declaration. The assistant catalog merges by name
  with field-level overrides: among
  contributing tools the later entry wins per name, and that winning
  delivered entry is the BASE; an authored entry under the same
  name overrides field by field — every field the authored entry
  specifies (agent, env, delegate, prompt, skills — presence decides,
  an explicit empty skills/env is an override) replaces the base value
  while omitted fields keep flowing from the base. A delivered name with
  no authored entry adds as a fresh name verbatim. Tool INLINE
  declarations under an authored name stay silently dropped; every other
  duplicate-suppression rule of the evolving merged namespace holds —
  the merged document never carries a duplicate assistant name. The
  delegation block is whole: the authored block is unbeatable, and
  with no authored block the later contributing block wins — no
  field-level merging. The overlay merge preserves the run-cycle tuning
  the same way: the repeat block is whole — an authored block is
  unbeatable, otherwise the later contributing tool's block wins — and
  the rebuilt document carries the effective repeat verbatim, so a
  tool-amended run never loses an authored cycle bound. The per-stage
  assistant maps append with
  deduplication by name: the authored entries first in authored order,
  then the contributing entries in enumeration order, each entry whose
  name is already present on the stage dropped silently, and an appended
  entry shaped as a declaration (any key beyond gate, when, skip) whose
  name is already present anywhere in the merged workflow-side assistant
  namespace is dropped silently the same way — the append rule is
  form-blind. An appended stage-assistant entry may carry any authored
  form — a reference, a full inline declaration, a when-less extension,
  or a {skip: true} veto; a skip entry and a gate/when-only entry append
  like any other: the merge never resolves a name beyond the workflow
  document — an entry may address a name the workflow-file does not
  declare (a pipeline-file declaration, an extension, or a veto of one),
  and the entry's origin classification and the effective-namespace
  uniqueness (the pipeline declarations included) are compilation checks
  raised where both documents meet. The final
  document assembly carries the merged collaboration fields like every
  workflow-level field — they never vanish in the overlay. The gates
  follow the same preservation law: the workflow-level gates settings
  block merges whole like repeat (an authored block is unbeatable,
  otherwise the later contributing tool's block wins), and every stage's
  authored check-step list is an unbeatable ordinary stage field — an
  authored list is never overwritten, and an unset list takes the later
  contributing tool's entries.
  The overlay merge preserves the global run settings of the workflow
  model: the authored agent and env fields ride the rebuilt document
  verbatim — in the verbatim-from-base set beside profile and build. The
  merge reads the globals of the base only; a tool can neither supply
  nor override them — global run settings belong to the workflow author
  alone.
  Use the `per-tool-delivery` practice for the staged delivery loop of
  the amendment checkpoint — its loop skeleton, primitives, and
  tool-grouped commit apply as written.
  Use the `declaring-actions` practice for the emission contract of
  the notification checkpoints.
  Use the `registering-hooks` practice for the hook signature and the
  failure handling behind every checkpoint.
  Use relative imports.

---

"PipelineIdentity(name: str, display_name: str = \"\", description: str, source: str)":
  location: identity.py
  annotations: |
    The identity vocabulary of every pipeline event — the discovered
    name, the authored header facts, and the source of the
    pipeline-file.

    `name`: the discovered pipeline name — the file stem without the
             .yml extension
    `display_name`: the authored pipeline name from the DSL header; may
                     differ from the discovered stem; empty when the
                     header names none
    `description`: the pipeline description from the DSL header
    `source`: the origin of the pipeline-file — exactly project or user

    Apply the `convention` practice for the data-model rules and
    intra-package imports.

    Requirements:
    - `name` is non-empty and carries no path separators and no .yml
      suffix
    - `source` is exactly project or user
    - Pure facts — the constructing operation passes resolved values;
      nothing is read here
  properties:
    "name -> str": |
      The discovered pipeline name — the file stem without the .yml
      extension.
    "display_name -> str": |
      The authored pipeline name from the DSL header; may differ from
      the discovered stem.
    "description -> str": |
      The pipeline description from the DSL header.
    "source -> str": |
      The origin of the pipeline-file — project or user.

"WorkflowDecision(kind: str, workflow_name: str | None)":
  location: identity.py
  annotations: |
    The workflow decision of one composition — the outcome of the
    resolution and the resolved name.

    `kind`: exactly one of disabled, explicit, auto-match, silent-miss
    `workflow_name`: the resolved workflow name — present for explicit
                      and auto-match, None otherwise

    Apply the `convention` practice for the data-model rules and
    intra-package imports.

    Requirements:
    - `kind` is exactly one of the four fixed values
    - Pure facts — the decision mirrors the resolution the operation
      already made
  properties:
    "kind -> str": |
      The outcome of the workflow resolution — disabled, explicit,
      auto-match, or silent-miss.
    "workflow_name -> str | None": |
      The resolved workflow name, or None when no name resolved.

"WorkIdentity(branch: str, slug: str | None = None, year: str | None = None)":
  location: identity.py
  annotations: |
    The topics-shaped identity of the current work — the branch, with
    the topic slug and year when the branch hosts a topic.

    `branch`: the current branch name as resolved by the operation
    `slug`: the normalized topic slug — present when the branch hosts a
             topic
    `year`: the resolved year as four digits — present when the branch
             hosts a topic

    Apply the `convention` practice for the data-model rules and
    intra-package imports.

    Requirements:
    - The hosting decision and every resolution happen in the
      constructing operation — nothing is read here
    - The branch-only form — `slug` and `year` None — serves a branch
      hosting no topic
  properties:
    "branch -> str": |
      The current branch name as resolved by the operation.
    "slug -> str | None": |
      The normalized topic slug, or None in the branch-only form.
    "year -> str | None": |
      The resolved year as four digits, or None in the branch-only form.

"CompositionStage(id: str, title: str)":
  location: contexts.py
  annotations: |
    One row of the final composition — the stage identity and its
    display title, as the card shows them.

    `id`: the stage identifier
    `title`: the stage display title

    Apply the `convention` practice for the data-model rules and
    intra-package imports.
  properties:
    "id -> str": |
      The stage identifier.
    "title -> str": |
      The stage display title.

"ToolContribution(tool: str, document: WorkflowDocument)":
  location: overlay.py
  annotations: |
    The committed contribution of one tool — the pairing of the tool
    identity with its declarative document.

    `tool`: the tool identity assigned by the platform
    `document`: the committed contribution — a `WorkflowDocument`-shaped
                 set of instructions

    Apply the `convention` practice for the data-model rules and
    intra-package imports.
  properties:
    "tool -> str": |
      The tool identity assigned by the platform.
    "document -> WorkflowDocument": |
      The committed contribution of the tool.

"WorkflowOverlay(workflow: WorkflowDocument | None, provenance: list[str])":
  location: overlay.py
  annotations: |
    The result of the amendment layer — the effective workflow and its
    provenance.

    `workflow`: the final effective workflow — None only in the
                 passthrough case: no authored workflow and no committed
                 contribution
    `provenance`: the tools whose contributions committed, in
                   enumeration order

    Apply the `convention` practice for the data-model rules and
    intra-package imports.

    Requirements:
    - A None workflow with a non-empty provenance never occurs — a
      committed contribution always yields a document
  properties:
    "workflow -> WorkflowDocument | None": |
      The final effective workflow, or None in the passthrough case.
    "provenance -> list[str]": |
      The tools whose contributions committed, in enumeration order.

"WorkflowAmendment(pipeline: PipelineIdentity, decision: WorkflowDecision, workflow: WorkflowDocument | None, work: WorkIdentity, profile: ResolvedProfile | None = None)":
  location: amendments.py
  annotations: |
    The read-and-contribute view of one tool — the delivered facts of
    the amendment checkpoint and the buffer of one tool's contribution.

    `pipeline`: the identity of the pipeline being composed
    `decision`: the workflow decision of the operation
    `workflow`: the original authored workflow — post decision, post
                 runner-skip merge, pre-layer; read-only and identical
                 for every tool; None when no workflow resolved
    `work`: the current work identity
    `profile`: the operation's already-resolved active contributor
                profile — the profile that rendered the authored
                workflow-file: its name, its whole content, and its
                source (project or home) — or None when no profile is
                active (no activation resolved, or no workflow in
                effect)

    Apply the `convention` practice for the data-model rules and
    intra-package imports.
    Use the `registering-hooks` practice for the hook signature that
    receives this view.

    Requirements:
    - The reads deliver the original facts — no staged-application
      state exists; a tool never sees another tool's contribution
    - The `profile` fact is operation data passed in by the caller —
      no reads and no re-resolution happen at the checkpoint; it is
      read-only and identical for every tool and in every delivery
      form, and reads absent (None) without activation — including
      the no-workflow silent-miss case
    - The buffered contribution belongs to this tool alone
  properties:
    "pipeline -> PipelineIdentity": |
      The identity of the pipeline being composed.
    "decision -> WorkflowDecision": |
      The workflow decision of the operation.
    "workflow -> WorkflowDocument | None": |
      The original authored workflow, read-only and identical for every
      tool; None when no workflow resolved.
    "work -> WorkIdentity": |
      The current work identity.
    "profile -> ResolvedProfile | None": |
      The operation's active contributor profile — its name, its whole
      content, and its source — or None when no profile is active;
      read-only and identical for every tool.
  methods:
    "contribute(document: WorkflowDocument)": |
      Buffer one declarative contribution of this tool.

      `document`: the complete contribution — a `WorkflowDocument`-shaped
                  set of instructions (prompt, stages, extend, memory,
                  assistants, delegation, repeat, gates) using the same
                  vocabulary an authored workflow-file uses

      Requirements:
      - The call buffers into the buffer of this tool alone and changes
        nothing until the delivery commits it
      - The replacement is whole — a later call replaces the earlier
        buffered document
      - A document with no prompt, no stages, no extend, no memory, no
        assistants, no delegation, no repeat, and no gates block is an
        empty contribution — the delivery discards it with a warning

      Constraints:
      - Do not cancel, redirect, or defer the operation — a
        contribution transforms the workflow layer only

"merge_workflow_overlay(base: WorkflowDocument | None, contributions: list[ToolContribution]) -> overlay: WorkflowOverlay":
  location: overlay.py
  annotations: |
    The authored-wins overlay merge — compose the effective workflow
    from the authored base and the committed tool contributions.

    `base`: the authored workflow after the decision and the
             runner-skip merge; None is the empty base — a silent
             auto-match miss keeps the layer active
    `contributions`: the committed contributions in enumeration order
    `overlay`: the effective workflow with its provenance

    Apply the `convention` practice for docstring style and
    intra-package imports.

    Algorithm:
    1. Take `base` as the authored layer — None is the empty base
    2. prompt: place the authored prompt first, then append the prompt
       of every committed contribution in enumeration order; with no
       authored prompt the first tool text becomes the prompt
    3. memory: keep the authored block when present — it is unbeatable;
       otherwise the block of the later contributing tool wins; no
       field-level merging
    4. stages: for each stage name take the authored entry as the
       ground — an authored field is never overwritten; a field the
       author left unset takes the value of the later contributing tool
       that sets it; a stage with no authored entry is fully defined by
       the tools. The per-stage field merge covers the FULL declared
       field set of WorkflowStage, including env: an authored env is
       unbeatable exactly like every other authored stage field; an
       unset env takes the value of the later contributing tool that
       sets it. The merge is field-set-complete, never a named-subset
       copy — a new stage field flows through without touching this
       cell again. The assistants field is the one append-merge stage
       field — it follows 5.1 instead of the authored-value-wins rule;
       every other stage field follows the field-set-complete merge
       unchanged
    4.1. assistants (catalog): resolve the winning delivered entry per
        name among the contributions in enumeration order (the
        later-tool-wins rule among contributions). For a name carrying an authored entry
        (the authored catalog or an authored inline declaration — one
        authoring surface owns the name): the winning delivered entry of
        that name is the BASE, and the authored entry overrides field by
        field — every field it specifies (agent, env, delegate, prompt,
        skills; presence decides — None is not authored, an explicit
        empty skills list or env map IS) replaces the base value, every
        omitted field flows from the base; no delivered entry under the
        name leaves the authored entry standing alone. A delivered name
        with no authored entry adds as a fresh name with the winning
        entry verbatim. Tool inline declarations under an authored name
        are dropped silently; the namespace carries each
        name exactly once
    4.2. delegation: keep the authored block when present — it is
        unbeatable; otherwise the block of the later contributing tool
        wins; no field-level merging
    4.3. repeat: keep the authored block when present — it is unbeatable;
        otherwise the block of the later contributing tool wins; no
        field-level merging
    4.4. gates (settings block, `WorkflowGates`): keep the authored block
        when present — it
        is unbeatable; otherwise the block of the later contributing tool
        wins; no field-level merging
    5. skip is an ordinary stage field: an authored skip — from the
       workflow-file or the merged runner skip — is unbeatable; an
       unset skip takes a contributing skip; skip=False overrides
       nothing
    5.1. stage assistants: for each stage name the authored map is the
        ground — the authored entries first, in authored order; the
        contributing entries append in enumeration order, an entry whose
        name is already present on the stage dropped silently, and an
        appended entry shaped as a declaration (any key beyond gate,
        when, skip) whose name is already present anywhere in the merged
        workflow-side assistant namespace dropped silently the same way;
        a skip entry and a gate/when-only entry append like every other
        entry (their origin classification belongs to compilation); a
        stage with no authored entry takes the appended contributing
        entries the same way
    5.2. stage gates: an ordinary stage field of the field-set-complete
        stage merge — an authored check-step list is never overwritten; a
        field the author left unset takes the value of the later
        contributing tool that sets it
    6. extend: keep the authored entries; a contribution entry under an
       authored name is not applied; among contributing tools the later
       entry wins per name
    7. Compose the provenance from the identities of the committed
       contributions in enumeration order
    8. Return the `WorkflowOverlay` — the workflow None only when the
       base is None and no contribution committed; the final document
       assembly carries the profile, build, agent, and env fields of
       `base` verbatim (exactly as memory survives the rebuild), the
       assistants field of the base together with the appended
       contributing entries, the effective repeat, and the effective
       gates settings block riding the rebuilt document verbatim —
       workflow-level instructions never vanish in the overlay

    Requirements:
    - Pure — the inputs stay unmutated; the result is a new document
    - The prompt concatenation joins the non-empty texts with a single
      blank line between consecutive texts — the authored prompt first,
      then each committed contribution text in enumeration order; no other
      separators, prefixes, or suffixes are added
    - Deterministic — the same inputs give the same overlay
    - The result stays declarative — it passes the same compilation
      validation an authored workflow passes, and the merged assistant
      namespace (the catalog plus every inline declaration) never carries
      a duplicate name
    - The rebuilt `WorkflowDocument` preserves every workflow-level field
      of the base (profile, build verbatim; memory as today) and
      the stage merge is over the complete WorkflowStage field set
      (including env)
    - The rebuilt `WorkflowDocument` preserves the collaboration fields:
      the merged catalog, the effective delegation block, and the
      appended per-stage assistant maps — a rebuild that drops them
      would silently disable collaboration for tool-amended runs
    - The rebuilt `WorkflowDocument` preserves the run-cycle tuning: the
      effective repeat block rides the rebuild verbatim — a rebuild that
      drops it would silently recompile an authored cycle bound as the
      scalar default on tool-amended runs
    - The rebuilt `WorkflowDocument` preserves the gates instructions — the
      settings block whole and every stage's authored check-step list; a
      rebuild that drops them would silently strip stage quality checks
      from tool-amended runs
    - The rebuilt `WorkflowDocument` preserves the global run settings:
      the agent and env fields of the base ride the rebuild verbatim —
      a rebuild that drops them would silently revert a tool-amended
      run to configuration-level globals; a tool-supplied global never
      reaches the final document (the merge reads the globals of the
      base only)
    - The override is field-presence based: an authored None means
      "not authored" (the base value flows), an authored empty
      skills/env means "clear" (the base value is replaced with the
      empty value), an authored delegate False is an opt-out while an
      absent delegate inherits the base value
    - A name authored inline and delivered in a tool CATALOG follows the
      same rule — the authored inline declaration overrides the
      delivered catalog entry field by field
    - Workflows whose assistant names collide with no tool delivery
      merge to their authored workflow verbatim
    - The merge is form-blind over the stage-assistant entry forms: a
      skip veto, a when-less extension, a reference, and a full inline
      declaration all ride the append rule unchanged; the merged
      workflow document never resolves a name beyond the workflow-file —
      entries addressing pipeline-file declarations pass through, and
      every collision with them fails at compilation with the
      effective-namespace errors

    Constraints:
    - Do not read or write the filesystem
    - Do not invent instructions absent from the inputs
    - Do not mutate `base`, the contributions, or their maps
    - Do not interpret the repeat block — cycle semantics belong to the
      consumer and the engine; the merge carries the value whole
    - Do not interpret, validate, or rebuild the gates values — the block
      and the per-stage lists are carried whole; the merge unit is the
      field/block
    - Do not read the agent or env fields of any contribution document
      — the globals are author-territory; only the base carries them
      into the overlay
    - Do not classify an appended entry's origin (veto, extension,
      reference, declaration) and do not resolve names against any
      pipeline-file — the overlay is pipeline-blind by design
    - Do not merge content fields partially — prompt
      and skills replace whole (no text concatenation, no list union); the
      field unit is the merge unit

"RunCreated(pipeline: PipelineIdentity, decision: WorkflowDecision, workflow: WorkflowDocument | None, composition: list[CompositionStage], provenance: list[str], work: WorkIdentity, statuses: list[str], runtime_dir: str)":
  location: contexts.py
  annotations: |
    The read-only context of the run-creation notification — the facts
    of the composition at the moment immediately before the runner
    launch.

    `pipeline`: the identity of the running pipeline
    `decision`: the workflow decision of the operation
    `workflow`: the final effective workflow — the authored instructions
                 plus the committed tool contributions
    `composition`: the ordered stages of the final composition — one row
                    per compiled stage, as the card shows
    `provenance`: the tools whose contributions committed, in
                   enumeration order
    `work`: the current work identity
    `statuses`: the maximal present statuses of the work's topic at the
                 moment — both axes, built-in and tool
    `runtime_dir`: the run's runtime directory as a posix string

    Apply the `convention` practice for the data-model rules and
    intra-package imports.

    Requirements:
    - Read-only facts of the composed moment — a hook observes and
      cannot alter
  properties:
    "pipeline -> PipelineIdentity": |
      The identity of the running pipeline.
    "decision -> WorkflowDecision": |
      The workflow decision of the operation.
    "workflow -> WorkflowDocument | None": |
      The final effective workflow — authored instructions plus the
      committed tool contributions.
    "composition -> list[CompositionStage]": |
      The ordered stages of the final composition, as the card shows
      them.
    "provenance -> list[str]": |
      The tools whose contributions committed, in enumeration order.
    "work -> WorkIdentity": |
      The current work identity.
    "statuses -> list[str]": |
      The maximal present statuses of the work's topic at the moment.
    "runtime_dir -> str": |
      The run's runtime directory as a posix string.

"RunCompleted(pipeline: PipelineIdentity, decision: WorkflowDecision, workflow: WorkflowDocument | None, composition: list[CompositionStage], provenance: list[str], work: WorkIdentity, statuses: list[str], runtime_dir: str, exit_code: int)":
  location: contexts.py
  annotations: |
    The read-only context of the run-completion notification — the same
    facts recomputed at the completion moment, plus the outcome of the
    launch attempt.

    `pipeline`: the identity of the running pipeline
    `decision`: the workflow decision of the operation
    `workflow`: the final effective workflow the run executed
    `composition`: the ordered stages of the executed composition
    `provenance`: the tools whose contributions committed
    `work`: the current work identity
    `statuses`: the maximal present statuses recomputed at the
                 completion moment
    `runtime_dir`: the run's runtime directory as a posix string
    `exit_code`: the actual exit code of the launch attempt — zero,
                  non-zero, or a spawn failure (126/127)

    Apply the `convention` practice for the data-model rules and
    intra-package imports.

    Requirements:
    - Read-only facts of the completed attempt — completion is a fact,
      not a success claim
  properties:
    "pipeline -> PipelineIdentity": |
      The identity of the running pipeline.
    "decision -> WorkflowDecision": |
      The workflow decision of the operation.
    "workflow -> WorkflowDocument | None": |
      The final effective workflow the run executed.
    "composition -> list[CompositionStage]": |
      The ordered stages of the executed composition.
    "provenance -> list[str]": |
      The tools whose contributions committed, in enumeration order.
    "work -> WorkIdentity": |
      The current work identity.
    "statuses -> list[str]": |
      The maximal present statuses recomputed at the completion moment.
    "runtime_dir -> str": |
      The run's runtime directory as a posix string.
    "exit_code -> int": |
      The actual exit code of the launch attempt.

"RunIdentity(run_id: str, run_dir: str, root_dir: str, resumed: bool)":
  location: contexts.py
  annotations: |
    The run identity carried by every bridged mid-run event — passthrough
    values under goga-idiomatic names; the raw event payload stays out of
    the zone.

    `run_id`: the run identity of the executing run
    `run_dir`: the run's state directory as a posix string
    `root_dir`: the flow's root directory as a posix string
    `resumed`: whether the run resumed earlier state

    Apply the `convention` practice for the data-model rules and
    intra-package imports.

    Requirements:
    - Pure passthrough facts — the constructing operation passes
      resolved values; nothing is read here
  properties:
    "run_id -> str": |
      The run identity of the executing run.
    "run_dir -> str": |
      The run's state directory as a posix string.
    "root_dir -> str": |
      The flow's root directory as a posix string.
    "resumed -> bool": |
      Whether the run resumed earlier state.

"StageTransition(id: str, name: str, from_status: str, to_status: str, phase: str)":
  location: contexts.py
  annotations: |
    The stage facts of one bridged stage event — the transition of a
    single stage.

    `id`: the stage identifier
    `name`: the stage name
    `from_status`: the lifecycle status the stage left
    `to_status`: the lifecycle status the stage entered
    `phase`: the stage phase at the event moment

    Apply the `convention` practice for the data-model rules and
    intra-package imports.

    Requirements:
    - `from_status` / `to_status` carry the lifecycle statuses under
      idiomatic names — the raw names are reserved words and cannot serve
      as attribute names
  properties:
    "id -> str": |
      The stage identifier.
    "name -> str": |
      The stage name.
    "from_status -> str": |
      The lifecycle status the stage left.
    "to_status -> str": |
      The lifecycle status the stage entered.
    "phase -> str": |
      The stage phase at the event moment.

"RunEvent(pipeline: str, run: RunIdentity, event_id: str, occurred_at: str, reason: str = \"\")":
  location: contexts.py
  annotations: |
    The read-only context of a run-level bridged event — the facts a tool
    needs to react without knowledge of the event source.

    `pipeline`: the pipeline name of the running flow
    `run`: the run identity of the event
    `event_id`: the stable event identity — the idempotency key of the
                 emission
    `occurred_at`: the event moment as an ISO-8601 UTC string
    `reason`: the free-text cause of the event; empty when the source
               names none

    Apply the `convention` practice for the data-model rules and
    intra-package imports.

    Requirements:
    - Read-only facts — a hook observes and cannot alter
    - No raw payload exposure — only the curated facts under idiomatic
      names
  properties:
    "pipeline -> str": |
      The pipeline name of the running flow.
    "run -> RunIdentity": |
      The run identity of the event.
    "event_id -> str": |
      The stable event identity — the idempotency key of the emission.
    "occurred_at -> str": |
      The event moment as an ISO-8601 UTC string.
    "reason -> str": |
      The free-text cause of the event; empty when the source names none.

"StageEvent(pipeline: str, run: RunIdentity, stage: StageTransition, event_id: str, occurred_at: str, reason: str = \"\")":
  location: contexts.py
  annotations: |
    The read-only context of a stage-level bridged event — the run facts
    plus the transition of one stage.

    `pipeline`: the pipeline name of the running flow
    `run`: the run identity of the event
    `stage`: the stage transition of the event
    `event_id`: the stable event identity — the idempotency key of the
                 emission
    `occurred_at`: the event moment as an ISO-8601 UTC string
    `reason`: the free-text cause of the event; empty when the source
               names none

    Apply the `convention` practice for the data-model rules and
    intra-package imports.

    Requirements:
    - Read-only facts — a hook observes and cannot alter
    - No raw payload exposure — only the curated facts under idiomatic
      names
  properties:
    "pipeline -> str": |
      The pipeline name of the running flow.
    "run -> RunIdentity": |
      The run identity of the event.
    "stage -> StageTransition": |
      The stage transition of the event.
    "event_id -> str": |
      The stable event identity — the idempotency key of the emission.
    "occurred_at -> str": |
      The event moment as an ISO-8601 UTC string.
    "reason -> str": |
      The free-text cause of the event; empty when the source names none.

"PipelineHooks()":
  location: events.py
  annotations: |
    The checkpoint surface of the pipeline domain — the amendment
    delivery, the run notifications, and the bridged mid-run events over
    the platform facade.

    Apply the `convention` practice for the code style and
    intra-package imports.
    Use the `per-tool-delivery` practice for the staged delivery loop of
    the amendment checkpoint.
    Use the `declaring-actions` practice for the emission contract of
    the notification checkpoints.
    Use the `registering-hooks` practice for the registration contract
    behind every checkpoint.

    Requirements:
    - Cheap construction — no enumeration and no imports happen at
      construction
    - One `HookRegistry` per run carries every checkpoint of a command
      — the assembly runs once per run whatever the number of
      checkpoints; a bridged emission builds its registry once per
      event process
    - Every context is built from the values the caller passes — no
      repository reads happen at a checkpoint
  methods:
    "amend_workflow(pipeline: PipelineIdentity, decision: WorkflowDecision, workflow: WorkflowDocument | None, work: WorkIdentity, profile: ResolvedProfile | None = None) -> overlay: WorkflowOverlay": |
      Deliver the workflow-amendment checkpoint and return the
      effective workflow with its provenance.

      `pipeline`: the identity of the pipeline being composed
      `decision`: the workflow decision of the operation
      `workflow`: the authored workflow after the decision and the
                   runner-skip merge; None when no workflow resolved
      `work`: the current work identity
      `profile`: the operation's already-resolved active contributor
                 profile — the profile that rendered the authored
                 workflow-file — or None when no profile is active
                 (including the no-workflow silent-miss case);
                 identical for every tool and in every delivery form
      `overlay`: the effective workflow and the contributing tools

      Use the `per-tool-delivery` practice for the delivery loop.

      Algorithm:
      1. Resolve the address domain="pipeline", action="amend_workflow"
         against `declared_actions`
      2. Walk the subscriptions of the address per tool in enumeration
         order: build the tool's `WorkflowAmendment` view over the
         delivered facts — every tool reads the same original
         `workflow` and the same `profile` fact — wrap it via
         `wrap_context`, project the call arguments via
         `build_hook_arguments` with the tool's own context, and call
         each hook of the tool
      3. A tool with a raising hook is a hard failure: a clean error
         naming the tool and the action stops the command at the first
         failure; the tool's contribution is discarded
      4. A tool whose every hook returned without raising has its
         buffered document rendered at its commit moment: every string
         of the contribution renders with the active profile's content
         via `render_contribution`, which receives the content of
         `profile` as its rendering context — an empty mapping when
         `profile` is None. A render failure is the same hard failure
         as a raising hook: the clean error naming the tool and the
         action carries the template cause from the render error; the
         tool's whole contribution is discarded and the walk stops
         before the next tool is called
      5. The empty-contribution check runs on the rendered document and
         stays presence-based and unchanged: a tool whose rendered
         document is empty — no prompt, no stages, no extend, no
         memory, no assistants, no delegation, no repeat, and no gates
         block — is a content no-op: a warning naming the tool, the
         action, and the reason, the contribution discarded, the walk
         continues
      6. A tool whose rendered document is non-empty commits as one
         `ToolContribution` — the rendered document is the committed
         document
      7. Merge the committed contributions onto `workflow` via
         `merge_workflow_overlay` and return the overlay

      Requirements:
      - The commit granularity is the tool — a tool's whole
        contribution renders and commits only after every hook of the
        tool succeeds
      - The render runs inside the walk at each tool's commit — never
        as a pass after the walk; after a render failure no later
        tool's hooks run
      - The profile fact never varies per tool — one resolved value
        reaches every view
      - An address without subscriptions returns the passthrough
        overlay — the workflow passed in, an empty provenance
      - The merged result passes the same compilation validation an
        authored workflow passes
      - A contribution without template syntax composes byte-identically
        with or without an active profile

      Constraints:
      - Do not apply any contribution outside the single merge after
        the walk
      - Do not skip a subscriber of the address
      - Do not read repositories or the filesystem at the checkpoint
      - Do not resolve the profile here — the resolved value arrives as
        `profile`
    "emit_run_created(pipeline: PipelineIdentity, decision: WorkflowDecision, overlay: WorkflowOverlay, composition: list[CompositionStage], work: WorkIdentity, statuses: list[str], runtime_dir: str)": |
      Emit the run-creation notification — the facts of the composition
      immediately before the runner launch.

      `pipeline`: the identity of the running pipeline
      `decision`: the workflow decision of the operation
      `overlay`: the amendment result — the effective workflow and the
                  provenance
      `composition`: the ordered stages of the final composition
      `work`: the current work identity
      `statuses`: the maximal present statuses at the moment
      `runtime_dir`: the run's runtime directory as a posix string

      Use the `declaring-actions` practice for the emission contract.

      Algorithm:
      1. Build the `RunCreated` context from the values — the effective
         workflow and the provenance read from `overlay`
      2. Emit the address domain="pipeline", action="run_created" via
         `emit_hook_event`

      Requirements:
      - Fire-and-forget — nothing is collected and no value returns
      - A failing hook is skipped with a warning under the soft error
        class of the action — the launch proceeds
    "emit_run_completed(pipeline: PipelineIdentity, decision: WorkflowDecision, overlay: WorkflowOverlay, composition: list[CompositionStage], work: WorkIdentity, statuses: list[str], runtime_dir: str, exit_code: int)": |
      Emit the run-completion notification — the recomputed facts of
      the finished launch attempt.

      `pipeline`: the identity of the running pipeline
      `decision`: the workflow decision of the operation
      `overlay`: the amendment result of the run
      `composition`: the ordered stages of the executed composition
      `work`: the current work identity
      `statuses`: the maximal present statuses recomputed at the
                   completion moment
      `runtime_dir`: the run's runtime directory as a posix string
      `exit_code`: the actual exit code of the launch attempt

      Use the `declaring-actions` practice for the emission contract.

      Algorithm:
      1. Build the `RunCompleted` context from the values
      2. Emit the address domain="pipeline", action="run_completed"
         via `emit_hook_event`

      Requirements:
      - Fire-and-forget — nothing is collected and no value returns
      - The emission happens on every launch-attempt return path —
        zero, non-zero, and spawn failures alike
      - A failing hook warns under the soft error class — the exit code
        of the run is never affected
    "emit_run_event(action: str, context: RunEvent)": |
      Emit a run-level bridged event — the soft notification of the run
      interior.

      `action`: the run-level action name within the pipeline domain
      `context`: the read-only facts of the event

      Use the `declaring-actions` practice for the emission contract.

      Algorithm:
      1. Emit the address domain="pipeline", action=`action` with
         `context` over the platform facade

      Requirements:
      - Fire-and-forget — nothing is collected and no value returns
      - One shared read-only context instance — every subscribed tool
        reads the same facts
      - A failing hook warns under the soft error class — nothing outside
        the emission is affected
    "emit_stage_event(action: str, context: StageEvent)": |
      Emit a stage-level bridged event — the soft notification of a stage
      transition of the run interior.

      `action`: the stage-level action name within the pipeline domain
      `context`: the read-only facts of the event

      Use the `declaring-actions` practice for the emission contract.

      Algorithm:
      1. Emit the address domain="pipeline", action=`action` with
         `context` over the platform facade

      Requirements:
      - Fire-and-forget — nothing is collected and no value returns
      - One shared read-only context instance — every subscribed tool
        reads the same facts
      - A failing hook warns under the soft error class — nothing outside
        the emission is affected

---

Author: Goga
CreatedAt: 18/09/26
Description: |
  Owner of the pipeline domain hooks zone — the run-event facts, the
  workflow amendment with its overlay, the checkpoint surface over the
  hooks platform, and the bridged mid-run events with their passthrough
  contexts. The overlay merge preserves the full workflow model —
  per-stage `env` instructions, the workflow-level `profile` and `build`
  fields, the global `agent` and `env` run settings, the run-cycle
  tuning (repeat block, gates settings block) with
  the per-stage check-step lists, and the collaboration instructions
  (assistant catalog, delegation block, stage attachments). The
  amendment is profile-aware: the resolved-profile fact on the view and
  the commit-time rendering of contributed strings.
