# People, starters & leavers — module spec (generated from modules/hr/module.yaml)
# A starting vocabulary for phase 2: correct it with the customer, then write ERP_HR.md.
# START HERE, before reading on: dodil://erp/build is the map (read it first; this spec is a vocabulary, not the method).
# WORKING CODE EXISTS — run `code.init` below (uvx --from git+https://git.dodil.io/dodil/erp-platform.git@v0.9.13 erp-compose init hr): it composes these bricks; do not rewrite the module.
schema: dodil.module-spec/v1
code:
  start_here: "START HERE, before reading on: dodil://erp/build is the map (read it first; this spec is a vocabulary, not the method). Then, in the project folder, two commands: (1) `uvx --from git+https://git.dodil.io/dodil/erp-platform.git@v0.8.2 erp-compose init hr`; (2) SHOW the customer the diagram: `uvx --from git+https://git.dodil.io/dodil/erp-platform.git@v0.8.2 erp-compose process --module hr --playbook employee-onboarding --calls config/hr.calls.yaml` (config/hr.calls.yaml: `- { use_case: install_localisation_pack, args: { pack: gb, with_playbooks: true } }`), then paste its step names in order, with who does each, into your message (`grep -o 'Task_[a-z_]*\" name=\"[^\"]*\"' processes/employee-onboarding.bpmn`). The signed artifact is that BPMN: never prose, never \"open bpmn.io\". Cards: dodil://erp/phase/show, dodil://erp/phase/signoff."
  status: This module has working, tested code. COMPOSE it; do not rewrite it.
  how: "Run: uvx --from git+https://git.dodil.io/dodil/erp-platform.git@v0.9.13 erp-compose init hr  (in a fresh folder; no DODIL login needed). It pins the bricks at these tags, installs them, writes compose.yaml, requirements.txt and tests/test_composition.py, and runs the checks. Then configure rows through the bricks' use cases. Write a new brick only for a need no brick covers."
  init: uvx --from git+https://git.dodil.io/dodil/erp-platform.git@v0.9.13 erp-compose init hr
  repos:
    - name: brick-hr
      role: brick
      tag: v0.5.3
      clone: git clone --depth 1 --branch v0.5.3 https://git.dodil.io/dodil/erp-brick-hr.git
    - name: brick-business-partner
      role: brick
      tag: v0.3.2
      clone: git clone --depth 1 --branch v0.3.2 https://git.dodil.io/dodil/erp-brick-business-partner.git
    - name: erp-platform
      role: platform
      tag: v0.8.2
      clone: git clone --depth 1 --branch v0.8.2 https://git.dodil.io/dodil/erp-platform.git
  compose_yaml: |-
    # compose.yaml: what `uvx --from git+https://git.dodil.io/dodil/erp-platform.git@v0.9.13 erp-compose init hr` writes (for reference; run the command, do not
    # hand-write this). The exact format erp_platform.compose loads; check it: erp-compose check compose.yaml
    name: <customer>-hr
    version: 0.1.0
    tier: 1
    bricks:
      - { name: hr, brick: "brick_hr.application.use_cases:HR", version: 0.5.3 }
      - { name: business-partner, brick: "brick_bp.application.use_cases:BP", version: 0.3.2 }
    # capabilities: omit to let each capability's only provider be used; a capability no brick
    # provides becomes a manual task. Map one only to choose between two providers.
  test_composition_py: |
    """The composition boots, its bricks answer through HTTP together, and a signed-in caller can read each one."""
    import inspect
    import pathlib
    from contextlib import ExitStack

    import anyio
    import httpx
    from sqlalchemy import create_engine
    from erp_platform import compose, seam
    from erp_platform.scenarios import Catalogue
    from erp_platform.scenarios.inprocess import stage

    COMPOSE = pathlib.Path(__file__).resolve().parent.parent / "compose.yaml"


    def test_composition_boots_and_every_brick_answers_a_signed_in_read(tmp_path):
        comp = compose.load(COMPOSE)
        assert compose.check(comp)["problems"] == []
        engine = create_engine(f"sqlite:///{tmp_path / 'bucket.db'}", connect_args={"check_same_thread": False})
        perms = sorted({u.permission for m in comp.members for u in m.brick.use_cases if u.permission})
        me = {"sub": "tester.1", "email": "tester@test", "app_roles": ["tester"], "permissions": perms}

        async def get(app, path):
            async with httpx.AsyncClient(transport=httpx.ASGITransport(app=app), base_url="http://t") as c:
                return await c.get(path, headers=seam.gateway_headers(me))

        with ExitStack() as st:
            app = stage(Catalogue("t", compose=comp, roles=None), st, lambda name: engine).app
            assert anyio.run(get, app, "/healthz").status_code == 200
            for m in comp.members:
                reads = [u for u in m.brick.use_cases if u.kind == "query" and u.method == "GET" and u.tool
                         and not u.path_params and all(d is not inspect.Parameter.empty for _, _, d in u.inputs)]
                assert reads, f"{m.name}: no plain read use case to call"
                # The first plain read may refuse an empty question (activity's GET /contacts wants a bp_id or an
                # email: 422). A refusal is the use case answering; a 5xx is the composition broken. So: no read
                # may 5xx, and at least one must answer 200.
                answers = []
                for u in reads:
                    r = anyio.run(get, app, f"/{m.name}{u.path}")
                    assert r.status_code < 500, f"{m.name} {u.path}: {r.status_code} {r.text[:200]}"
                    answers.append(f"{u.path} {r.status_code}")
                    if r.status_code == 200:
                        break
                else:
                    raise AssertionError(f"{m.name}: no plain read answered 200 ({', '.join(answers)})")
id: hr
name: People, starters & leavers
short: People
version: 4
maturity: tested
summary: Who works here, on what terms and since when, and the admin of bringing a new employee or freelancer in and taking them out again. That covers their details, the contract, accounts and access, first-week plans, everyone's tasks, and access removed at the right time. The history is kept, so nothing is ever overwritten.
facets:
  domain: people
  industries:
    - any
  customer_words:
    - onboarding and offboarding
    - bring a new employee or freelancer into the business
    - collect their details and trigger an onboarding checklist
    - remove access at the right time
    - who works here
    - starters and leavers
    - a new starter on Monday
    - handover when someone leaves
  replaces:
    - spreadsheets
    - a checklist in a shared doc
    - BambooHR
    - HiBob
    - Personio
    - Workday
  pillars:
    - sql
    - graph
  first_module_fit: medium
  depends_on:
    - module: business-partner
      why: every person gets ONE business partner (one per natural person, S/4's model), so contracts, finance and purchasing address the same person with one key, and a freelancer's company is the supplier finance pays
      required: true
    - module: contracts
      why: the contract step in a run (draft from an approved template, sign, file the signed copy on the person)
      required: recommended
  feeds:
    - contracts
    - expenses
    - itsm
    - helpdesk
  owns_master_data:
    - person
    - org_unit
    - position
    - job
  references_master_data:
    - business_partner
    - cost_centre
brick:
  package: brick_hr
  short_name: hr
  layout:
    - "src/brick_hr/domain/        rules in plain Python: aggregates, value objects, domain events, domain services, policies. No SQLAlchemy, FastAPI, MCP or identity."
    - src/brick_hr/application/   use cases declared ONCE with @HR.use_case (each one is an API route AND an MCP tool), with `caller` as the first parameter; row visibility is decided here
    - src/brick_hr/infrastructure/ tables + one repository per aggregate (erp_platform.repository Aggregate/Part); the CapabilitySeam and the Models adapter live here (the anti-corruption layers)
    - src/brick_hr/app.py         app = HR.app()
    - src/brick_hr/schema.sql     inside the package, so an installed brick can migrate itself; additive only
    - "tests/test_rules.py         rules with no database: one test per Given/When/Then sentence"
    - "tests/test_doors.py         both doors (API and MCP) over the real app with storage on SQLite / the in-memory repository: same outcome both ways, the 404 for another person's row, the 403 without the permission"
    - tests/test_tier1.py         a tier-1 suite with the real neighbour bricks (business-partner, contracts when it exists) in one bucket
    - scripts/live_check.py       the deployed brick against a dev bucket (erp_platform.livecheck)
    - "README.md · AGENTS.md · CLAUDE.md, like brick-pipeline's: where a change goes, what not to do, how to test"
  refusals: Refused(status, reason) with the rule's own words; a broken domain rule is 409, invalid input 422, a row the caller may not see 404 (never 403)
  no_hand_written_doors: "no api/ or mcp/ folder: both doors are generated from the use-case declarations"
  uses_platform:
    - "erp_platform.repository: Aggregate/Part, one aggregate per unit of work, no session.merge, no hand-written upsert"
    - "erp_platform.money: exact Money. NEEDS a 4-decimal Rate type (see domain_model.value_objects.Rate); money.py is 2dp today"
    - "erp_platform.seam: the business-partner seam (bp:person:sync, bp:partner:promote)"
    - "CapabilitySeam (platform, to be built per capabilities.yaml 0.3): every action step, contracts.* included"
    - "the public-link door (platform, to be built): the starter's intake link"
    - "the tracked-work LIBRARY (platform, not a brick): timing rules with working-day offsets and the chase unit, due/overdue/today/this-week, the board, chasing cadence. hr passes it a WorkCalendar built from its schedule and holiday rows; delivery will use it too"
    - "erp_platform.requestlog: one request id through every door and seam (logged, not used as a key)"
    - "append-only ids are (aggregate key | seq), deterministic, never UUID(): hr_event person_id|n|seq, hr_run_log run_id|seq"
  use_cases:
    commands:
      - record_hire
      - record_leave
      - record_transfer
      - record_pay_change
      - record_contract_extension
      - record_rehire
      - record_conversion
      - correct_slice
      - move_event_date
      - submit_intake
      - reissue_intake_link
      - complete_step
      - approve_step
      - approve_draft
      - assign_run_party
      - retry_step
      - cancel_run
      - file_document
      - record_compliance
      - invite_to_sign_in
      - keep_org
      - keep_configuration
      - keep_playbook
      - change_playbook
      - record_sensitive
      - produce_payroll_extract
      - mark_extract_sent
      - record_privacy_request
      - run_due_steps
      - set_demo_clock
    queries:
      - my_hr_tasks
      - run_board
      - show_run
      - preview_run
      - show_person
      - show_sensitive
      - list_documents
      - read_action_log
      - headcount
      - starters_and_leavers
      - org_chart
      - export_subject_access
      - show_my_record
      - show_playbook_bpmn
      - playbook_deviations
      - scenario_paths
      - onboarding_monitor
domain_model:
  ubiquitous_language:
    person: a natural person we employ or engage. One per human, however many times they come back. Key person_id.
    engagement: one period of working for us under one worker type (employee, freelancer, contractor, intern). A rehire is a new engagement; so is a conversion.
    worker_type: "what the engagement is (a row): employee full-time, freelancer (sole trader), freelancer (via a company)… It decides the playbook, whether payroll applies, and the business-partner roles."
    assignment: "where an engagement sits on a date: org unit, job, optional position, location, work schedule, FTE, cost centre ref. Sliced."
    org_unit: a team or department in the org tree. Sliced, so a reorganisation is dated.
    position: one seat in an org unit that describes a job. It can be vacant. Optional, except the chief position.
    chief_position: the position that manages an org unit. Its holder is the manager of everyone assigned to the unit, and of units below it that have no chief of their own.
    manager: "DERIVED: the holder of the chief position of the assignment's org unit, walking up the tree. Never stored. A manager override on the assignment is the rare exception."
    job: a catalogue entry (Motion Designer). A position describes one; an assignment names one.
    slice: one dated version of a record, valid_from to valid_to (open = 9999-12-31).
    delimit: to end the previous slice the day before a new one starts (valid_to = new valid_from − 1). Nothing is overwritten.
    correction: a new slice with the SAME valid_from that supersedes the old one (superseded_by). We keep what we believed before.
    personnel_event: "something that happened to an engagement on an effective date: Hired, Transferred, PayChanged, ContractExtended, Left, Rehired, Converted. It writes slices and may start a run."
    reason: "why a personnel event happened (a row per event type: resignation, end of project…)."
    infogroup: the list of records one event type captures (a row set). The event wizard is generated from it.
    playbook: the customer's checklist for one kind of run (worker type × event type × reason × org unit), versioned.
    run: a playbook expanded for one person and one personnel event. Its id is derived, so a double click is one run.
    step: "one item of a run, of a kind: task | action | document | draft | intake | approval."
    responsible_group: "WHO a step goes to: manager, IT, finance, buddy, HR, the starter. Not a named person; resolved when the step falls due."
    capability: a named thing a provider brick can do in the outside world (identity.provision_user). hr asks for capabilities, never vendors.
    manual_task: "the first-class path when no provider is wired: a task carrying the capability, the exact validated input and the plan in words."
    sensitive_data: NI/tax id, bank, home address, date of birth, emergency contact, right-to-work evidence. Its own aggregate, HR and finance only.
    localisation_pack: a country's legal fields, document types, steps and checks (UK first), swappable per country.
  bounded_context:
    inside: people, engagements, org structure (units, positions, jobs, locations, schedules), pay RATES (not payroll), personnel events, onboarding/offboarding/change/conversion runs and their steps, the starter intake, documents on a person, sensitive data, retention, headcount reporting
    outside: payroll calculation (tax, NI, pensions, RTI), contract wording and signing (contracts), the party record itself (business-partner), the vendor's systems (provider bricks), sign-in (the pool), time and absence (future bricks), cost centres (finance)
  context_map:
    - neighbour: business-partner
      relationship: "hr is UPSTREAM for person fields: hr is the single writer of a person's partner (name, work contact, roles) through a PUBLISHED write path (bp:person:sync). bp is the shared record everyone reads."
    - neighbour: contracts
      relationship: "customer/supplier: hr is the customer and asks through the contracts.* capabilities (to be added to capabilities.yaml). contracts never reads hr; hr passes the counterparty bp_id, the context ref and the variables."
    - neighbour: connector providers (google-workspace first; none in the first demo)
      relationship: "an ANTI-CORRUPTION LAYER: hr speaks capabilities (capabilities.yaml 0.3) through the CapabilitySeam, never vendor terms. No provider means the manual task path."
    - neighbour: the payroll provider (outside the platform)
      relationship: "an ANTI-CORRUPTION LAYER through the period extract: hr publishes rates, slices and proration dates per legal entity; it never models tax or payslips."
    - neighbour: the identity pool (dodil-appid)
      relationship: "conformist: hr stores pool_user_sub when a person is invited, and resolves callers through it. It never verifies tokens (the gateway does)."
    - neighbour: Models (api.dodil.io, OpenAI-compatible)
      relationship: a small adapter for draft steps, under the billed ignite.model-user role, granted deliberately. It is given no sensitive field.
  aggregates:
    - name: Person
      root: hr_person (person_id)
      parts:
        - hr_person_detail
        - hr_engagement
        - hr_assignment
        - hr_pay
        - hr_pay_component
        - hr_event
        - hr_document
        - hr_compliance_record
      invariants:
        - "TC1: hr_person_detail has exactly one slice on every date from the person's first; no gap, no overlap"
        - "TC1 per engagement: hr_assignment covers the engagement from its start date to its end, no gaps, no overlaps"
        - "TC1 per engagement from the FIRST pay slice: once pay is recorded it has no gaps or overlaps to the engagement's end (a hire may be registered before pay is known; the playbook's 'record pay' task closes that)"
        - at most ONE active engagement at a time in v1 (concurrent employment is an extension point; the model already allows n)
        - personnel events are append-only, and each one writes at least one slice in the same transaction
        - a freelancer engagement via a company names a supplier_bp_id; an employee engagement never does
        - a correction keeps the old slice (superseded_by) and is itself a slice, so 'what we believed on date X' is answerable
        - a manager override names a person assigned within the SAME org (org_id) as the assignment; across org trees it is refused in v1
      enforced_in: domain (Person.apply(event) and the slice rules), never the database
    - name: Org
      root: "hr_org (org_id): one per org tree"
      parts:
        - hr_org_unit
        - hr_position
      invariants:
        - the unit tree is acyclic on every date
        - a unit has at most one chief position at a time
        - every unit and position is TC1 over its own lifetime
        - a position moving units is a new slice, not a new key (keys are org_id|position_id|valid_from)
      enforced_in: domain
    - name: Sensitive
      root: "hr_sensitive (person_id PK, version): a thin root row, so it is a proper Aggregate with its own version for concurrency"
      parts:
        - hr_sensitive
        - hr_person_sensitive
      invariants:
        - "a separate root: no manager-facing use case loads it, and the Person repository never joins it"
        - read and written only through use cases requiring hr:sensitive:read / hr:sensitive:write
      enforced_in: application (permission) + repository (no join path) + an access test on every route
    - name: Configuration
      root: one small aggregate per catalogue, rooted at its natural key (job_code, location_code, schedule_code, event_type, …)
      invariants:
        - an event reason belongs to exactly one event type; an infogroup names only records the event's kind can write
        - a pay component is valid for the worker types it names
      enforced_in: domain
    - name: Playbook
      root: hr_playbook (playbook_id|version)
      parts:
        - hr_playbook_step
      invariants:
        - an active version is immutable once a run has used it; a change is a new version
        - a destructive capability step depends on an approval step
        - identity.delete_user depends on a drive.transfer_ownership step in the same playbook (the engine then waits on drive.transfer_status = completed)
        - depends_on forms no cycle; step:<n>.done anchors name an existing step
      enforced_in: domain (refused on save, 409, in words)
    - name: Run
      root: hr_run (run_id)
      parts:
        - hr_run_step
        - hr_run_party
        - hr_run_log
      invariants:
        - "the playbook version is frozen at expansion: later playbook edits never change an open run"
        - a destructive step never fires without a granted approval
        - a done step is never re-timed and never acts again
        - each action/document step carries idempotency_key = <run_id>|<step_no>
      enforced_in: domain
    - name: Intake
      root: hr_intake (intake_id = <person_id>|<n>)
      invariants:
        - one open link at a time; reissuing revokes the previous one (through the door)
    - name: PayrollExtract
      root: hr_payroll_batch (batch_id = <legal_entity_ref>|<period>)
      parts:
        - hr_payroll_line
      invariants:
        - a sent batch is frozen; a later change to a sent period goes into the next open batch as a retro line, so a row goes out exactly once
    - name: PrivacyRequest
      root: hr_privacy_request (request_id)
      parts:
        - hr_retention_log
  transactions: "One aggregate per transaction. Cross-aggregate consistency is EVENTUAL: a personnel event commits on the Person, and the run engine (run_due_steps) then expands the run, syncs the business partner and calls capabilities, each step idempotent on its own key. A step that reads what an earlier transaction wrote re-reads after commit (no read-your-writes inside an open transaction)."
  value_objects:
    EffectivePeriod: valid_from / valid_to (9999-12-31 = open). delimit(new_from) → valid_to = new_from − 1 day; covers(date); overlaps(other)
    PersonKey: the customer's staff number ('staff:<no>'), else 'email:<lower(trim(personal_email))>'. Fixed at creation, never re-keyed
    PersonId: "int.from_bytes(blake2b(person_key, digest_size=7)): a 56-bit BIGINT, like bp_id"
    EngagementRef: person_id|n
    RunId: <direction>:<person_id>:<n>:<event seq>
    Rate: amount NUMERIC(19,4) + basis (hour | day | month | year | fixed) + currency (ISO 4217). Never converted between bases at write time
    Minutes: an integer count of minutes (time is never a float)
    Days: NUMERIC(5,2)
    PayableAmount: rate × quantity (minutes/60 or days) in exact decimal, rounded ONCE at the payable line to the currency's minor unit with the configured rounding mode
    TimingRule: anchor (start_date | last_day | event_date | step:<n>.done | run.created) + offset (signed integer) in calendar_days or working_days + time of day + the org's timezone (IANA, a row)
    CapabilityCall: capability name + validated input + idempotency_key + dry_run. The result is done | planned | in_progress | connection_required | failed (capabilities.yaml 0.3)
    ResponsibleGroup: a group code resolved on the due date (derived manager, a pool role, or a run party)
  domain_events:
    Hired: a new engagement starts (first ever, for a new person). Writes engagement, first assignment, optional pay, detail when new. Starts an onboarding run
    Transferred: a new assignment slice (unit, job, position, location, schedule). Starts a change run (the access delta)
    PayChanged: a new pay or component slice; reason required. No run (it appears in the payroll extract)
    ContractExtended: planned_end moves. Re-times the offboarding run's undone steps if one exists
    Left: actual_end set; assignment and pay delimited at last day + 1. Starts an offboarding run, unless the reason is 'converted'
    Rehired: a NEW engagement n+1 for an existing person; history kept. Starts an onboarding run (rehire playbook). NEVER starts an offboarding run
    Converted: Left (reason converted) on n plus a new engagement n+1 on the same date, as ONE event. Starts one conversion run; access is kept
  domain_services:
    ManagerOf: "(person, date) → the derived manager: the assignment's org unit chief, walking up; the override wins when set"
    FteOf: (assignment, date) → schedule hours ÷ the schedule's full-time base × the assignment's employment %
    RunExpansion: (personnel event, playbook version, person, org) → a Run with steps whose due_at comes from each TimingRule; a capability with no provider becomes a manual task here (rule 8)
    Retimer: (run, changed anchor) → new due_at for every step not done; done steps untouched
    Headcount: (date or period, grouping) → headcount, FTE, starters, leavers, derived from slices
    WorkingDayCalendar: (location, date) → working day or not, from the work schedule and the public-holiday calendar rows; handed to the tracked-work library as its WorkCalendar
  policies:
    - event types (each mapped to one domain event kind), reasons and infogroups
    - "playbook selection: worker type × event type × reason × org unit (most specific wins; a tie is refused on save)"
    - "step conditions: a named specification from a fixed set in code (worker_type_is, via_company, rate_outside_band, pack_requires) chosen by a row"
    - chasing cadence (the tracked-work library), the max attempts before an action step goes to IT
    - the rounding mode at the payable line (default half-up)
    - the retention schedule per data category
    - which document types are personnel, pay-bearing or sensitive
  factories:
    PersonFactory: "from a Hired event: Person + detail slice + engagement 1 + first assignment (+ pay), person_id derived from PersonKey. A second submit finds the same person_id and the same engagement, so it is a no-op"
    RunFactory: from a committed personnel event + the selected playbook version → Run (RunExpansion)
  repositories: One per aggregate (PersonRepository, OrgRepository, SensitiveRepository, ConfigurationRepository, PlaybookRepository, RunRepository, IntakeRepository, PayrollExtractRepository, PrivacyRepository), each an erp_platform.repository Aggregate of Parts whose keys all start with the root key. Each one loads the whole aggregate, with no lazy loading. Nothing loads two aggregates in one unit of work.
actors:
  - id: hr_admin
    name: Operations / HR
    does: runs every starter and leaver, keeps the org, playbooks and catalogues, handles personal data and privacy requests
    sees: everything, including sensitive data
    permissions:
      - hr:person:read
      - hr:person:write
      - hr:hire:record
      - hr:leave:record
      - hr:event:record
      - hr:pay:read
      - hr:pay:write
      - hr:sensitive:read
      - hr:sensitive:write
      - hr:document:read
      - hr:document:write
      - hr:org:read
      - hr:org:write
      - hr:run:read
      - hr:run:preview
      - hr:run:reschedule
      - hr:run:cancel
      - hr:task:read
      - hr:task:complete
      - hr:step:approve
      - hr:draft:approve
      - hr:action:retry
      - hr:action_log:read
      - hr:config:write
      - hr:offboarding:policy
      - hr:report:read
      - hr:run:monitor
      - hr:privacy:manage
      - hr:pool:invite
      - hr:clock:set
  - id: manager
    name: Hiring manager / team lead
    does: asks for a starter, approves the welcome email, records a leaver, takes over their work, moves a start or last day
    sees: the people in their line (derived from the org tree) and their runs and pay, never sensitive data
    permissions:
      - hr:person:read
      - hr:hire:record
      - hr:leave:record
      - hr:event:record
      - hr:pay:read
      - hr:document:read
      - hr:org:read
      - hr:run:read
      - hr:run:preview
      - hr:run:reschedule
      - hr:task:read
      - hr:task:complete
      - hr:draft:approve
      - hr:report:read
      - hr:run:monitor
  - id: it
    name: IT / ops
    does: does the account and access steps by hand until a connector is wired, approves account deletion, retries failed actions
    sees: people with an open IT step, and the runs and action log for them, never sensitive data or pay
    permissions:
      - hr:person:read
      - hr:run:read
      - hr:task:read
      - hr:task:complete
      - hr:step:approve
      - hr:action:retry
      - hr:action_log:read
  - id: finance
    name: Finance
    does: payroll hand-off for employees, supplier set-up for freelancers, bank and tax details
    sees: every person, their pay and their sensitive data
    permissions:
      - hr:person:read
      - hr:pay:read
      - hr:pay:write
      - hr:sensitive:read
      - hr:sensitive:write
      - hr:task:read
      - hr:task:complete
      - hr:report:read
  - id: assignee
    name: Anyone a step is assigned to (a buddy, a takeover, a director)
    does: sees and completes the steps of the responsible groups they belong to
    sees: only their own steps, and the person's name and start date on them
    permissions:
      - hr:task:read
      - hr:task:complete
  - id: employee
    name: The person themselves, once they can sign in
    does: sees their own record, their own engagement and documents, and their first-week plan
    sees: only themselves, and not their own sensitive data (that goes through HR, customer_varies)
    permissions:
      - hr:self:read
  - id: starter
    name: The starter, before they have a sign-in
    does: fills in their own details and uploads right-to-work evidence through a link
    sees: one intake form, bound to their engagement, through the public-link door. It never echoes back stored sensitive values
    permissions: []
  - id: clock
    name: The clock (a service client, or the always-on worker)
    does: calls run_due_steps(now). ONE clock worker (the clock service client) calls every brick's tick route, listed in the composition
    sees: nothing through people's doors; the tick runs as the brick's service identity
    permissions:
      - hr:run:tick
  - id: expenses_client
    name: Expenses (a service client)
    does: asks who a person is on a date, their employment and their derived manager, to fix an approval chain
    sees: the employment slice and the derived manager on a date; no pay, no sensitive data
    permissions:
      - hr:employment:read
      - hr:manager:read
      - hr:assignment:read
      - hr:roster:read
  - id: pos_client
    name: Point of sale (a service client)
    does: asks whether a person is employed on a date (staff discount, till login)
    sees: the employment slice on a date; no pay, no sensitive data
    permissions:
      - hr:employment:read
  - id: time_off_client
    name: Time off (a service client, v3)
    does: asks whether a person is employed, their work pattern and holidays, and their derived manager, to cost and route a request
    sees: the employment slice, the work pattern and the derived manager; no pay, no sensitive data
    permissions:
      - hr:employment:read
      - hr:manager:read
      - hr:work_pattern:read
      - hr:assignment:read
      - hr:roster:read
  - id: timesheets_client
    name: Timesheets (a service client, v3)
    does: asks a person's employment, expected hours and manager, to build and route a week
    sees: the employment slice, the work pattern and the derived manager; no pay, no sensitive data
    permissions:
      - hr:employment:read
      - hr:manager:read
      - hr:work_pattern:read
      - hr:assignment:read
      - hr:roster:read
  - id: payroll_client
    name: Payroll (a service client, v3)
    does: produces and reads the payroll extract, marks it sent when a run is approved, reads the identity HMRC needs and the work pattern for proration
    sees: the extract, the employment slice, the work pattern and the payroll identity (audited); never bank details
    permissions:
      - hr:employment:read
      - hr:work_pattern:read
      - hr:payroll_extract:read
      - hr:payroll_extract:mark_sent
      - hr:payroll_identity:read
      - hr:assignment:read
      - hr:roster:read
  - id: payments_client
    name: Payments (a service client)
    does: reads one person's bank account on the payment date to pay an approved expense report
    sees: one bank slice of person_sensitive per call, every read audited; nothing else of the sensitive aggregate
    permissions:
      - hr:bank_account:read_for_payout
  - id: system
    name: The system
    does: expands runs, times steps, calls capabilities, syncs the business partner, drafts, chases, applies retention
    sees: everything, through its own service account
    permissions: []
stories:
  - id: HR-01
    kind: person
    actor: manager
    story: As a manager, I want to ask for a starter with one form, so that the onboarding starts without me chasing HR.
    given: "the form: legal name, preferred name, personal email, worker type (employee / freelancer sole trader / freelancer via a company / intern…), job, org unit, start date, and for a freelancer a day rate or a fixed fee (and the company, when via a company)"
    when: I submit it (record_hire, a Hired event)
    then: there is one person (person_id derived from the staff number, or from the normalised personal email) with its business partner created AT HIRE (kind person, name and work contact only, HR-50), one engagement, one assignment slice from the start date, a pay slice if a rate was given, and one onboarding run from the playbook for that worker type × event type × org unit, which Operations sees. Submitting twice gives the same person, engagement and run. A start date in the past beyond the setting is refused ("start dates more than 30 days back are corrections, ask HR"). A second open engagement for the same person is refused, naming the one that is open. A company freelancer with no company is refused.
    screen: New starter
    reference: not built
  - id: HR-02
    kind: person
    actor: starter
    story: As a starter, I want to fill in my own details from a link, so that nobody re-types my bank details from an email.
    given: an intake link sent to my personal email, valid for the configured days, asking for the fields for my worker type and country
    when: I fill in address, emergency contact, bank details (employee) or company and VAT details (freelancer), NI number, and upload my right-to-work document
    then: 'the values go to the Sensitive aggregate and the upload to a DataK3 object filed as a sensitive document; the form shows which fields are still missing and never shows a stored sensitive value back; the link works for this engagement only, expires, can be reissued (the old one stops working), and every use is audited by the door. The manager sees "details: 5 of 6 done", never the values.'
    screen: Your details
    reference: not built
  - id: HR-03
    kind: person
    actor: assignee
    story: As anyone with steps to do (IT, finance, a buddy, a manager), I want my steps as overdue, today and this week, so that I start the day knowing what is late.
    given: steps assigned to the responsible groups I belong to
    when: I open My tasks and complete one
    then: I see counts and lists by overdue / today / this week (derived on read through the tracked-work library); completing a step records who and when and makes the steps that depend on it due; a step of another group is not found. A manual task (an action with no provider) shows the capability, the exact input and the plan in words, and asks for the provider_ref (optional) when I mark it done.
    screen: My tasks
    reference: not built
  - id: HR-04
    kind: person
    actor: hr_admin
    story: As Operations, I want one view of every run, so that I see what is done, what is stuck and who it is waiting on.
    given: runs at different stages
    when: I open the run board
    then: each run shows the person, direction, start or last day, steps done of total, the next due step, "waiting on <group>" and what is stuck (overdue, failed, waiting for approval or signature), all derived on read; filters by direction, org unit, worker type
    screen: Runs
    reference: not built
  - id: HR-05
    kind: person
    actor: manager
    story: As a manager, I want an AI-drafted welcome email I can edit and approve, so that the starter gets a warm, specific welcome without me writing it from scratch.
    given: a draft step whose draft was made from the job, org unit, buddy (a run party), start date and first project brief (no sensitive field)
    when: I edit and approve it (approve_draft)
    then: the approved text becomes the input of the dependent mail.send step (from my work mailbox, to the starter's personal email). With no mail provider, that step is a manual task carrying the exact message, and I copy and send it and mark it sent. A failed draft is a manual task "write the welcome email" and never blocks the run.
    screen: Run
    reference: not built
  - id: HR-06
    kind: person
    actor: manager
    story: As a manager, I want to record a leaver with their last day and reason, so that offboarding is planned backwards from that day.
    given: a person with an active engagement in my line
    when: I record the leave (record_leave, a Left event) with last day and a reason from the list
    then: actual_end is set, the assignment and pay are delimited at last day + 1, and one offboarding run starts from the playbook for that worker type × reason (a freelancer's has no payroll steps). A draft step produces the handover list from what hr knows they look after (their open steps, people in their line via a chief position, org units they lead, the groups and spaces of their unit), and I edit it. Each item becomes a task for the takeover group (a run party I name). With the UK pack, a last day giving less than the statutory minimum notice is warned, not refused (the contract may say more, and the employee may waive).
    screen: Record a leaver
    reference: not built
  - id: HR-07
    kind: person
    actor: it
    story: As the approver for a destructive step, I want to approve or refuse it explicitly, so that an account is never deleted by a timer.
    given: an identity.delete_user step due at last_day + 30 days behind an approval step
    when: I approve it (approve_step), or refuse it with a reason
    then: "approved: the delete step runs when due, and only after drive.transfer_status says completed; refused: the delete step is cancelled with my reason; nobody without hr:step:approve can approve; the approval is in the run log with who and when"
    screen: Run
    reference: not built
  - id: HR-08
    kind: person
    actor: manager
    story: As a manager, I want to move a start date or a last day, so that the plan follows reality without rebuilding it.
    given: an onboarding run with 3 steps done and 9 not done, start date Monday 3rd
    when: I move the start date to Monday 10th (move_event_date)
    then: the 9 not-done steps get a new due_at from their timing rules (working days and the org's timezone respected); the 3 done steps keep their due_at and result; the run log says who moved it, from what to what, and when; the engagement and the assignment slice move with it. A contract extension (ContractExtended) re-times an open offboarding run the same way.
    screen: Run
    reference: not built
  - id: HR-09
    kind: person
    actor: it
    story: As IT, I want to read every action's request, result and actor, so that I can answer "what did the system do to this account".
    given: action steps that ran automatically, failed, or were done by hand as manual tasks
    when: I open the action log for a person or a run
    then: each attempt shows the capability, the input (secrets redacted), the result status, the provider_ref, the message, who or what acted and when. The automatic attempts come from the provider's log (capabilities rule 5) through the seam. Manual ones come from hr's own step record. Another person's log, for someone with no IT step, is not found.
    screen: Action log
    reference: not built
  - id: HR-10
    kind: person
    actor: hr_admin
    story: As Operations, I want to preview a run before it fires, so that I see every step, its date and every payload before going live.
    given: a hire about to be recorded, or an existing run
    when: I preview it (preview_run, dry_run=true)
    then: "I get every step with its computed due_at, responsible group, and for each action the exact capability input and the provider's plan (or \"manual: no provider\" and the plan in words). Nothing is written, claimed or sent. A go-live shadow is a dry run beside one real starter."
    screen: Run
    reference: not built
  - id: HR-11
    kind: person
    actor: hr_admin
    story: As Operations, I want to keep our checklists as playbooks, so that a new step never needs a developer.
    given: the employee onboarding playbook, version 3, used by two open runs
    when: I add a step "buddy coffee, start_date +1 working day 10:00, group buddy" and save
    then: version 4 is created and new runs use it; the two open runs keep version 3. Saving a destructive action with no approval before it is refused in words. So is a delete with no transfer before it, or a dependency cycle.
    screen: Playbooks
    reference: not built
  - id: HR-12
    kind: person
    actor: hr_admin
    story: As Operations, I want to keep the org (units, chief positions, jobs, locations, schedules, and which groups and spaces each unit has), so that managers, access and reports follow it.
    given: Studio under Operations, with a chief position held by the Studio lead
    when: I move Studio under Campaigns from the 1st of next month
    then: a new Studio slice from that date delimits the old one; until then the old tree is current; the derived manager changes on that date for everyone in Studio without touching their records; a move that would make a cycle is refused; a second chief for one unit on one date is refused
    screen: Org
    reference: not built
  - id: HR-13
    kind: person
    actor: finance
    story: As finance or HR, I want to read and correct a person's sensitive data, so that pay goes to the right account and nobody else sees it.
    given: a person whose bank details were entered at intake
    when: I open their sensitive data, and correct the sort code
    then: I see the current values per kind; the correction is a new slice (valid_from today, or a correction of the same date) and the old one is kept; a manager or IT user asking for the same route gets 404 (the route exists, the record does not, for them), through the API and through MCP alike
    screen: Sensitive data
    reference: not built
  - id: HR-14
    kind: person
    actor: hr_admin
    story: As HR, I want to record pay and pay components with effective dates, so that a raise next month is entered today and history is never overwritten.
    given: a salaried employee on 42,000.0000 GBP per year since 1 March
    when: I record a PayChanged event with reason "annual review", 45,000.0000 from 1 April
    then: a pay slice from 1 April delimits the March slice at 31 March; the reason is required; a component (car allowance) is its own sliced row; a rate basis of hour/day/month/year/fixed comes from the rows and is never converted at write time; no derived hourly rate is stored for a salaried person
    screen: Person
    reference: not built
  - id: HR-15
    kind: person
    actor: hr_admin
    story: As HR, I want to rehire someone who has worked here before, so that their history is kept and offboarding never fires by mistake.
    given: a freelancer whose engagement 1 ended last year
    when: I record a Rehired event
    then: the same person gets engagement 2; one onboarding run from the rehire playbook starts; no offboarding run is created by anything in the rehire; their old engagement, documents and events stay readable
    screen: Person
    reference: not built
  - id: HR-16
    kind: person
    actor: hr_admin
    story: As HR, I want to convert a freelancer to an employee in one step, so that they don't lose access between two contracts.
    given: a freelancer on engagement 1 with an account and team access
    when: I record a Converted event effective 1 December
    then: engagement 1 ends 30 November (reason converted), engagement 2 (employee) starts 1 December, as one event in one transaction; ONE conversion run starts (employment contract, payroll set-up, business-partner roles worker → employee, and supplier removed when they were a sole trader); no offboarding or access-removal step runs
    screen: Person
    reference: not built
  - id: HR-17
    kind: person
    actor: manager
    story: As a manager, I want to record a transfer to another team or job, so that their access changes on the day and the history shows both.
    given: a Designer in Studio
    when: I record a Transferred event to Campaigns, Campaign Producer, from the 15th
    then: a new assignment slice from the 15th delimits the Studio one; a change run is created with the access delta from the unit access rows (add the new unit's groups and spaces, remove the old ones) timed on the event date; a transfer into a unit outside my line is refused unless I hold the destination's chief position too
    screen: Person
    reference: not built
  - id: HR-18
    kind: person
    actor: hr_admin
    story: As Operations, I want starters, leavers, headcount and FTE by team and worker type over time, so that I can answer "how many people do we have" for any date.
    given: slices covering this year
    when: I open the report for this month, by org unit and worker type
    then: starters (engagements starting in the period), leavers (actual_end in the period), headcount and FTE at the period end, all derived from slices on read (no snapshot table); a past month gives the answer as the org was then, not as it is now; a manager sees their own line only
    screen: Reports
    reference: not built
  - id: HR-19
    kind: person
    actor: finance
    story: As finance, I want a payroll extract per legal entity and period, so that the payroll provider gets every change once and I re-key nothing.
    given: November, with two starters, one leaver, a pay change and a bank change at the legal entity GH-UK
    when: I produce the extract and mark it sent
    then: the batch lists every pay and component slice touching the period with its proration dates, starters and leavers, and bank changes; freelancer engagements (paid as suppliers) are never in it; once sent the batch is frozen, and a later change to November lands in the next open batch as a retro line, so no row goes out twice
    screen: Payroll extract
    reference: not built
  - id: HR-20
    kind: person
    actor: hr_admin
    story: As HR, I want documents filed on the person with a type, an expiry and an access class, so that the right-to-work copy and the signed contract are where they belong.
    given: a right-to-work document uploaded at intake, and a signed employment contract from contracts
    when: I open the person's documents
    then: the contract is a pay-bearing document (readable with hr:pay:read); the right-to-work copy is sensitive (filed in the Sensitive aggregate, readable with hr:sensitive:read only); downloads are streamed by the use case, never an object link; each has its DataK3 object key, sha256, uploaded by and when, and an expiry where the type has one. A time-limited right to work expiring within the configured days shows on the board and creates a follow-up check step (the UK pack).
    screen: Person
    reference: not built
  - id: HR-21
    kind: person
    actor: hr_admin
    story: As HR, I want to produce everything we hold on a person, so that a subject-access request is answered on time.
    given: a subject-access request from a former freelancer, recorded with its received date
    when: I export it (export_subject_access)
    then: one archive (a DataK3 object) with the person, every slice including superseded ones, events, documents, sensitive data, run steps naming them, and their business-partner fields. The request shows its due date (one month from receipt, UK GDPR Art. 12(3)), and the export is logged with who and when.
    screen: Privacy
    reference: not built
  - id: HR-22
    kind: person
    actor: hr_admin
    story: As HR, I want to handle an erasure request, so that we delete what we may and can say why we keep the rest.
    given: an erasure request from a leaver of three years ago
    when: I apply it
    then: each data category is erased or anonymised unless a retention rule with a legal-obligation basis still holds it, in which case it is kept and the reason is recorded; the business partner's person fields are anonymised through the bp seam; everything done is in the retention log
    screen: Privacy
    reference: not built
  - id: HR-23
    kind: person
    actor: hr_admin
    story: As HR, I want to cancel a run when a starter withdraws, so that nothing more fires and what already happened is undone deliberately.
    given: an onboarding run where the account was created and a group added
    when: I cancel it with a reason
    then: every not-done step is cancelled; for each done action a reversal task is created (suspend the account, remove from the group), named after the capability. Nothing is reversed silently. The cancellation is in the run log.
    screen: Run
    reference: not built
  - id: HR-24
    kind: person
    actor: employee
    story: As an employee, I want to see my own record and my first week, so that I know what is planned and what HR holds.
    given: I have signed in (pool_user_sub on my person)
    when: I open My record
    then: I see my person detail, engagement, assignment, documents of the personnel class and my first-week steps; anybody else's record is not found
    screen: My record
    reference: not built
  - id: HR-25
    kind: person
    actor: hr_admin
    story: As HR, I want to invite a person to sign in, so that they can see their record and their tasks.
    given: a person with a work email and no pool_user_sub
    when: I invite them (invite_to_sign_in)
    then: "an action step calls the capability identity.invite_app_user (proposed; a future appid provider brick provides it) with the work email and the pool; its output sub is stored on hr_person.pool_user_sub; inviting twice reuses the same user (idempotency_key invite:<person_id>). With no provider it is a manual task (rule 8): an admin creates the pool user with the exact input shown and records the sub on completion. Until then they are a person with no login, which is normal."
    screen: Person
    reference: not built — identity.invite_app_user is proposed, not yet in capabilities.yaml
  - id: HR-26
    kind: person
    actor: hr_admin
    story: As HR, I want to record the right-to-work check with its evidence, so that we can show the check was done before day one.
    given: an employee starting Monday with right-to-work evidence uploaded at intake (UK pack)
    when: I record the check, giving its type (manual document check, check via an identity service provider, or Home Office online check), the date, who did it and any follow-up date
    then: a compliance record on the engagement points at the sensitive evidence; the playbook's "right to work checked" gate before day-one steps is met. A start date before the check date is flagged. The record says what was done, and the module makes no legal judgement.
    screen: Person
    reference: not built
  - id: HR-27
    kind: person
    actor: hr_admin
    story: As HR, I want to record the IR35 status determination for a freelancer, so that the contract cannot go out before it is decided.
    given: a freelancer via a limited company, at a client the customer has set as medium or large (UK pack)
    when: I record the determination (inside or outside, the reasons, the date, given to the worker and to whoever we contract with)
    then: a compliance record exists, and the contract step's condition is met. Without it the contract step stays blocked with "record the status determination first". The module records the determination and does not make it.
    screen: Person
    reference: not built
  - id: HR-28
    kind: person
    actor: hr_admin
    story: As Operations, I want to keep the catalogues (worker types, event types and reasons, infogroups, jobs, rate bases, pay components, document types, retention rules, settings), so that our vocabulary is ours and not the software's.
    given: the default catalogues from the UK pack
    when: I add a leave reason "end of project" to Left, and a worker type "intern"
    then: new events and hires can use them at once; a reason in use cannot be deleted, only retired; a worker type must say whether payroll applies and which business-partner roles it gives
    screen: Settings
    reference: not built
  - id: HR-29
    kind: person
    actor: hr_admin
    story: As Operations, I want to see how our onboarding is actually going — how long runs take, where steps go late and how soon a starter can work — so that I fix the programme, not just the run in front of me.
    given: onboarding runs over time, some done and some open, from one or more versions of the playbooks
    when: I open the onboarding monitor (onboarding_monitor, GET /reports/onboarding), optionally from a date
    then: "I see the run lead time (median and longest, in days, from the run's creation to its last step done) and the age of the runs still open; the steps overdue now, counted by owner group and by team (the person's org unit); the days from the start date to the first access granted (an account made, a group or chat space joined; negative is before day one, which is the aim); and, per playbook version the runs used, how many runs used it and its deviations from the pack's standard by class. Every number is derived from the runs on read, nothing stored; every date is the business date in business_timezone. A manager sees the same numbers over the runs of their own line (the run board's rows). APQC 7.3.1.3 Monitor and update employee onboarding program (11243): monitor here, update through versioned playbooks (HR-11) and playbook_deviations."
    screen: Reports
    reference: "brick-hr 0.6 (unreleased): domain/monitoring.py, application/reports.onboarding_monitor; tests test_hr_29_*"
  - id: HR-30
    kind: system
    actor: system
    trigger: run_due_steps(now), called by the clock every minute or so
    story: The system moves every run on. Steps that are due and whose dependencies are done get done, so nothing depends on someone remembering.
    given: steps with due_at ≤ now, their depends_on done, state pending
    when: the tick runs
    then: "each step is executed by kind (task: shown as due; action/document: a CapabilitySeam call with idempotency_key <run_id>|<step_no>; draft: the Models adapter; intake: the door issues the link; approval: waits for a person); a step claimed by a concurrent tick is skipped; running the tick twice acts once per step. It also applies due future-dated changes (HR-38) and chases (HR-36)."
    reference: not built
  - id: HR-31
    kind: system
    actor: system
    trigger: at the account step's timing (typically start_date −3 working days 09:00, org timezone)
    story: The system sets the starter up in our tools (work account, team groups, chat spaces, shared folders), and does it automatically once a provider is wired.
    given: an onboarding run past its contract-signed gate, the org unit's access rows (groups, spaces, folders)
    when: the steps fall due
    then: 'identity.provision_user, then one groups.add_member / chat.add_to_space / drive.create_folder step per access row; with a provider: done, and the work email is written back as a new person-detail slice and synced to the business partner. With no provider: each is a manual task with the exact input ("create anna.berg@… in OU /Staff/London") and the plan in words, and marking it done with the created address writes it back the same way. Wiring a provider later changes no playbook.'
    reference: not built
  - id: HR-32
    kind: system
    actor: system
    trigger: at each calendar step's timing
    story: The system puts the first week in the calendar (day-one welcome, IT set-up, buddy coffee, week-one review).
    given: playbook calendar steps with titles, times (working-day offsets from start_date) and attendee groups
    when: they fall due
    then: calendar.create_event with the times resolved in the org's timezone; with no provider, a manual task with the times and attendees filled in
    reference: not built
  - id: HR-33
    kind: system
    actor: system
    trigger: when a draft step falls due, or when a manager asks for it early
    story: The system drafts the welcome email, the handover list and the leaver letter with AI, so that the manager edits rather than writes.
    given: a draft step with its draft instructions row and the allowed fields (job, unit, buddy, dates, first project; never a sensitive field)
    when: it runs
    then: a chat completion at https://api.dodil.io/v1 with the brick's service-account token (ignite.model-user) produces the draft, stored on the step, waiting for approval by its group; the model name is a settings row; on any failure or timeout the step becomes a manual task "write it by hand" and the run goes on; running it twice keeps the first draft unless the approver asks for a new one
    reference: not built
  - id: HR-34
    kind: system
    actor: system
    trigger: at last_day 17:30 (org timezone), or at the event date for a reason the playbook treats as immediate
    story: The system removes access at the right time.
    given: an offboarding run
    when: the removal steps fall due
    then: identity.suspend_user, drive.transfer_ownership to the derived manager on the last day, mail.set_autoreply, groups.remove_member and chat.remove_from_space per access row; with no provider each is a manual task due at exactly that time, which the board shows as a countdown
    reference: not built
  - id: HR-35
    kind: system
    actor: system
    trigger: at last_day +30 days 09:00, after its approval
    story: The system deletes the account and frees the licence only when it is safe.
    given: an approved identity.delete_user step and a drive.transfer_ownership step done earlier
    when: it falls due
    then: it first asks drive.transfer_status; if not completed the step stays waiting (in_progress) and is asked again on the next tick; then identity.delete_user; without an approval it never runs; with no provider it is a manual task
    reference: not built
  - id: HR-36
    kind: system
    actor: system
    trigger: on every tick
    story: The system handles every outcome of an action, so that a failure becomes work for a person instead of a silent gap.
    given: action steps with results
    when: the result is in_progress / failed retryable / failed not retryable / connection_required, or the capability has no provider
    then: "in_progress: asked again next tick, not counted as a failure; failed retryable: retried with backoff and after N attempts (a row) a manual task for IT with the provider's message in words; failed not retryable or connection_required: a manual task at once, naming what is missing; no provider: a manual task from the start (rule 8), with the same input and plan"
    reference: not built
  - id: HR-37
    kind: system
    actor: system
    trigger: on every tick, per the chasing cadence rows
    story: The system chases what is late (an incomplete intake, an overdue task), so that Operations is not the reminder service.
    given: an intake missing two fields for 2 working days, and a task overdue since yesterday
    when: the cadence says it is time
    then: a reminder through mail.send (or a manual task to send it) to the starter or to the task's group, at most once per cadence slot and up to the configured maximum; the chase is in the run log. Running twice in one slot sends once (idempotency_key <run_id>|<step_no>|chase|<slot>).
    reference: not built
  - id: HR-38
    kind: system
    actor: system
    trigger: on every tick, for slices and events whose effective date has arrived
    story: The system makes future-dated changes take effect outside hr too, so that the business partner is right on the day.
    given: a Hired event recorded today for a start date in two weeks, and a Left event for Friday
    when: the effective date arrives
    then: the business partner gets role employee (or worker) from the start date and loses employee after the last day, through the bp seam; each sync is keyed by the event, so a second tick changes nothing. This is pitfall 5 in the research, avoided.
    reference: not built
  - id: HR-39
    kind: system
    actor: system
    trigger: on read (derived)
    story: The system derives every state that a date decides, so that no job sets a flag and nothing is stale.
    given: slices, events and steps
    when: anything is read
    then: the current slice is valid_from ≤ today < valid_to; the manager is ManagerOf(person, date); FTE, engagement status (future / active / ending / ended), overdue, "waiting on", run done, and headcount are computed; reading twice gives the same answer
    reference: not built
  - id: HR-40
    kind: system
    actor: system
    trigger: once a day, in the first tick after 02:00 (org timezone)
    story: The system applies the retention schedule, so that leavers' data does not pile up.
    given: retention rules per data category (e.g. sensitive bank details, N months after the engagement ends, purged)
    when: the sweep runs
    then: each category past its period is purged or anonymised per its rule; each action is a row in the retention log (date, person, category, action); the business partner is anonymised through the seam when the person category goes; running twice on the same day changes nothing
    reference: not built
  - id: HR-41
    kind: system
    actor: system
    trigger: on every tick
    story: The system warns when a fixed-term engagement or a time-limited right to work is about to run out, so that someone decides in time.
    given: an engagement with planned_end in 14 days and no Left or ContractExtended event, or a right-to-work follow-up date in 28 days
    when: the configured warning days are reached
    then: one task to the manager ("extend or record a leaver") or to HR ("follow-up right-to-work check"), keyed by the engagement and the date, so it is created once
    reference: not built
  - id: HR-42
    kind: system
    actor: system
    trigger: when a Left event whose reason is redundancy expands its offboarding run
    story: The system adds an outplacement offer to a redundancy's offboarding, so that the person made redundant is offered help to find their next job and the answer is on record.
    given: the employee offboarding playbook with the step offer_outplacement (hr, 2 working days after the run is created, condition reason_is [redundancy], outcomes [accepted, declined])
    when: a leaver is recorded with the reason redundancy (any other reason skips the step, recorded with its condition)
    then: 'HR has a task "Offer outplacement support"; completing it MUST give the outcome, accepted or declined (output.outcome; any other answer is refused 422 naming both), which is kept on the step and shown with it to whoever sees the step. A done step never changes its answer. With an outplacement provider connected the step can be an action with the same two outcomes; with none it is this task. The step is a playbook row, so a customer removes it, re-times it or gives it another group like any other step (a variation in playbook_deviations). APQC 7.6.2.4 Develop and implement employee outplacement (10516). This changes the offboarding PROCESS: the signed artifact is signoff/hr/employee-offboarding.bpmn.'
    reference: "brick-hr 0.6 (unreleased): gb pack offboarding step 14, playbook condition reason_is, step outcomes; tests test_hr_42_*"
  - id: HR-43
    kind: system
    actor: system
    trigger: when a Left event whose reason is retirement expands its offboarding run
    story: The system runs a retirement as its own checklist, so that the pension scheme is told, the knowledge is handed over and the long service is recognised, not only the access removed.
    given: the playbook employee-retirement (event type leave, reason retirement, employee worker types) — rows, chosen because it names the reason (the most specific playbook wins)
    when: a leaver is recorded with the reason retirement
    then: 'the run comes from employee-retirement: every access step and approval of the employee offboarding (no outplacement offer), plus "Tell the pension scheme they are retiring" (finance, last day −20 working days), "Knowledge handover sessions held" (manager, last day −5 working days, after the handover list) and "Long-service recognition" (manager, last day −2 working days). No new code path: the playbook mechanism (HR-11). APQC 7.6.2.1 Manage retirement (10514).'
    reference: "brick-hr 0.6 (unreleased): gb pack retirement(); test test_hr_43_*"
  - id: HR-50
    kind: integration
    actor: system
    trigger: when a person is created, a name or work contact changes, or a role-bearing event takes effect
    story: hr keeps the person's business partner right, as its single writer, so that every module addresses this person with one key and reads nothing private.
    given: business-partner installed, with person partners, the bp:person:sync write path, and person partners readable only with bp:person:read
    when: hr syncs
    then: a partner of kind person with bp_key 'person:<person_id>' (so hr derives the bp_id without a round trip) carries ONLY the legal name, preferred name and work email / work phone; roles employee (while an employee engagement is active), worker (freelancer), supplier (a sole-trader freelancer, paid outside payroll). A freelancer's company is its own partner (organisation, supplier role, created or reused through promote), and bp holds the edge person works_for company. Personal email, phone, address, NI, bank and right to work never go to bp. The partner is created at the hire (HR-01), not at the start date; person partners are readable only with bp:person:read (hr, contracts and finance roles), never by every signed-in user. Syncing twice changes nothing.
    owner: business-partner
    reference: not built — needs the business-partner changes listed in reference.known_gaps
  - id: HR-51
    kind: integration
    actor: system
    trigger: when a document step falls due
    story: hr asks contracts to draft, send and track the right contract, so that the run waits for "signed" and the signed copy lands on the person.
    given: an approved template for the worker type, the person's business partner, the engagement and pay
    when: the step runs
    then: contracts.draft (counterparty bp_id; context person_id|n; template kind; the variables, including the UK client_size_regime from hr's settings for the engagement's legal entity; signers), then contracts.send. Then contracts.status on each tick until signed, declined or expired. The contract_id produced is stored on the step. When signed, contracts.status gives hr, as the ORIGINATOR, the executed copy's object key and sha256; hr streams it with contracts.fetch_executed (no broad contract:employment:read) and files it on the person as a pay-bearing document, and the steps that depend on it become due. With contracts not installed, it is a manual task with the same input ("send the employment contract and attach the signed copy").
    owner: contracts
    reference: not built — the contracts.* capabilities are proposed, not yet in capabilities.yaml
  - id: HR-52
    kind: integration
    actor: system
    trigger: when an action step runs
    story: hr asks a provider brick to act in the customer's tools through capabilities, never vendor terms.
    given: compose.yaml mapping each capability to a provider brick, or to none
    when: an action step runs
    then: a POST /capabilities/<name> through the CapabilitySeam with idempotency_key, dry_run and the validated input; the RESULT shape is handled as in HR-36; the provider owns its claim table and action log
    owner: the capability provider (google-workspace first; none in the first demo)
    reference: not built
  - id: HR-53
    kind: integration
    actor: system
    trigger: when an intake step runs, or HR reissues the link
    story: The starter reaches their intake through the platform's public-link door, never through the staff app.
    given: the public-link door (a separate app, no pool)
    when: hr asks for an intake link
    then: the door issues a token bound to (hr, intake_id) and the actions read_intake / submit_intake, stored as a hash, expiring, single purpose, rate-limited, revocable, with an audit row per use; the door calls hr's intake use cases through a seam with a service identity scoped to that one intake
    owner: erp-platform (the public-link door)
    reference: not built — platform piece
  - id: HR-54
    kind: integration
    actor: system
    trigger: when a Left event commits, and at the last day 17:30 for the sign-in
    story: hr tells the other modules that a person has left, so that nothing they own outlives the person — no ERP sign-in, no open task, no open expense report.
    given: a committed Left event (actual_end set) and its offboarding run; the outbound seams below
    when: the event commits (never inside its transaction), and the tick consumes what is pending
    then: "(1) the ERP sign-in: the offboarding step revoke_erp_login (it, last day 17:30, after the access-removal approval) asks identity.revoke_app_user {pool, email, sub, reason} — the composition's dodil-appid pool user disabled and every session revoked — claimed once on <run_id>|<step_no>; with no connector (or no pool configured) it is a manual task with that exact input (rule 8). (2) open tasks: each module holding tasks assigned to the person hands them to the DERIVED manager on the last day (hr answers the manager; it stores none). (3) expenses settles the person's open expense reports before final pay. (4) v3: time-off cancels leave after the last day and fixes the leaver's balance for payroll (POST /employees/{person_id}/leaver on time-off). (2), (3) and (4) are consumed after commit from pending rows (the Left event, until each consumer has acknowledged it); a consumer that is down delays its part and nothing else. Only (1) is built."
    owner: dodil-appid (through a provider brick) for (1); the task-owning modules for (2); expenses for (3); time-off for (4)
    reference: "brick-hr 0.6 (unreleased): (1) only — identity.revoke_app_user (erp-platform capabilities.yaml 0.6, from 0.9.7; hr's own capabilities.local.yaml before), gb offboarding step 13, its timing from HR-55; tests test_hr_54_*. (2) and (3) are named seams, not built"
  - id: HR-55
    kind: person
    actor: hr_admin
    story: As the owner of offboarding, I want to choose when a leaver loses their sign-in to this ERP — at the end of their last day, or as soon as they are recorded — with a different choice per leave reason, so that a dismissed person loses access at the meeting while someone who resigned keeps it to their last day.
    given: the dated setting offboarding.revoke_access_at, default last_day_end (the last day at the business close, 17:30 in business_timezone, after the access-removal approval); the other value is immediate (as soon as the leaver is recorded and the access removal approved); I hold hr:offboarding:policy
    when: I set dismissal to immediate, then a dismissal and a resignation are recorded today
    then: "the dismissal's revoke_erp_login step is due when the leaver is recorded and runs once the access-removal approval is given, months before the last day; the resignation's is due on the last day at 17:30. The setting is a new dated row each time, never an edit: from tomorrow by default, only the first row of a key and reason may start today, never earlier, and a different value for a day that has a row is refused (409). Every row — who, when, from which day, the note — is readable, and the one in force is the reason's own, else the default's, else last_day_end, on the business date the leaver is recorded. A run already made keeps its timing. Without hr:offboarding:policy the change is refused (403)."
    screen: Settings
    reference: "brick-hr 0.6 (unreleased): POST/GET /dated-settings/{setting_key}, hr_setting_row; tests test_hr_55_*"
  - id: HR-56
    kind: integration
    actor: system
    trigger: when another module needs to know whether a person is employed on a date (expenses, pos, time-off, timesheets, payroll)
    story: Other modules ask hr whether a person is employed on a date and where, so that nobody keeps a second staff list.
    given: person 4410 employed by UK01 from 2024-03-01 in org unit SALES, location LON, cost centre SALES-N
    when: time-off calls GET /persons/4410/employment?on=2026-12-21, and GET /persons/4410/employment?on=2024-02-01
    then: "{employed: true, engagement_id, worker_type, company_code UK01, org_unit_id, location_code LON, cost_centre SALES-N, bp_id}; for 2024-02-01 employed false with nulls, never a 404; no pay and no sensitive data"
    owner: hr
    reference: named seam (v2 draft)
  - id: HR-57
    kind: integration
    actor: system
    trigger: when another module fixes an approver (expenses, time-off, timesheets)
    story: Other modules ask hr who a person's manager is on a date, so that approvals follow the org tree and nobody stores a manager.
    given: person 4410 in org unit SALES whose chief position is held by 2280 on 2026-12-21; 2280's own manager is 1904
    when: GET /persons/4410/manager?on=2026-12-21, and GET /persons/2280/manager?on=2026-12-21&level=1
    then: "{manager: {person_id 2280, bp_id, pool_user_sub, email}, source org_tree} and, for 2280, 1904; derived by ManagerOf on read, never stored"
    owner: hr
    reference: named seam (v2 draft)
  - id: HR-58
    kind: integration
    actor: system
    trigger: when a person signs in to another module's screen (expenses, time-off, timesheets, payroll self-service)
    story: Other modules turn the signed-in user's sub into a person_id here, so that "my" means the same person everywhere.
    given: person 4410 with hr_person.pool_user_sub s-4410
    when: GET /persons?pool_user_sub=s-4410, and with a sub nobody carries
    then: "{person_id 4410, bp_id, company_code UK01}; 404 for the unknown sub"
    owner: hr
    reference: named seam (v2 draft)
  - id: HR-59
    kind: integration
    actor: system
    trigger: when payments exports a payout run to a person (an expense reimbursement, a salary)
    story: Payments reads one person's bank account on the payment date, so that the account is known only to the payment file.
    given: person 4410 with a bank slice valid from 2025-06-01
    when: payments' client calls GET /persons/4410/bank-account?on=2026-11-30
    then: "{account_holder, sort_code, account_number, valid_from 2025-06-01}; every read audited (who, when, which person, which payout); any other client is refused; 404 when none is held on the date"
    owner: hr
    reference: named seam (v2 draft)
  - id: HR-60
    kind: integration
    actor: system
    trigger: when the payroll module prepares a pay run (instead of a payroll provider reading the extract)
    story: The payroll module reads hr's payroll extract for a legal entity and period, so that pay, starters, leavers and changes reach the payslip with nobody re-keying them.
    given: "company UK01, monthly period 2026-11: starter 4450 (2026-11-02, salary 30,000.00 a year), leaver 4495 (last day 2026-11-13), a pay change for 4410 from 2026-11-16 (36,000.00 to 38,400.00), a retro line for October; weekly period 2026-W47 for the weekly-paid"
    when: "payroll calls POST /payroll-extracts {legal_entity_ref UK01, period 2026-11}, GET /payroll-extracts/UK01|2026-11, and after its run is approved POST /payroll-extracts/UK01|2026-11/sent {sent_ref: the pay run id}"
    then: the produce call answers the draft batch (re-produced while it is a draft, so a later change before the run is approved is picked up); the GET lists every line (person_id, n, component, for_period, rate_basis, rate_amount NUMERIC 19,4, prorate_from, prorate_to, change_kind) with starters and leavers named, 4410's pay as two slices split on 2026-11-16, and October's retro line; freelancers never appear; sent freezes the batch exactly as mark_extract_sent does (HR-19), a repeat with the same sent_ref answers the same, a different sent_ref 409; a weekly period is an ISO week (YYYY-Www) for a weekly pay schedule (v3)
    owner: hr
    reference: not built
  - id: HR-61
    kind: integration
    actor: system
    trigger: when payroll builds a full payment submission or a P45/P60 for a person
    story: Payroll reads the identity HMRC needs (legal name, date of birth, NI number, home address) from hr, so that it is kept once, as sensitive data, and read only by payroll.
    given: person 4410 with ni_number, date_of_birth and home_address slices in person_sensitive
    when: payroll's client calls GET /persons/4410/payroll-identity?on=2026-11-30
    then: "{person_id, legal_first_names, legal_last_name, date_of_birth, ni_number (or null), home_address (the address shape), valid_from}; every read audited like a bank read; refused to every client but payroll's and to every person role; no bank data on this route"
    owner: hr
    reference: not built
  - id: HR-62
    kind: integration
    actor: system
    trigger: when time-off costs a request, timesheets builds a week's expected hours, or payroll prorates a part period
    story: Other modules read a person's working pattern and public holidays day by day, so that a bank holiday, a part-time day and a mid-month start mean the same in every module.
    given: person 5120 at location EDI (holiday_calendar GB-SCT), schedule Monday to Wednesday 450 minutes, FTE 0.6000
    when: GET /persons/5120/work-pattern?from=2026-11-30&to=2026-12-06
    then: "7 days: 2026-11-30 contracted 450 with public_holiday \"St Andrew's Day\", 2026-12-01 and 12-02 450, Thursday to Sunday 0; employed per day; at most 400 days per call (422 bounds); derived from the assignment, work schedule and hr_holiday rows on read. v4: contracted_minutes is the day's contracted time (0 on a non-working day and on a public holiday the schedule does not work); a caller counting working days counts a day with contracted_minutes > 0 while employed, whatever its length, and a caller costing hours uses the minutes"
    owner: hr
    reference: not built
  - id: HR-63
    kind: integration
    actor: system
    trigger: when another module needs a person's company, org unit, team, manager or work email on a date (time-off, expenses, timesheets, payroll)
    story: Other modules ask hr for a person's organisational assignment and work email by person id, so that no module types an email or keeps its own copy of who belongs where.
    given: person 4410 employed by UK01 in org unit SALES, team SALES-N, derived manager 2280, work email ana.lee@example.com on 2026-12-21
    when: expenses calls GET /persons/4410/assignment?on=2026-12-21
    then: "{person_id 4410, on 2026-12-21, employed true, company_code UK01, org_unit_id, org_unit_code SALES, team_code SALES-N, manager_person_id 2280, work_email ana.lee@example.com, pool_user_sub (null until the person signs in)}; a date with no engagement answers employed false with nulls, never a 404; derived on read from the assignment slice, the ManagerOf walk and the communication record in force on the date (SAP's organisational assignment plus communication), nothing stored by the caller; no pay and no sensitive data; a caller sees only the companies its grant is scoped to"
    owner: hr
    reference: "v4 (2026-10-26, seemo's decided answer 2): not built"
  - id: HR-64
    kind: integration
    actor: system
    trigger: when another module works over everyone of a company, an org unit or a manager's team (a year-end pass, a team calendar, a reminder run, a migration matching people)
    story: Other modules ask hr for the roster of a company, org unit or team on a date, so that a year-end pass or a team calendar covers everyone and nobody keeps a staff list.
    given: "UK01 on 2026-12-31: 212 people employed, 5 of them in the team whose derived manager is 2280"
    when: time-off calls GET /roster?company_code=UK01&on=2026-12-31&limit=200, then the next page; and GET /roster?company_code=UK01&manager_person_id=2280&on=2026-12-21
    then: a page of [{person_id, company_code, org_unit_code, team_code, manager_person_id, work_email, fte, employed_from, employed_to}] ordered by person_id, at most 200 a page with next_offset; 212 people in two pages; the team query answers the 5 whose derived manager is 2280 on that date (direct reports, level 1); people who left before `on` are not listed; a company outside the caller's scope answers an empty page, never another company's people
    owner: hr
    reference: "v4 (2026-10-26, seemo's decided answer 2): not built"
workflows:
  - entity: run
    states:
      - open
      - done
      - cancelled
    transitions:
      - from: none
        to: open
        by: system
        gate: a committed personnel event whose kind starts a run, and a playbook matching it
        effect: steps expanded from the frozen playbook version; due_at computed
      - from: open
        to: cancelled
        by: hr_admin
        requires: reason
        effect: not-done steps cancelled; a reversal task per done action
    note: done is DERIVED (every step done, skipped or cancelled). 'stuck' and 'waiting on <group>' are derived too
  - entity: step
    states:
      - pending
      - waiting
      - done
      - skipped
      - cancelled
    transitions:
      - from: pending
        to: waiting
        by: system
        gate: due and its dependencies done; for an approval, draft, document or in_progress action, waiting on someone or something
        effect: shown on My tasks for its group
      - from:
          - pending
          - waiting
        to: done
        by:
          - assignee
          - system
        gate: task completed / capability done / approval granted / contract signed / draft approved
        effect: result and provider_ref stored; dependants become due
      - from:
          - pending
          - waiting
        to: skipped
        by: system
        gate: its condition is false for this person
        effect: recorded with the condition
      - from:
          - pending
          - waiting
        to: cancelled
        by:
          - hr_admin
          - it
        gate: run cancelled, or an approval refused
    note: "overdue = due_at < now and not done, derived; a done step is never re-timed and never acts again. An action with no provider is a manual task from expansion, with the same kind and the same input. v2: a step with outcomes (the outplacement offer: accepted / declined) reaches done only WITH one of them, kept on the step"
  - entity: offboarding_playbook
    states:
      - standard
      - redundancy
      - retirement
    transitions:
      - from: none
        to: standard
        by: system
        gate: "a Left event: the employee offboarding playbook"
        effect: "the gb steps 1–13: handover, approvals, access removal at last day 17:30, the ERP sign-in revoked (HR-54), deletion after approval"
      - from: none
        to: redundancy
        by: system
        gate: the reason is redundancy (condition reason_is)
        effect: the same run plus offer_outplacement (HR-42, outcome accepted or declined)
      - from: none
        to: retirement
        by: system
        gate: "the reason is retirement: the playbook employee-retirement, which names the reason"
        effect: the standard steps plus pension_notice, knowledge_handover, long_service_recognition (HR-43)
    note: "v2 PROCESS CHANGE for sign-off: not a state machine on a row but which checklist a leaver gets. The source is the playbook rows (gb pack); the signed artifacts are signoff/hr/employee-offboarding.bpmn and signoff/hr/employee-retirement.bpmn (show_playbook_bpmn). Signed by seemo 2026-10-25"
  - entity: engagement
    states:
      - future
      - active
      - ending
      - ended
    transitions:
      - from: none
        to: future
        by:
          - manager
          - hr_admin
        gate: a Hired, Rehired or Converted event
      - from:
          - future
          - active
        to: ending
        by:
          - manager
          - hr_admin
        gate: a Left event (actual_end set)
    note: every state is DERIVED from start date, planned_end, actual_end and today; nothing stores a status
  - entity: intake
    states:
      - issued
      - submitted
      - expired
      - revoked
    transitions:
      - from: none
        to: issued
        by: system
        gate: the intake step falls due
      - from: issued
        to: submitted
        by: starter
        gate: every required field for the worker type and pack
      - from:
          - issued
          - expired
        to: revoked
        by: hr_admin
        effect: a reissue makes a new link
    note: expired is derived from the door's expiry; 'complete' is derived from the required fields
entities:
  - id: person
    meaning: a natural person we employ or engage, once, however many times they come back
    natural_key: person_id = blake2b(person_key, 7); person_key = 'staff:<no>' else 'email:<normalised personal email>'
    key_attributes:
      - person_key
      - staff_no
      - bp_id
      - pool_user_sub
      - created_at
    relationships:
      - 1..n engagement
      - -> business_partner (bp_id)
      - 0..1 pool user
    master_data: SHARED — hr is the sole writer (person_id in shared.yaml)
    reference_table: hr_person
    note: "identity only, not sliced. Date of birth is NOT here: it is sensitive (see person_sensitive)"
  - id: person_detail
    meaning: the person's names and contact on a date
    natural_key: person_id|valid_from (TC1)
    key_attributes:
      - legal_given_name
      - legal_family_name
      - preferred_name
      - personal_email
      - personal_phone
      - work_email
      - work_phone
      - valid_to
      - superseded_by
      - created_by
    master_data: module-owned (Person aggregate)
    reference_table: hr_person_detail
  - id: engagement
    meaning: one period of working for us under one worker type
    natural_key: person_id|n
    key_attributes:
      - worker_type
      - legal_entity_ref
      - start_date
      - planned_end
      - actual_end
      - supplier_bp_id
    relationships:
      - 1..n assignment
      - 0..n pay
      - 1..n event
      - -> business_partner (supplier_bp_id, a company freelancer)
    master_data: module-owned (Person aggregate)
    reference_table: hr_engagement
    note: header, not sliced; status derived. legal_entity_ref from day 1 (multiple legal entities is an extension point). supplier_bp_id is a bp_id (BIGINT)
  - id: assignment
    meaning: where an engagement sits on a date
    natural_key: person_id|n|valid_from (TC1 per engagement)
    key_attributes:
      - org_id
      - org_unit_id
      - position_id
      - job_code
      - location_code
      - schedule_code
      - employment_pct
      - employee_subgroup
      - cost_centre
      - manager_override_person_id
      - valid_to
      - superseded_by
    master_data: module-owned (Person aggregate)
    reference_table: hr_assignment
    note: position optional; cost_centre is a reference to finance's code (shared.yaml), inherited from the position or unit when empty; manager override is the rare exception
  - id: pay
    meaning: the rate an engagement is paid at on a date
    natural_key: person_id|n|valid_from (TC1 per engagement from its first slice)
    key_attributes:
      - rate_basis
      - rate_amount (NUMERIC(19
      - 4))
      - currency
      - frequency
      - pay_grade
      - valid_to
      - superseded_by
    master_data: module-owned (Person aggregate)
    reference_table: hr_pay
  - id: pay_component
    meaning: an allowance or recurring extra
    natural_key: person_id|n|component|valid_from (TC3)
    key_attributes:
      - rate_basis
      - rate_amount (NUMERIC(19
      - 4))
      - currency
      - valid_to
      - superseded_by
    master_data: module-owned (Person aggregate)
    reference_table: hr_pay_component
  - id: event
    meaning: a personnel event on an engagement (Hired, Transferred, PayChanged, ContractExtended, Left, Rehired, Converted)
    natural_key: person_id|n|seq (append-only)
    key_attributes:
      - event_type
      - kind
      - reason
      - effective_date
      - actor
      - recorded_at
      - slices_written
      - run_id
      - bp_synced_at
    master_data: module-owned (Person aggregate)
    reference_table: hr_event
    note: seq is the next integer for the engagement; a concurrent second write of one key is rejected (23505) and retried with seq+1
  - id: document
    meaning: a non-sensitive document on a person (signed contract, letters)
    natural_key: "person_id|doc_id (doc_id derived: 'contract:<contract_id>', 'letter:<run_id>|<step_no>')"
    key_attributes:
      - document_type
      - object_key
      - sha256
      - size_bytes
      - expires_on
      - contract_id
      - uploaded_by
      - uploaded_at
    master_data: module-owned (Person aggregate)
    reference_table: hr_document
    note: the file is a DataK3 object under hr/<person_id>/…; access class comes from the document type (personnel | pay)
  - id: compliance_record
    meaning: a record a localisation pack requires (right-to-work check, status determination, written statement given)
    natural_key: person_id|n|kind|valid_from
    key_attributes:
      - pack
      - outcome
      - checked_on
      - checked_by
      - follow_up_on
      - evidence_ref
      - reasons
    master_data: module-owned (Person aggregate)
    reference_table: hr_compliance_record
    note: evidence_ref points into the Sensitive aggregate; the record says what was done, never a legal judgement
  - id: sensitive
    meaning: the root of one person's sensitive data
    natural_key: person_id
    key_attributes:
      - version
      - erased_at
      - anonymised_at
    master_data: module-owned (Sensitive aggregate root)
    reference_table: hr_sensitive
    note: "carries the aggregate's version, checked on save (two finance users correcting bank details at once: one gets 409)"
  - id: person_sensitive
    meaning: the personal data only HR and finance may see
    natural_key: person_id|kind|valid_from (TC3, under the hr_sensitive root)
    key_attributes:
      - kind (ni_number | tax_id | bank | home_address | date_of_birth | emergency_contact | right_to_work_evidence | vat_number)
      - value_json
      - object_key
      - valid_to
      - superseded_by
      - created_by
    master_data: module-owned (its OWN aggregate)
    reference_table: hr_person_sensitive
  - id: org
    meaning: one org tree
    natural_key: org_id
    key_attributes:
      - name
      - legal_entity_ref
    master_data: module-owned (Org aggregate root)
    reference_table: hr_org
  - id: org_unit
    meaning: a team or department on a date
    natural_key: org_id|org_unit_id|valid_from (TC1 over its lifetime)
    key_attributes:
      - name
      - parent_org_unit_id
      - org_unit_type
      - cost_centre
      - chief_position_id
      - location_code
      - valid_to
    master_data: SHARED — hr is the sole writer (other modules may group by it)
    reference_table: hr_org_unit
    note: "the walk up for the manager is a recursive CTE over current slices: trees of hundreds of units"
  - id: position
    meaning: one seat in an org unit that describes a job
    natural_key: org_id|position_id|valid_from (TC1 over its lifetime)
    key_attributes:
      - org_unit_id
      - job_code
      - fte_pct
      - cost_centre
      - vacant_policy
      - valid_to
    master_data: module-owned (Org aggregate)
    reference_table: hr_position
    note: optional per unit, EXCEPT the chief position, which is how the manager is derived; a holder is the assignment that names it
  - id: job
    meaning: a job in the catalogue
    natural_key: job_code
    key_attributes:
      - title
      - family
      - default_subgroup
      - default_pay_grade
      - active
    master_data: SHARED — hr is the sole writer
    reference_table: hr_job
  - id: location
    meaning: an office or place of work
    natural_key: location_code
    key_attributes:
      - address
      - country
      - timezone
      - holiday_calendar
    master_data: module-owned (configuration)
    reference_table: hr_location
  - id: work_schedule
    meaning: a weekly pattern of working time
    natural_key: schedule_code
    key_attributes:
      - weekly_minutes
      - daily_pattern
      - full_time_weekly_minutes
    master_data: module-owned (configuration)
    reference_table: hr_work_schedule
  - id: holiday
    meaning: a public holiday in a calendar
    natural_key: holiday_calendar|holiday_date
    key_attributes:
      - name
    master_data: module-owned (configuration; a localisation pack loads its rows)
    reference_table: hr_holiday
  - id: catalogue
    meaning: the small catalogues (worker types, employee subgroups, org unit types, event types → kind, reasons, infogroups, rate bases, pay component types, pay grades, responsible groups, document types, intake fields, draft instructions, retention rules, settings)
    natural_key: each by its own code (worker_type, event_type, event_type|reason, event_type|record, component, group_code, document_type, pack|field, category, key)
    key_attributes:
      - label
      - active
      - and per catalogue its rule fields
    master_data: module-owned (configuration)
    reference_table:
      - hr_worker_type
      - hr_employee_subgroup
      - hr_org_unit_type
      - hr_event_type
      - hr_event_reason
      - hr_infogroup
      - hr_rate_basis
      - hr_pay_component_type
      - hr_pay_grade
      - hr_responsible_group
      - hr_document_type
      - hr_intake_field
      - hr_draft_instruction
      - hr_retention_rule
      - hr_settings
  - id: unit_access
    meaning: the groups, chat spaces and folders that come with an org unit
    natural_key: org_unit_id|kind|target
    key_attributes:
      - kind (group | chat_space | drive_folder)
      - target
      - role
    master_data: module-owned (configuration)
    reference_table: hr_unit_access
  - id: playbook
    meaning: the customer's checklist for one kind of run, versioned
    natural_key: playbook_id|version
    key_attributes:
      - name
      - event_types
      - worker_types
      - reasons
      - org_unit_id
      - status
      - created_by
    master_data: module-owned (configuration with invariants)
    reference_table: hr_playbook
  - id: playbook_step
    meaning: one step of a playbook
    natural_key: playbook_id|version|step_no
    key_attributes:
      - kind
      - title
      - responsible_group
      - capability
      - input_template
      - timing_rule
      - depends_on
      - condition
      - approval_group
      - draft_instruction
      - template_kind
      - fan_out
    master_data: module-owned (Playbook aggregate)
    reference_table: hr_playbook_step
  - id: run
    meaning: a playbook expanded for one person and one personnel event
    natural_key: run_id = <direction>:<person_id>:<n>:<event seq>
    key_attributes:
      - direction
      - person_id
      - n
      - event_seq
      - playbook_id
      - playbook_version
      - created_at
      - cancelled_at
      - cancel_reason
    master_data: module-owned (Run aggregate root)
    reference_table: hr_run
  - id: run_step
    meaning: one step of one run
    natural_key: run_id|step_no (step_no = the playbook step_no, plus '/<target>' when fanned out per access row)
    key_attributes:
      - kind
      - responsible_group
      - capability
      - input_json
      - plan
      - manual
      - timing_rule
      - due_at
      - state
      - attempts
      - last_status
      - provider_ref
      - result_json
      - contract_id
      - draft_text
      - done_by
      - done_at
    master_data: module-owned (Run aggregate)
    reference_table: hr_run_step
    note: idempotency_key = <run_id>|<step_no>; contract_id (shared.yaml) for a document step
  - id: run_party
    meaning: who a run-scoped group is for this run (the buddy, the takeover)
    natural_key: run_id|group_code
    key_attributes:
      - person_id
      - set_by
    master_data: module-owned (Run aggregate)
    reference_table: hr_run_party
  - id: run_log
    meaning: the run's history (reschedules, approvals, completions, chases, cancellations)
    natural_key: run_id|seq (append-only; seq is the next integer for the run, a concurrent duplicate is rejected 23505 and retried)
    key_attributes:
      - what
      - from_value
      - to_value
      - actor
      - event_at
    master_data: module-owned (Run aggregate)
    reference_table: hr_run_log
  - id: intake
    meaning: the starter's self-service form for one engagement
    natural_key: intake_id = person_id|n
    key_attributes:
      - link_ref (the door's id
      - never the token)
      - issued_at
      - expires_at
      - submitted_at
      - missing_fields
      - chases
    master_data: module-owned (Intake aggregate)
    reference_table: hr_intake
  - id: payroll_batch
    meaning: one period's hand-off to payroll for one legal entity
    natural_key: batch_id = <legal_entity_ref>|<period>
    key_attributes:
      - state (draft | sent)
      - produced_at
      - sent_at
      - sent_by
    master_data: module-owned (PayrollExtract aggregate)
    reference_table: hr_payroll_batch
  - id: payroll_line
    meaning: one line of a payroll extract
    natural_key: batch_id|person_id|n|component|for_period
    key_attributes:
      - rate_basis
      - rate_amount (NUMERIC(19
      - 4))
      - currency
      - prorate_from
      - prorate_to
      - quantity_minutes
      - quantity_days (NUMERIC(5
      - 2))
      - payable_amount (NUMERIC(18
      - 2))
      - change_kind
    master_data: module-owned (PayrollExtract aggregate)
    reference_table: hr_payroll_line
    note: payable_amount only where a quantity exists (from the future time brick) or a fixed amount is due; rounded once here
  - id: privacy_request
    meaning: a subject-access or erasure request
    natural_key: request_id (derived from the person and the received date)
    key_attributes:
      - person_id
      - kind (access | erasure)
      - received_on
      - due_on
      - done_at
      - export_object_key
      - outcome
    master_data: module-owned (PrivacyRequest aggregate)
    reference_table: hr_privacy_request
  - id: retention_log
    meaning: what the retention sweep or an erasure did
    natural_key: run_date|person_id|category
    key_attributes:
      - action (purged | anonymised | kept)
      - basis
      - actor
    master_data: module-owned (append-only)
    reference_table: hr_retention_log
master_data:
  owns:
    - hr_person
    - hr_org_unit
    - hr_job
  references:
    - entity: business_partner
      owner: business-partner
      how: hr_person.bp_id = business_partner.bp_id (bp_key 'person:<person_id>'); hr_engagement.supplier_bp_id for a company freelancer
      if_absent: "not optional: contracts and finance address people by bp_id; without it a freelancer is paid from a second, unlinked record (S/4's old-model failure)"
    - entity: cost_centre
      owner: gl (finance/controlling); hr stores the code only
      how: hr_assignment.cost_centre, hr_position.cost_centre, hr_org_unit.cost_centre
      if_absent: a free code typed by HR, validated against nothing until finance owns cost centres
  warning: "Before this module, the sign-in pool WAS the staff list: other modules hold the pool user's sub or email in their owner columns. From now on, person_id is the key for people. hr_person.pool_user_sub maps the two, and a module that needs more than \"who is signed in\" references person_id, never a copy of the staff list. And never put a person's private data on their business partner: it is the record other modules share. Even with person partners restricted to bp:person:read, a partner carries a name and a work contact, nothing more."
jobs:
  - story: HR-30
    trigger: every minute or so
    runs: POST /run-due-steps (run_due_steps(now)), as the brick's service identity
    where_options:
      - the ONE clock worker (the clock service client) that calls every brick's tick route listed in the composition, pinned warm (--reserved 1 --max-replicas 1)
      - external scheduler calling the route with a service client holding hr:run:tick
    idempotent: each step's state guard plus idempotency_key <run_id>|<step_no>; a tick may run twice
  - story: HR-31
    trigger: at each step's due_at
    runs: the account and access action steps
    where_options:
      - inside the tick (HR-30)
    idempotent: <run_id>|<step_no>; the provider claims it with a plain INSERT
  - story: HR-32
    trigger: at each step's due_at
    runs: calendar action steps
    where_options:
      - inside the tick (HR-30)
    idempotent: <run_id>|<step_no>
  - story: HR-33
    trigger: at the draft step's due_at, or on request
    runs: the Models adapter
    where_options:
      - inside the tick (HR-30)
      - in the same request when a manager asks early
    idempotent: the first draft is kept; a new one only on the approver's request
  - story: HR-34
    trigger: last_day 17:30 org timezone
    runs: access removal steps
    where_options:
      - inside the tick (HR-30)
    idempotent: <run_id>|<step_no>
  - story: HR-35
    trigger: last_day +30 days, after approval
    runs: transfer status check, then delete
    where_options:
      - inside the tick (HR-30)
    idempotent: <run_id>|<step_no>; drive.transfer_status is a read
  - story: HR-36
    trigger: every tick
    runs: result handling and retries
    where_options:
      - inside the tick (HR-30)
    idempotent: attempts counted on the step; a manual task is created once (its key is the step)
  - story: HR-37
    trigger: per the cadence rows
    runs: chasing
    where_options:
      - inside the tick (HR-30)
    idempotent: <run_id>|<step_no>|chase|<slot>
  - story: HR-38
    trigger: when an effective date arrives
    runs: business-partner sync of future-dated events
    where_options:
      - inside the tick (HR-30)
      - in the same request when the effective date is today or past
    idempotent: keyed by the event (person_id|n|seq); bp_synced_at set after success
  - story: HR-39
    trigger: on read
    runs: nothing stored
    where_options:
      - derived on read
    idempotent: nothing to repeat
  - story: HR-40
    trigger: daily, first tick after 02:00 org timezone
    runs: the retention sweep
    where_options:
      - inside the tick (HR-30)
      - external scheduler
    idempotent: retention log key run_date|person_id|category
  - story: HR-41
    trigger: every tick
    runs: expiry warnings
    where_options:
      - inside the tick (HR-30)
    idempotent: the task is keyed by the engagement and the date warned for
seams:
  - story: HR-50
    with: business-partner
    owner: business-partner
    rule: hr calls bp:person:sync (person partner fields, roles, works_for edge) and bp:partner:promote (a freelancer's company). It never writes business_partner, bp_role or bp_edges itself
  - story: HR-51
    with: contracts
    owner: contracts
    rule: hr calls contracts.draft / contracts.send / contracts.status (capabilities, through the CapabilitySeam); contracts never reads hr tables
  - story: HR-52
    owner: the capability provider named in compose.yaml
    provider: google-workspace first; none in the first demo
    rule: hr calls POST /capabilities/<name> on the mapped provider; it never names a vendor and never holds vendor credentials
  - story: HR-53
    owner: erp-platform (public-link door)
    rule: the door holds the token (hashed) and calls hr's intake use cases with a service identity scoped to one intake
  - story: HR-54
    provider: dodil-appid
    owner: the identity provider brick named in compose.yaml (a dodil-appid provider); none = a manual task
    direction: outbound
    event: hr.person.left
    route: POST /capabilities/identity.revoke_app_user (CapabilitySeam; CAPABILITY_IDENTITY_REVOKE_APP_USER)
    request: '{idempotency_key: "<run_id>|<step_no>", dry_run, input: {pool: "<org>/<pool>", email, sub (null when hr has none), reason: "left on <last_day>"}}'
    response: "the capability RESULT; output {disabled: bool, sessions_revoked: int}; a user not in the pool is done with disabled false"
    rule: the offboarding step revoke_erp_login, due at last day 17:30 after the access-removal approval; the run step is the pending row the tick consumes after commit, claimed once. hr never holds an appid admin credential. The capability is hr's own contract (capabilities.local.yaml) until erp-platform's capabilities.yaml has identity.revoke_app_user under the same name
    status: built in brick-hr 0.6 (unreleased)
  - story: HR-54
    with: crm
    owner: the task-owning module
    direction: outbound
    event: hr.person.left
    route: 'proposed: POST /tasks/reassign-owner {from_bp_id, to_bp_id, effective_on, reason: left, source_ref: "hr:left:<person_id>:<n>"}'
    rule: on the last day, hr names the DERIVED manager on that date (ManagerOf, never stored) as the new owner of the person's open tasks; keyed on source_ref, so a retry reassigns nothing twice; consumed after commit from the pending Left event until the owner acknowledges. Named, not built
    status: named seam (v2 draft); the owner's route is to be agreed
  - story: HR-54
    with: expenses
    owner: expenses
    direction: outbound
    event: hr.person.left
    route: POST /employees/{person_id}/leaver
    request: "{last_day (YYYY-MM-DD), source_ref: \"hr:left:<person_id>:<n>\"} (v4: the body moved out of route, so the route reads as a route; offered by expenses v1; permission exp:leaver:intake, held by hr's service client alone)"
    rule: expenses settles the person's open expense reports (submit, approve or reject what is open; reimburse what is approved) before the final pay step; hr only tells it who left and when. Named, not built
    status: named seam (v2 draft)
  - story: HR-56
    with: expenses
    owner: hr
    direction: inbound
    route: GET /persons/{person_id}/employment?on=
    permission: hr:employment:read
    caller: machine (the service clients of expenses and pos)
    request: path person_id; query on (YYYY-MM-DD, default today in business_timezone)
    response: "200 {person_id, on, employed (bool: an engagement active on `on`), engagement_id, worker_type, company_code, org_unit_id, location_code, cost_centre, bp_id}; employed false (and nulls) when no engagement covers the date, never a 404 for a person the caller may ask about"
    rule: read from the engagement and assignment slices in force on the date; no pay, no sensitive data
    status: named seam (v2 draft)
  - story: HR-56
    with: payroll
    owner: hr
    direction: inbound
    route: GET /persons/{person_id}/employment?on=
    permission: hr:employment:read
    caller: machine (the service clients of expenses and pos)
    request: path person_id; query on (YYYY-MM-DD, default today in business_timezone)
    response: "200 {person_id, on, employed (bool: an engagement active on `on`), engagement_id, worker_type, company_code, org_unit_id, location_code, cost_centre, bp_id}; employed false (and nulls) when no engagement covers the date, never a 404 for a person the caller may ask about"
    rule: read from the engagement and assignment slices in force on the date; no pay, no sensitive data
    status: "hr v4 2026-10-26: one entry per caller, as erp_platform.contract reads with: (was a callers: list); listed for payroll PRL-20"
  - story: HR-56
    with: timesheets
    owner: hr
    direction: inbound
    route: GET /persons/{person_id}/employment?on=
    permission: hr:employment:read
    caller: machine (the service clients of expenses and pos)
    request: path person_id; query on (YYYY-MM-DD, default today in business_timezone)
    response: "200 {person_id, on, employed (bool: an engagement active on `on`), engagement_id, worker_type, company_code, org_unit_id, location_code, cost_centre, bp_id}; employed false (and nulls) when no engagement covers the date, never a 404 for a person the caller may ask about"
    rule: read from the engagement and assignment slices in force on the date; no pay, no sensitive data
    status: "hr v4 2026-10-26: one entry per caller, as erp_platform.contract reads with: (was a callers: list); listed for timesheets TS-18"
  - story: HR-56
    with: time-off
    owner: hr
    direction: inbound
    route: GET /persons/{person_id}/employment?on=
    permission: hr:employment:read
    caller: machine (the service clients of expenses and pos)
    request: path person_id; query on (YYYY-MM-DD, default today in business_timezone)
    response: "200 {person_id, on, employed (bool: an engagement active on `on`), engagement_id, worker_type, company_code, org_unit_id, location_code, cost_centre, bp_id}; employed false (and nulls) when no engagement covers the date, never a 404 for a person the caller may ask about"
    rule: read from the engagement and assignment slices in force on the date; no pay, no sensitive data
    status: "hr v4 2026-10-26: one entry per caller, as erp_platform.contract reads with: (was a callers: list); listed for time-off TOF-19"
  - story: HR-56
    with: pos
    owner: hr
    direction: inbound
    route: GET /persons/{person_id}/employment?on=
    permission: hr:employment:read
    caller: machine (the service clients of expenses and pos)
    request: path person_id; query on (YYYY-MM-DD, default today in business_timezone)
    response: "200 {person_id, on, employed (bool: an engagement active on `on`), engagement_id, worker_type, company_code, org_unit_id, location_code, cost_centre, bp_id}; employed false (and nulls) when no engagement covers the date, never a 404 for a person the caller may ask about"
    rule: read from the engagement and assignment slices in force on the date; no pay, no sensitive data
    status: "hr v4 2026-10-26: one entry per caller, as erp_platform.contract reads with: (was a callers: list); listed for pos POS-32"
  - story: HR-57
    with: expenses
    owner: hr
    direction: inbound
    route: GET /persons/{person_id}/manager?on=&level=
    permission: hr:manager:read
    caller: machine (expenses' service client)
    request: path person_id; query on (YYYY-MM-DD), level (1 = the derived manager, 2 = the next one up; default 1)
    response: "200 {person_id, on, level, manager: {person_id, bp_id, pool_user_sub, email} | null, source: override | org_tree}; null when nobody holds the chief position up the tree"
    rule: DERIVED from the org tree on that date by ManagerOf (the chief of the assignment's org unit, walking up; manager_override_person_id wins), never stored
    status: named seam (v2 draft)
  - story: HR-57
    with: timesheets
    owner: hr
    direction: inbound
    route: GET /persons/{person_id}/manager?on=&level=
    permission: hr:manager:read
    caller: machine (expenses' service client)
    request: path person_id; query on (YYYY-MM-DD), level (1 = the derived manager, 2 = the next one up; default 1)
    response: "200 {person_id, on, level, manager: {person_id, bp_id, pool_user_sub, email} | null, source: override | org_tree}; null when nobody holds the chief position up the tree"
    rule: DERIVED from the org tree on that date by ManagerOf (the chief of the assignment's org unit, walking up; manager_override_person_id wins), never stored
    status: "hr v4 2026-10-26: one entry per caller, as erp_platform.contract reads with: (was a callers: list); listed for timesheets TS-18"
  - story: HR-57
    with: time-off
    owner: hr
    direction: inbound
    route: GET /persons/{person_id}/manager?on=&level=
    permission: hr:manager:read
    caller: machine (expenses' service client)
    request: path person_id; query on (YYYY-MM-DD), level (1 = the derived manager, 2 = the next one up; default 1)
    response: "200 {person_id, on, level, manager: {person_id, bp_id, pool_user_sub, email} | null, source: override | org_tree}; null when nobody holds the chief position up the tree"
    rule: DERIVED from the org tree on that date by ManagerOf (the chief of the assignment's org unit, walking up; manager_override_person_id wins), never stored
    status: "hr v4 2026-10-26: one entry per caller, as erp_platform.contract reads with: (was a callers: list); listed for time-off TOF-19"
  - story: HR-58
    with: expenses
    owner: hr
    direction: inbound
    route: GET /persons?pool_user_sub=
    permission: hr:employment:read
    caller: machine (expenses' service client), for the sub in the signed-in person's token
    request: query pool_user_sub
    response: 200 {person_id, bp_id, company_code} | 404 when no person carries that sub
    rule: looks up hr_person.pool_user_sub; returns identity keys only
    status: named seam (v2 draft)
  - story: HR-58
    with: payroll
    owner: hr
    direction: inbound
    route: GET /persons?pool_user_sub=
    permission: hr:employment:read
    caller: machine (expenses' service client), for the sub in the signed-in person's token
    request: query pool_user_sub
    response: 200 {person_id, bp_id, company_code} | 404 when no person carries that sub
    rule: looks up hr_person.pool_user_sub; returns identity keys only
    status: "hr v4 2026-10-26: one entry per caller, as erp_platform.contract reads with: (was a callers: list); listed for payroll PRL-11"
  - story: HR-58
    with: timesheets
    owner: hr
    direction: inbound
    route: GET /persons?pool_user_sub=
    permission: hr:employment:read
    caller: machine (expenses' service client), for the sub in the signed-in person's token
    request: query pool_user_sub
    response: 200 {person_id, bp_id, company_code} | 404 when no person carries that sub
    rule: looks up hr_person.pool_user_sub; returns identity keys only
    status: "hr v4 2026-10-26: one entry per caller, as erp_platform.contract reads with: (was a callers: list); listed for timesheets TS-18"
  - story: HR-58
    with: time-off
    owner: hr
    direction: inbound
    route: GET /persons?pool_user_sub=
    permission: hr:employment:read
    caller: machine (expenses' service client), for the sub in the signed-in person's token
    request: query pool_user_sub
    response: 200 {person_id, bp_id, company_code} | 404 when no person carries that sub
    rule: looks up hr_person.pool_user_sub; returns identity keys only
    status: "hr v4 2026-10-26: one entry per caller, as erp_platform.contract reads with: (was a callers: list); listed for time-off TOF-19"
  - story: HR-59
    with: payments
    owner: hr
    direction: inbound
    route: GET /persons/{person_id}/bank-account?on=
    permission: hr:bank_account:read_for_payout
    caller: machine, payments' service client ONLY; never a person role, never expenses
    request: path person_id; query on (YYYY-MM-DD, the payment date)
    response: 200 {person_id, account_holder, sort_code | null, account_number | null, iban | null, bic | null, valid_from}; 404 when none is held on that date
    rule: reads the kind=bank slice of person_sensitive (its own aggregate, hr_sensitive root) in force on the date; sensitive personal data; every read audited (who, when, which person, which payout) in the action log; no other sensitive kind is reachable by this permission
    status: named seam (v2 draft)
  - story: HR-54
    with: time-off
    owner: time-off
    direction: outbound
    event: hr.person.left
    route: POST /employees/{person_id}/leaver
    request: "{last_day (YYYY-MM-DD), source_ref: \"hr:left:<person_id>:<n>\"} (v4: the body moved out of route, so the route reads as a route; offered by time-off v1; permission tof:leaver:intake, held by hr's service client alone)"
    rule: time-off cancels the leaver's approved leave after the last day and fixes the balance payroll pays or deducts; consumed after commit from the pending Left event; a moved last day sends n+1
    status: named seam (v3 draft)
  - story: HR-60
    with: payroll
    owner: hr
    direction: inbound
    route: POST /payroll-extracts
    permission: hr:payroll_extract:read
    caller: machine (payroll's service client)
    request: "{legal_entity_ref (the company_code), period (YYYY-MM, or YYYY-Www for a weekly schedule)}"
    request_schema:
      - field: legal_entity_ref
        type: company_code
        required: true
      - field: period
        type: string
        required: true
    response: "201 the draft batch {batch_id, state: draft, produced_at, lines: n}; 200 the same, re-produced, while it is a draft; 200 the frozen batch once sent"
    rule: produce_payroll_extract (HR-19) called by a machine; a sent batch is never re-produced
    status: named seam (v3 draft)
  - story: HR-60
    with: payroll
    owner: hr
    direction: inbound
    route: GET /payroll-extracts/{batch_id}
    permission: hr:payroll_extract:read
    caller: machine (payroll's service client)
    request: path batch_id ("<legal_entity_ref>|<period>")
    request_schema:
      - field: batch_id
        type: string
        required: true
        in: path
    response: "200 {batch_id, state, starters: [{person_id, n, start_date, worker_type}], leavers: [{person_id, n, last_day, reason}], lines: [{person_id, n, component, for_period, rate_basis, rate_amount, currency, prorate_from, prorate_to, quantity_minutes, quantity_days, payable_amount, change_kind}], bank_changed: [person_id]}; 404 for a batch never produced"
    rule: the extract as HR-19 defines it; never a freelancer; bank details are never in it (payments reads them, HR-59)
    status: named seam (v3 draft)
  - story: HR-60
    with: payroll
    owner: hr
    direction: inbound
    route: POST /payroll-extracts/{batch_id}/sent
    permission: hr:payroll_extract:mark_sent
    caller: machine (payroll's service client)
    request: "{sent_ref (the pay run id)}"
    request_schema:
      - field: batch_id
        type: string
        required: true
        in: path
      - field: sent_ref
        type: string
        required: true
    response: "200 {batch_id, state: sent, sent_ref}; 200 the same for the same sent_ref; 409 {gate: sent_once, reason, fix} for another"
    rule: mark_extract_sent (HR-19) after payroll's run is approved, from payroll's pending rows; a later change lands in the next batch as a retro line
    status: named seam (v3 draft)
  - story: HR-61
    with: payroll
    owner: hr
    direction: inbound
    route: GET /persons/{person_id}/payroll-identity?on=
    permission: hr:payroll_identity:read
    caller: machine, payroll's service client ONLY; never a person role
    request: path person_id; query on (the pay date)
    request_schema:
      - field: person_id
        type: person_id
        required: true
        in: path
      - field: on
        type: date
        required: true
        in: query
    response: 200 {person_id, legal_first_names, legal_last_name, date_of_birth, ni_number | null, home_address (shared.yaml conventions.address), valid_from}; 404 for a person hr does not hold
    rule: reads the ni_number, date_of_birth and home_address slices of person_sensitive and the legal name; every read audited (who, when, which person, which submission); no bank or other sensitive kind
    status: named seam (v3 draft)
  - story: HR-62
    with: time-off
    owner: hr
    direction: inbound
    route: GET /persons/{person_id}/work-pattern?from=&to=
    permission: hr:work_pattern:read
    caller: machine (the service clients of time-off, timesheets and payroll)
    request: path person_id; query from, to (at most 400 days apart)
    request_schema:
      - field: person_id
        type: person_id
        required: true
        in: path
      - field: from
        type: date
        required: true
        in: query
      - field: to
        type: date
        required: true
        in: query
    response: "200 {person_id, from, to, days: [{date, employed, contracted_minutes, public_holiday (name | null), location_code, holiday_calendar, fte}]}; 422 {gate: bounds} for a longer range"
    rule: derived on read from the assignment's work schedule and the location's holiday_calendar (hr_holiday); never stored; no pay
    status: named seam (v3 draft)
  - story: HR-62
    with: payroll
    owner: hr
    direction: inbound
    route: GET /persons/{person_id}/work-pattern?from=&to=
    permission: hr:work_pattern:read
    caller: machine (the service clients of time-off, timesheets and payroll)
    request: path person_id; query from, to (at most 400 days apart)
    request_schema:
      - field: person_id
        type: person_id
        required: true
        in: path
      - field: from
        type: date
        required: true
        in: query
      - field: to
        type: date
        required: true
        in: query
    response: "200 {person_id, from, to, days: [{date, employed, contracted_minutes, public_holiday (name | null), location_code, holiday_calendar, fte}]}; 422 {gate: bounds} for a longer range"
    rule: derived on read from the assignment's work schedule and the location's holiday_calendar (hr_holiday); never stored; no pay
    status: "hr v4 2026-10-26: one entry per caller, as erp_platform.contract reads with: (was a callers: list); listed for payroll PRL-04"
  - story: HR-62
    with: timesheets
    owner: hr
    direction: inbound
    route: GET /persons/{person_id}/work-pattern?from=&to=
    permission: hr:work_pattern:read
    caller: machine (the service clients of time-off, timesheets and payroll)
    request: path person_id; query from, to (at most 400 days apart)
    request_schema:
      - field: person_id
        type: person_id
        required: true
        in: path
      - field: from
        type: date
        required: true
        in: query
      - field: to
        type: date
        required: true
        in: query
    response: "200 {person_id, from, to, days: [{date, employed, contracted_minutes, public_holiday (name | null), location_code, holiday_calendar, fte}]}; 422 {gate: bounds} for a longer range"
    rule: derived on read from the assignment's work schedule and the location's holiday_calendar (hr_holiday); never stored; no pay
    status: "hr v4 2026-10-26: one entry per caller, as erp_platform.contract reads with: (was a callers: list); listed for timesheets TS-18"
  - story: HR-63
    with: time-off
    owner: hr
    direction: inbound
    route: GET /persons/{person_id}/assignment?on=
    permission: hr:assignment:read
    request: path person_id; query on (YYYY-MM-DD, default today in business_timezone)
    request_schema:
      - field: person_id
        type: person_id
        required: true
        in: path
      - field: on
        type: date
        required: false
        in: query
    response: 200 {person_id, on, employed, company_code, org_unit_id, org_unit_code, team_code, manager_person_id, work_email, pool_user_sub}; employed false with nulls when no engagement covers the date, never a 404 for a person in the caller's companies; 404 for one outside them
    rule: the organisational assignment and work email by person id (SAP organisational assignment plus communication); derived on read; no pay, no sensitive data; scoped to the companies the caller's grant names
    status: added 2026-10-26 (hr v4, seemo's decided answer 2) for time-off TOF-19
  - story: HR-63
    with: expenses
    owner: hr
    direction: inbound
    route: GET /persons/{person_id}/assignment?on=
    permission: hr:assignment:read
    request: path person_id; query on (YYYY-MM-DD, default today in business_timezone)
    request_schema:
      - field: person_id
        type: person_id
        required: true
        in: path
      - field: on
        type: date
        required: false
        in: query
    response: 200 {person_id, on, employed, company_code, org_unit_id, org_unit_code, team_code, manager_person_id, work_email, pool_user_sub}; employed false with nulls when no engagement covers the date, never a 404 for a person in the caller's companies; 404 for one outside them
    rule: the organisational assignment and work email by person id (SAP organisational assignment plus communication); derived on read; no pay, no sensitive data; scoped to the companies the caller's grant names
    status: added 2026-10-26 (hr v4, seemo's decided answer 2) for expenses EXP-19
  - story: HR-63
    with: timesheets
    owner: hr
    direction: inbound
    route: GET /persons/{person_id}/assignment?on=
    permission: hr:assignment:read
    request: path person_id; query on (YYYY-MM-DD, default today in business_timezone)
    request_schema:
      - field: person_id
        type: person_id
        required: true
        in: path
      - field: on
        type: date
        required: false
        in: query
    response: 200 {person_id, on, employed, company_code, org_unit_id, org_unit_code, team_code, manager_person_id, work_email, pool_user_sub}; employed false with nulls when no engagement covers the date, never a 404 for a person in the caller's companies; 404 for one outside them
    rule: the organisational assignment and work email by person id (SAP organisational assignment plus communication); derived on read; no pay, no sensitive data; scoped to the companies the caller's grant names
    status: added 2026-10-26 (hr v4, seemo's decided answer 2) for timesheets TS-18
  - story: HR-63
    with: payroll
    owner: hr
    direction: inbound
    route: GET /persons/{person_id}/assignment?on=
    permission: hr:assignment:read
    request: path person_id; query on (YYYY-MM-DD, default today in business_timezone)
    request_schema:
      - field: person_id
        type: person_id
        required: true
        in: path
      - field: on
        type: date
        required: false
        in: query
    response: 200 {person_id, on, employed, company_code, org_unit_id, org_unit_code, team_code, manager_person_id, work_email, pool_user_sub}; employed false with nulls when no engagement covers the date, never a 404 for a person in the caller's companies; 404 for one outside them
    rule: the organisational assignment and work email by person id (SAP organisational assignment plus communication); derived on read; no pay, no sensitive data; scoped to the companies the caller's grant names
    status: added 2026-10-26 (hr v4, seemo's decided answer 2) for payroll PRL-20
  - story: HR-64
    with: time-off
    owner: hr
    direction: inbound
    route: GET /roster?company_code=&on=&org_unit_code=&manager_person_id=&limit=&offset=
    permission: hr:roster:read
    request: "query company_code, on (YYYY-MM-DD, default today), org_unit_code (optional), manager_person_id (optional: the direct reports of that derived manager on `on`), limit (at most 200), offset"
    request_schema:
      - field: company_code
        type: company_code
        required: true
        in: query
      - field: on
        type: date
        required: false
        in: query
      - field: org_unit_code
        type: string
        required: false
        in: query
      - field: manager_person_id
        type: person_id
        required: false
        in: query
      - field: limit
        type: integer
        required: false
        in: query
      - field: offset
        type: integer
        required: false
        in: query
    response: "200 {company_code, on, people: [{person_id, company_code, org_unit_code, team_code, manager_person_id, work_email, fte, employed_from, employed_to}], next_offset (null on the last page)}; a company outside the caller's scope answers people [] (never another company's people)"
    rule: who is employed on a date, paged by person_id; derived on read; no pay, no sensitive data
    status: added 2026-10-26 (hr v4, seemo's decided answer 2) for time-off TOF-04, TOF-10, TOF-14 (team calendar, year end)
  - story: HR-64
    with: expenses
    owner: hr
    direction: inbound
    route: GET /roster?company_code=&on=&org_unit_code=&manager_person_id=&limit=&offset=
    permission: hr:roster:read
    request: "query company_code, on (YYYY-MM-DD, default today), org_unit_code (optional), manager_person_id (optional: the direct reports of that derived manager on `on`), limit (at most 200), offset"
    request_schema:
      - field: company_code
        type: company_code
        required: true
        in: query
      - field: on
        type: date
        required: false
        in: query
      - field: org_unit_code
        type: string
        required: false
        in: query
      - field: manager_person_id
        type: person_id
        required: false
        in: query
      - field: limit
        type: integer
        required: false
        in: query
      - field: offset
        type: integer
        required: false
        in: query
    response: "200 {company_code, on, people: [{person_id, company_code, org_unit_code, team_code, manager_person_id, work_email, fte, employed_from, employed_to}], next_offset (null on the last page)}; a company outside the caller's scope answers people [] (never another company's people)"
    rule: who is employed on a date, paged by person_id; derived on read; no pay, no sensitive data
    status: added 2026-10-26 (hr v4, seemo's decided answer 2) for expenses EXP-19, EXP-24 (cards, delegates, migration)
  - story: HR-64
    with: timesheets
    owner: hr
    direction: inbound
    route: GET /roster?company_code=&on=&org_unit_code=&manager_person_id=&limit=&offset=
    permission: hr:roster:read
    request: "query company_code, on (YYYY-MM-DD, default today), org_unit_code (optional), manager_person_id (optional: the direct reports of that derived manager on `on`), limit (at most 200), offset"
    request_schema:
      - field: company_code
        type: company_code
        required: true
        in: query
      - field: on
        type: date
        required: false
        in: query
      - field: org_unit_code
        type: string
        required: false
        in: query
      - field: manager_person_id
        type: person_id
        required: false
        in: query
      - field: limit
        type: integer
        required: false
        in: query
      - field: offset
        type: integer
        required: false
        in: query
    response: "200 {company_code, on, people: [{person_id, company_code, org_unit_code, team_code, manager_person_id, work_email, fte, employed_from, employed_to}], next_offset (null on the last page)}; a company outside the caller's scope answers people [] (never another company's people)"
    rule: who is employed on a date, paged by person_id; derived on read; no pay, no sensitive data
    status: added 2026-10-26 (hr v4, seemo's decided answer 2) for timesheets TS-15, TS-22 (reminders, migration)
  - story: HR-64
    with: payroll
    owner: hr
    direction: inbound
    route: GET /roster?company_code=&on=&org_unit_code=&manager_person_id=&limit=&offset=
    permission: hr:roster:read
    request: "query company_code, on (YYYY-MM-DD, default today), org_unit_code (optional), manager_person_id (optional: the direct reports of that derived manager on `on`), limit (at most 200), offset"
    request_schema:
      - field: company_code
        type: company_code
        required: true
        in: query
      - field: on
        type: date
        required: false
        in: query
      - field: org_unit_code
        type: string
        required: false
        in: query
      - field: manager_person_id
        type: person_id
        required: false
        in: query
      - field: limit
        type: integer
        required: false
        in: query
      - field: offset
        type: integer
        required: false
        in: query
    response: "200 {company_code, on, people: [{person_id, company_code, org_unit_code, team_code, manager_person_id, work_email, fte, employed_from, employed_to}], next_offset (null on the last page)}; a company outside the caller's scope answers people [] (never another company's people)"
    rule: who is employed on a date, paged by person_id; derived on read; no pay, no sensitive data
    status: added 2026-10-26 (hr v4, seemo's decided answer 2) for payroll PRL-20
screens:
  - id: my_tasks
    name: My tasks
    stories:
      - HR-03
    actors:
      - assignee
      - manager
      - it
      - finance
      - hr_admin
  - id: new_starter
    name: New starter
    stories:
      - HR-01
    actors:
      - manager
      - hr_admin
  - id: your_details
    name: Your details
    stories:
      - HR-02
    actors:
      - starter
    surface: public
    served_by: the platform's public-link door app (no sign-in pool), never the staff app
    note: "PUBLIC: one form, no navigation, grant SUBMIT; see surfaces below"
  - id: runs
    name: Runs
    stories:
      - HR-04
    actors:
      - hr_admin
      - manager
      - it
  - id: run
    name: Run
    stories:
      - HR-05
      - HR-07
      - HR-08
      - HR-10
      - HR-23
    actors:
      - hr_admin
      - manager
      - it
  - id: leaver
    name: Record a leaver
    stories:
      - HR-06
    actors:
      - manager
      - hr_admin
  - id: action_log
    name: Action log
    stories:
      - HR-09
    actors:
      - it
      - hr_admin
  - id: playbooks
    name: Playbooks
    stories:
      - HR-11
    actors:
      - hr_admin
  - id: org
    name: Org
    stories:
      - HR-12
    actors:
      - hr_admin
      - manager
  - id: person
    name: Person
    stories:
      - HR-14
      - HR-15
      - HR-16
      - HR-17
      - HR-20
      - HR-25
      - HR-26
      - HR-27
    actors:
      - hr_admin
      - manager
      - finance
  - id: sensitive
    name: Sensitive data
    stories:
      - HR-13
    actors:
      - hr_admin
      - finance
    note: a separate screen and separate routes; a manager has no link to it and gets 404 on its routes
  - id: reports
    name: Reports
    stories:
      - HR-18
      - HR-29
    actors:
      - hr_admin
      - manager
      - finance
    note: "v2: the onboarding monitor (HR-29) is a tab here, for hr_admin and managers (hr:run:monitor)"
  - id: payroll
    name: Payroll extract
    stories:
      - HR-19
    actors:
      - finance
  - id: privacy
    name: Privacy
    stories:
      - HR-21
      - HR-22
    actors:
      - hr_admin
  - id: my_record
    name: My record
    stories:
      - HR-24
    actors:
      - employee
  - id: settings
    name: Settings
    stories:
      - HR-28
      - HR-55
    actors:
      - hr_admin
    note: every config_row below lives here
surfaces:
  private:
    app: the composition's staff app (one app, a router per brick), behind the dodil-appid pool; the gateway injects X-Dodil-User
    documents: "the app's service account is the ONLY bucket principal (a bucket-scoped k3.editor, as on crm-demo and the pilot demo). People never touch DataK3 objects: a document is read only through an hr use case that checks its document-class permission (personnel: hr:document:read, pay: hr:pay:read, sensitive: hr:sensitive:read) and STREAMS the bytes. A direct or presigned object link is never handed out, to a screen, an agent or an email."
    screens:
      - my_tasks
      - new_starter
      - runs
      - run
      - leaver
      - action_log
      - playbooks
      - org
      - person
      - sensitive
      - reports
      - payroll
      - privacy
      - my_record
      - settings
  public:
    app: "the platform's public-link door: a SEPARATE app with no sign-in pool (public_invoke true), its own image and its own narrow service account. It holds a token reader and calls hr through a seam with a service identity scoped to one record. It cannot import hr's private use cases, and it holds no Models key and no connector credential (the precedent is an earlier client CRM's public-surface plan)"
    screens:
      - your_details
    stories:
      - HR-02
    token:
      subject: (hr, intake, <person_id>|<n>)
      recipient: "the starter's personal email: ONE token per person, never one per document"
      grants:
        - SUBMIT
      stored: as a hash (the secret never sits in a table); expiring (hr_settings intake validity); revocable as a column with who and when; reissue revokes the previous one
      seen_vs_acted: first_seen_at / last_seen_at / seen_count are kept apart from used_at (submitted), so the board can say 'opened, not submitted'
      audit: one row per use (seen, submitted, refused) with time, IP and user agent, kept by the door
      rate_limited: true
    what_hr_exposes_to_it: read_intake_form (the fields to ask, which are still missing; never a stored sensitive value) and submit_intake (the values and the upload); nothing else
    not_public: everything else, including the starter's first-week plan, which they see in My record once they can sign in
permissions:
  namespace: hr
  catalog:
    - hr:person:read
    - hr:person:write
    - hr:hire:record
    - hr:leave:record
    - hr:event:record
    - hr:pay:read
    - hr:pay:write
    - hr:sensitive:read
    - hr:sensitive:write
    - hr:document:read
    - hr:document:write
    - hr:org:read
    - hr:org:write
    - hr:run:read
    - hr:run:preview
    - hr:run:reschedule
    - hr:run:cancel
    - hr:run:tick
    - hr:run:monitor
    - hr:task:read
    - hr:task:complete
    - hr:step:approve
    - hr:draft:approve
    - hr:action:retry
    - hr:action_log:read
    - hr:config:write
    - hr:offboarding:policy
    - hr:report:read
    - hr:employment:read
    - hr:manager:read
    - hr:bank_account:read_for_payout
    - hr:work_pattern:read
    - hr:assignment:read
    - hr:roster:read
    - hr:payroll_extract:read
    - hr:payroll_extract:mark_sent
    - hr:payroll_identity:read
    - hr:privacy:manage
    - hr:pool:invite
    - hr:self:read
    - hr:clock:set
  row_visibility:
    rule: "hr_admin and finance see every person; a manager sees the people whose derived manager they are (ManagerOf on today's or a future slice, walking down from every chief position they hold) and their runs, pay and personnel/pay documents, never sensitive data; IT sees people with an open IT step; an assignee sees only steps of groups they belong to (a pool role, the derived manager, or a run party); an employee sees only themselves; sensitive data needs hr:sensitive:read, which only hr_admin and finance hold. v4 (2026-10-26, seemo's decided answer 2): every hr grant is scoped per company (SAP's structural authorisation by company code): a grant names the companies it covers (company_codes on the role row; none named = every company, for a single-company customer), an hr_admin or finance of UK01 sees UK01's people only, and a service client's reads (HR-56..64) answer only people of the companies its grant names"
    enforced: inside every use case from `caller` (BRICKS.md); the Sensitive repository has no join path from Person; the same rule serves the API and the MCP door
    not_found_not_forbidden: true
config_rows:
  - table: hr_playbook
    changes: "your checklists per worker type, event type, reason and team, versioned (v2: employee-retirement, for the reason retirement)"
  - table: hr_playbook_step
    changes: "each step: what, which group, when (anchor, offset in days or working days, time), what it depends on, approvals, conditions, and (v2) the outcomes completing it must record"
  - table: hr_org_unit
    changes: your teams and departments, who leads each (the chief position), dated
  - table: hr_unit_access
    changes: which groups, chat spaces and shared folders each team gets
  - table: hr_job
    changes: your job catalogue and families
  - table: hr_location
    changes: offices, their country, timezone and holiday calendar
  - table: hr_work_schedule
    changes: working patterns (37.5 hours Mon–Fri, part-time patterns) and the full-time base
  - table: hr_holiday
    changes: public holidays per calendar (the pack loads them; you can add company days)
  - table: hr_worker_type
    changes: "employee, freelancer (sole trader / via a company), intern…: payroll or supplier, which partner roles"
  - table: hr_event_type
    changes: your names for the personnel events, each mapped to one of the seven kinds
  - table: hr_event_reason
    changes: leave reasons, pay-change reasons, transfer reasons
  - table: hr_infogroup
    changes: what each event's form asks for
  - table: hr_rate_basis
    changes: hour, day, month, year, fixed fee, and their labels
  - table: hr_pay_component_type
    changes: allowances and extras (≈ wage types), and which worker types they apply to
  - table: hr_pay_grade
    changes: optional pay bands per job, used by the 'rate outside band' condition
  - table: hr_responsible_group
    changes: "who does what: manager, IT, finance, buddy, HR, director, and how each is resolved"
  - table: hr_document_type
    changes: document types, their access class (personnel / pay / sensitive), expiry and retention category
  - table: hr_intake_field
    changes: what the starter is asked for, per worker type and country, and which fields are required
  - table: hr_draft_instruction
    changes: the instructions for each AI draft (welcome email, handover, leaver letter), and the fields it may use
  - table: hr_retention_rule
    changes: how long each kind of data is kept after someone leaves, and whether it is purged or anonymised
  - table: hr_setting_row
    changes: "v2 (HR-55): dated policy settings the owner sets (hr:offboarding:policy), rows only ever added — from tomorrow, the first row of a key and scope may start today, never earlier — so the table is the audit trail (set_by, set_at, note); scope '' is the default, a leave reason overrides it"
    settings:
      - key: offboarding.revoke_access_at
        type: str
        default: last_day_end
        scope: "'' or a leave reason (dismissal)"
        changes: "last_day_end | immediate: when a leaver's ERP sign-in is revoked (identity.revoke_app_user) — at the end of the last day (17:30 in business_timezone, after the access-removal approval) or as soon as the leaver is recorded and the access removal approved; read on the business date the leaver is recorded, a run already made keeps its timing"
  - table: hr_settings
    changes: timezone, intake link validity, chasing cadence, max action attempts before IT, warning days, AI model name, rounding mode, and per legal entity the UK client size for IR35 (passed to contracts, which keeps no copy)
in_code_not_rows:
  - "the seven domain event kinds and what each writes and starts: rehire never offboards; conversion is one run that keeps access"
  - "the slice rules: delimit on insert, corrections supersede, TC1 per the entity table, 'current' derived"
  - person_id derivation, run_id derivation and idempotency_key = <run_id>|<step_no>
  - the step kinds and how each executes; no provider = the same step as a manual task with the exact input (rule 8)
  - that a destructive step needs an approval, and delete waits for a completed transfer
  - that the Sensitive aggregate is separate and never loaded by a manager-facing use case
  - that only name and work contact go to the business partner
  - that documents are streamed by a use case after its class permission check; no object URL is ever handed out
  - that a draft is never given a sensitive field, and a failed draft is a manual task
  - that dry_run writes, claims and sends nothing
  - "that money is exact: rates NUMERIC(19,4), rounded once at the payable line; no float; no stored hourly rate for salaried staff"
  - that freelancer amounts never go to the payroll extract, and a sent batch is frozen
  - "the demo clock: the route exists only when HR_DEMO_CLOCK=enabled, and the app refuses to start with it set in a live deploy (DODIL_ENV=live)"
  - "the step condition specifications (worker_type_is, via_company, rate_outside_band, client_size_is, reason_is (v2), pack_requires): rows choose them, code defines them"
  - "v2: that a step with outcomes is done only with one of them, and a done step never changes its answer"
tests:
  acceptance: one per story id above, named for it (test_hr_01_double_submit_is_one_run, …), in tests/test_rules.py and tests/test_doors.py
  access:
    - a manager token gets 404 on EVERY sensitive route (show_sensitive, record_sensitive, the sensitive document download) — including for their own reports — through the API and through MCP
    - the MCP tool list for a manager-only caller contains no tool that returns sensitive data
    - a manager opening a person outside their line gets 404, not 403
    - IT cannot read pay or sensitive data (404); finance cannot record a hire (403 without the permission)
    - an assignee opening a step of another group gets 404
    - an employee opening another person's record gets 404
    - a starter's intake token reaches only its own intake; a reissued or expired token is refused by the door
    - the demo clock route does not exist when HR_DEMO_CLOCK is unset, and the app refuses to start with it set and DODIL_ENV=live
    - a request with no gateway identity is rejected; a forged X-Dodil-User header is stripped at the edge
  invariants:
    - a double-submitted hire yields one person, one engagement and one run
    - a tick run twice invokes each capability once per step
    - moving a date re-times only steps not done; done steps keep due_at and result
    - an identity.delete_user step never runs without an approval and before drive.transfer_status = completed
    - dry_run writes no row, claims no key and sends nothing
    - no gap and no overlap in a TC1 table after any write (property test over random event sequences)
    - a correction keeps the superseded slice readable
    - a rehire creates engagement n+1 and no offboarding run
    - a conversion creates exactly one run and no access-removal step
    - an open run keeps its playbook version after the playbook changes
    - 13.3333 an hour for 3 days of 150 minutes is 100.00 (rounded once at the line), never 99.99 (rounded per day)
    - a payroll batch never contains a freelancer engagement; a sent batch never changes
    - the business partner never receives a personal email, phone, address, NI number, bank detail or right-to-work field
    - the draft adapter is never given a field from the Sensitive aggregate
    - a capability with no provider produces a manual task whose input equals what the provider would have been sent
    - "v2: the ERP sign-in is revoked once per offboarding, never before the access-removal approval and never before last day 17:30"
    - "v2: the outplacement offer exists only on a redundancy, and is done only with the outcome accepted or declined"
    - "v2: the onboarding monitor counts days on the business date in business_timezone, and its statements do not grow with the number of runs"
  live: "scripts/live_check.py: the deployed brick against a dev bucket: a hire, a tick, a manual task, a 404 for a manager on sensitive"
  scenarios:
    - id: SC-HR-01
      name: future-dated hire
      stories:
        - HR-01
        - HR-38
        - HR-39
      given: today is 2026-10-17; no person with personal email anna@example.org
      when: a manager records a hire starting 2026-11-02
      then: person, engagement 1 (status future), assignment slice valid_from 2026-11-02, and an onboarding run exist today; headcount on 2026-10-31 excludes her and on 2026-11-02 includes her; her business partner gets no employee role until the 2026-11-02 tick, and a second tick that day changes nothing
    - id: SC-HR-02
      name: a change versus a correction
      stories:
        - HR-14
        - HR-39
      given: a pay slice 42,000.0000 GBP/year from 2026-03-01
      when: (a) a PayChanged to 45,000.0000 from 2026-04-01; (b) then a correction of the 2026-04-01 slice to 45,500.0000
      then: (a) the March slice is delimited at 2026-03-31 and a new slice opens 2026-04-01; (b) a new 2026-04-01 slice supersedes the first (superseded_by set, still readable); "what did we believe on 2026-04-15 before the correction" returns 45,000.0000; TC1 holds after both
    - id: SC-HR-03
      name: retro pay after the batch was sent
      stories:
        - HR-14
        - HR-19
      given: the November 2026 batch for GH-UK is sent
      when: on 2026-12-10 a PayChanged effective 2026-11-01 is recorded
      then: the November batch is unchanged; the December batch carries a retro line with for_period 2026-11 and its proration dates; no line appears twice across batches
    - id: SC-HR-04
      name: mid-month transfer
      stories:
        - HR-17
        - HR-18
        - HR-19
      given: a Designer in Studio since 2026-01-05
      when: a Transferred event to Campaigns from 2026-11-16 is recorded on 2026-11-10
      then: the Studio slice ends 2026-11-15 and the Campaigns slice starts 2026-11-16; headcount counts her in Studio on 2026-11-15 and in Campaigns on 2026-11-16; the November extract carries both slices with their proration dates; the change run's access delta is due on 2026-11-16, not on the 10th
    - id: SC-HR-05
      name: a reorganisation changes the derived manager
      stories:
        - HR-12
        - HR-39
      given: Studio (chief held by Lena) under Operations (chief held by Omar); Ben assigned to Studio
      when: Lena leaves on 2026-11-30 and Studio has no chief from 2026-12-01
      then: ManagerOf(Ben, 2026-11-30) is Lena and ManagerOf(Ben, 2026-12-01) is Omar (walking up), with no write to Ben's record; Omar sees Ben's runs from 2026-12-01 and not before; a manager override on Ben's assignment would win over both
    - id: SC-HR-06
      name: leave, then rehire
      stories:
        - HR-06
        - HR-15
      given: an employee on engagement 1
      when: a Left event (last day 2026-11-30) and, the same afternoon, a Rehired event starting 2026-12-01
      then: engagement 1 ends 2026-11-30 and engagement 2 starts 2026-12-01; one offboarding run (for the Left) and one onboarding run (rehire playbook) exist; the rehire creates no offboarding run; a rehire starting on 2026-11-30 instead is refused ("engagement 1 is still active on 30 Nov; start the new one on 1 Dec")
    - id: SC-HR-07
      name: freelancer converted to employee
      stories:
        - HR-16
        - HR-50
      given: a sole-trader freelancer on engagement 1 with an account and two groups
      when: a Converted event effective 2026-12-01
      then: engagement 1 ends 2026-11-30 (reason converted), engagement 2 (employee) starts 2026-12-01, in one transaction; exactly one conversion run; no suspend/remove/delete step anywhere; the business partner loses worker and supplier and gains employee on 2026-12-01; the November extract has no line for engagement 1
    - id: SC-HR-08
      name: two admins change the same person at once
      stories:
        - HR-14
      given: two HR admins open the same person
      when: both save a different pay slice at the same moment
      then: the repository's version check on save (platform work H2b) lets one save commit; the other is refused 409 "changed since you opened it" and nothing of it is written; TC1 holds; retrying after a reload succeeds as a normal change. The same holds on the Sensitive root (hr_sensitive.version)
    - id: SC-HR-09
      name: no provider wired
      stories:
        - HR-31
        - HR-36
        - HR-03
      given: a composition mapping no provider to identity.provision_user
      when: the account step falls due
      then: a manual task for IT carrying capability identity.provision_user, the exact validated input (given_name, family_name, primary_email, org_unit…) and the plan in words; IT marks it done with provider_ref and the work email; the email is written back as a person-detail slice; wiring a provider later and replaying the same playbook on a new starter makes the step automatic with no playbook change
    - id: SC-HR-10
      name: provider failing
      stories:
        - HR-36
      given: a provider that answers failed retryable=true three times, with max attempts 3
      when: three ticks pass
      then: three attempts in the action log, backoff between them, then a manual task for IT with the provider's message in words; the step is not done and the run shows "stuck"
    - id: SC-HR-11
      name: provider needs a connection
      stories:
        - HR-36
      given: a provider that answers connection_required
      when: the step falls due
      then: a manual task at once, naming what is missing ("no Workspace connection; create the account by hand or connect the provider"); no retries counted; a later tick after the connection exists does not double-act (the manual task, once done, is terminal)
    - id: SC-HR-12
      name: provider still working
      stories:
        - HR-35
        - HR-36
      given: drive.transfer_status answers in_progress for two ticks, then completed
      when: the delete step is approved and due
      then: identity.delete_user is called only after completed; in_progress never counts as a failure
    - id: SC-HR-13
      name: approvals pending, declined, timed out
      stories:
        - HR-07
        - HR-37
      given: three runs with an approval before identity.delete_user
      when: one is approved, one is declined with a reason, one is never answered
      then: 'approved: delete runs when due; declined: delete is cancelled and the reason is in the run log; unanswered: the approver group is chased per cadence and after the maximum a task goes to HR ("approval overdue"); the delete never runs by timeout'
    - id: SC-HR-14
      name: daylight saving
      stories:
        - HR-30
        - HR-31
        - HR-34
      given: org timezone Europe/London; British Summer Time ends on 2026-10-25
      when: a start on Wednesday 2026-10-28 with the account step at start −3 working days 09:00, and a last day on Friday 2026-10-30 with removal at 17:30
      then: the account step is due 2026-10-23T08:00Z (09:00 BST); the removal is due 2026-10-30T17:30Z (17:30 GMT); both stay 09:00 and 17:30 local after the change
    - id: SC-HR-15
      name: leap day and month end
      stories:
        - HR-14
        - HR-19
      given: a pay slice starting 2028-02-29, and a leaver whose last day is 2028-02-29
      when: the slices are written and the February 2028 extract is produced
      then: the previous slice ends 2028-02-28; the leaver's pay is delimited at 2028-03-01; the extract carries prorate_to 2028-02-29; no slice has a gap on 2028-02-29
    - id: SC-HR-16
      name: proration inputs and rounding once
      stories:
        - HR-19
      given: an hourly rate of 13.3333 GBP and, from the time brick, 3 days of 150 minutes in a period
      when: the payable line is computed
      then: 13.3333 × 450 / 60 = 99.99975, rounded once half-up to 100.00; rounding per day would give 99.99, and the test asserts 100.00
    - id: SC-HR-17
      name: retention purge
      stories:
        - HR-40
      given: a retention rule "bank details, purge 12 months after the engagement ends", and a leaver who ended 13 months ago
      when: the daily sweep runs, twice
      then: the bank slices are purged, one retention-log row is written per category, the second run writes nothing; a leaver who ended 11 months ago is untouched
    - id: SC-HR-18
      name: subject-access export
      stories:
        - HR-21
      given: a former freelancer with two engagements, a correction, sensitive data and documents
      when: HR exports their data
      then: the archive contains every slice including superseded ones, every event, the sensitive data, documents, the run steps naming them and their business-partner fields; the request shows its due date one month from receipt; the export is logged
    - id: SC-HR-19
      name: erasure with a legal hold
      stories:
        - HR-22
      given: an erasure request, and a retention rule holding payroll records on a legal-obligation basis
      when: HR applies it
      then: the categories without a hold are erased or anonymised, the payroll category is kept with its basis recorded, and the business partner's person fields are anonymised through the seam
    - id: SC-HR-20
      name: every role probes every forbidden operation
      stories:
        - HR-13
        - HR-24
      given: one caller per role (manager, it, finance, assignee, employee, a starter token, no identity)
      when: each calls every use case it does not hold, and every route for a row outside its visibility
      then: a missing permission is 403; a row outside visibility is 404, never 403. In particular, a manager gets 404 on show_sensitive, record_sensitive and every sensitive document download, for their own reports too, through the API and MCP. IT gets 404 on pay and sensitive data, and an employee on anyone else. A starter token reaches nothing but its own intake, and no identity is rejected at the gateway. The matrix is generated from the permission catalog × the actors, so a new use case cannot slip through untested.
    - id: SC-HR-21
      name: double submits everywhere
      stories:
        - HR-01
        - HR-05
        - HR-07
        - HR-30
      given: a hire form, a draft approval, a step approval and a tick
      when: each is sent twice, including two ticks running concurrently
      then: one person, one run, one approval, one capability call per step (the second concurrent claim of <run_id>|<step_no> is rejected 23505 and skipped)
    - id: SC-HR-22
      name: intake link lifecycle
      stories:
        - HR-02
        - HR-37
        - HR-53
      given: an intake link issued with a 7-day validity
      when: the starter opens it (seen), submits half, is chased, HR reissues, the old link is used, the new link completes it
      then: seen and submitted are recorded apart; the chase goes once per slot; the old link is refused after the reissue; the manager's view shows field names complete or missing and never a value; the right-to-work upload lands in the Sensitive aggregate
    - id: SC-HR-23
      name: the clock through a whole onboarding
      stories:
        - HR-01
        - HR-02
        - HR-30
        - HR-31
        - HR-32
        - HR-33
        - HR-51
      given: demo clock enabled in-process; a freelance motion designer hired on Monday 2026-10-19 to start Monday 2026-11-02
      when: the clock is advanced to each anchor in turn (run created, intake chase +2 working days, contract signed, start −3 working days 09:00, start 09:00, start +1 working day 10:00, start +4 working days)
      then: at each instant exactly the steps whose due_at has passed and whose dependencies are done appear as due, the rest do not; with no providers each action is a manual task with its exact input; at the end the run is done (derived); the same sequence against a live dev bucket is run without the clock, by recording the hire with dates relative to today
    - id: SC-HR-24
      name: moving a date with steps done
      stories:
        - HR-08
      given: an onboarding run with steps 1–3 done and 4–12 pending, start 2026-11-02
      when: the start moves to 2026-11-09
      then: steps 4–12 are re-timed, steps 1–3 keep due_at and results, the run log records who moved it from 2026-11-02 to 2026-11-09 and when
    - id: SC-HR-25
      name: playbook edited while runs are open
      stories:
        - HR-11
      given: two open runs on playbook version 3
      when: version 4 adds a step and removes another
      then: the open runs are unchanged; a run created afterwards uses version 4; saving a version whose delete step has no approval is refused in words
    - id: SC-HR-26
      name: a run cancelled after actions were done
      stories:
        - HR-23
      given: an onboarding run where provision_user and one add_member are done
      when: HR cancels it
      then: pending steps are cancelled and two reversal tasks (suspend the account, remove from the group) are created; nothing is reversed automatically
    - id: SC-HR-27
      name: the business partner receives nothing private
      stories:
        - HR-50
      given: a person with personal email, phone, address, NI number, bank and right-to-work evidence
      when: every sync path runs (hire, detail change, work email written back, conversion, anonymisation)
      then: the bp payload in each call contains only legal and preferred name, work email and work phone, roles and the works_for edge
    - id: SC-HR-28
      name: a company freelancer
      stories:
        - HR-01
        - HR-50
        - HR-27
      given: a freelancer via Studio Nine Ltd, at a client set as medium or large
      when: the hire is recorded
      then: the company is created or reused as an organisation partner with the supplier role, the person's partner has worker (not supplier), works_for links them, supplier_bp_id is on the engagement, and the contract step is blocked until the status determination is recorded
    - id: SC-HR-32
      name: employee documents by access class
      stories:
        - HR-20
        - HR-13
      given: a starter in a manager's line; HR files an NDA (personnel) and a right-to-work copy (sensitive)
      when: the manager lists and opens the starter's documents; HR and finance open the sensitive copy
      then: each type decides its class; the manager's list holds only the NDA, which is streamed (never a link); the sensitive copy is 404 for the manager when asked for by id; HR sees both, HR and finance open it. Proves Odoo Employees parity employees-05 (erp-roadmap parity/odoo/employees.yaml)
scale:
  reads: "the tables reader serves 16 concurrent reads; the wide reads are the run board, My tasks and the headcount report: compute derived state in the query and page the history"
  hot_paths:
    - the tick's due-step query (due_at ≤ now, state pending)
    - ManagerOf for row visibility (cache per request)
    - headcount over slices for a period
  workers: "the clock: one always-on worker pinned warm (--reserved 1 --max-replicas 1) calling run_due_steps, or an external scheduler"
  volumes: hundreds to a few thousand people and tens of runs a month; a Person aggregate loads all its slices, which stays small for decades of history
platform_constraints:
  - constraint: There is no server-side scheduler.
    today: one tick (run_due_steps) driven by an always-on worker or an external clock; every job above runs inside it
  - constraint: erp_platform.money is 2-decimal; rates need 4.
    today: the platform adds a Rate type (NUMERIC(19,4)) before hr is built; until then nothing in hr may route a rate through Money
  - constraint: No read-your-writes inside an open transaction.
    today: a personnel event commits first; run expansion and the bp sync read it back in a later transaction
customer_varies:
  - question: Do your people have staff numbers?
    changes: person_key (staff number, or the personal email)
    typical:
      small_agency: no staff numbers; the personal email identifies the starter until payroll assigns one
      with_a_payroll_provider: the payroll id becomes the staff number from the first payroll run
      warning: the key is fixed when the person is created; a staff number given later is stored, not re-keyed
  - question: Where do the people you take on work, which countries?
    changes: which localisation pack applies (intake fields, document types, the right-to-work step, notice checks, public holidays)
  - question: For people working in the UK, how do you check right to work, and when?
    changes: the UK pack's right-to-work step, its gate before day one, follow-up checks for time-limited permission, and retention of the copies
    standard: "Immigration, Asylum and Nationality Act 2006 s.15 (civil penalty for employing someone without the right to work) and the statutory excuse established by the checks the Home Office prescribes, described in the Home Office guidance \"An employer's guide to right to work checks\": a manual document check, a check through a certified identity service provider (British and Irish citizens with a valid passport), or the Home Office online check (share code), done BEFORE employment starts, with a follow-up check before time-limited permission ends. The guide asks for copies to be kept for the employment and two years after. Confirm against the edition in force: it changes."
    typical:
      employees: checked in the first week before the start, from the evidence uploaded at intake
      freelancers: often not checked, on the basis that they are self-employed; ask your adviser, this is not a rule we can give
  - question: Must the contract be signed before the first day?
    changes: the contract step's timing and the gate before day-one steps
    standard: "Employment Rights Act 1996 s.1 (as amended from 6 April 2020): employees and workers are entitled to a written statement of particulars, most of it on or before the first day of work. Which particulars may follow later is in s.1–s.2; read them with your adviser."
  - question: Do you engage freelancers through their own limited companies, and how big is your business?
    changes: the UK pack's status-determination record and the condition that blocks the contract step without it
    standard: "Income Tax (Earnings and Pensions) Act 2003, Part 2 Chapter 10 (off-payroll working): from 6 April 2021 a medium or large private-sector client decides the worker's status and gives a status determination statement with its reasons; a small client (Companies Act 2006 size thresholds) does not, and the worker's own company decides under Chapter 8. The module records the determination; it does not make it."
  - question: How much notice do you give and expect?
    changes: the UK pack's notice check on Left events
    standard: "Employment Rights Act 1996 s.86: at least one week after one month's employment, one week per complete year from two years up to twelve weeks; at least one week from the employee. A contract may give more."
  - question: When should access go when someone leaves?
    changes: the offboarding playbook's timing per reason
    typical:
      resignation_or_end_of_contract: at the end of the last day (e.g. 17:30), deletion after about 30 days with an approval
      dismissal: immediately, at the time of the meeting
      warning: deletion is irreversible after the vendor's grace period; keep it behind an approval whatever else changes
  - question: Should managers see the pay of their people?
    changes: who holds hr:pay:read (and so the pay-bearing documents, such as the signed contract)
    typical:
      small_business: yes, they set it
      larger_business: no; pay goes through HR and a manager sees the band
  - question: How long do you keep each kind of data after someone leaves?
    changes: hr_retention_rule
    standard: "UK GDPR Art. 5(1)(e) (storage limitation: no longer than necessary; no fixed period is given), Art. 15 (right of access, answered within one month under Art. 12(3)), Art. 17 (erasure, with the exceptions in Art. 17(3), such as a legal obligation to keep)."
    typical:
      payroll_and_tax: several years after the tax year it relates to, set with the payroll provider
      unsuccessful_or_withdrawn_starters: months, not years
      warning: a leaver's bank details kept for years "just in case" is the common finding in an audit
  - question: Do your checklists count calendar days or working days?
    changes: each timing rule's offset unit, and which holiday calendar the location uses
  - question: Who signs contracts on your side, and who approves anything off-template?
    changes: the responsible group for the company signer and the approval group before the contract step (contracts holds the template rules)
  - question: May we draft the welcome email, the handover and the leaver letter with AI?
    changes: whether draft steps exist in your playbooks (each one degrades to a manual task anyway)
  - question: When you make someone redundant, do you offer outplacement support, and who may see whether they took it?
    changes: "the offer_outplacement step (HR-42): kept, removed or re-timed; who sees its outcome"
    default: offered by HR two working days after the leave is recorded; the outcome is seen by whoever sees the step (HR, and the person's manager through the run). v2 DEFAULT, to confirm
    typical:
      small_business: an offer of a few career-transition sessions, often through a provider
      larger_business: a provider contract; the outcome seen by HR only
      warning: the outcome says something about a person being made redundant; if managers should not see it, the step needs its own visibility, which is a change, not a row
  - question: What happens when someone retires?
    changes: "the employee-retirement playbook (HR-43): the pension notice, the knowledge handover, the long-service recognition and their timing"
    default: pension scheme told 20 working days before the last day (finance), handover sessions 5 days before (manager), recognition 2 days before (manager). v2 DEFAULT, to confirm
  - question: When should a leaver lose their sign-in to this ERP?
    changes: "offboarding.revoke_access_at (HR-55): last_day_end or immediate, per leave reason; a dismissal usually moves it to the meeting (immediate)"
    default: "last_day_end for every reason: with the rest of the access, last day 17:30 in business_timezone, after the access-removal approval. v2 DEFAULT, to confirm"
localisation_packs:
  shape: A pack is code plus seed rows, registered by country code. It contributes intake fields, sensitive kinds, document types, compliance-record kinds, playbook step templates (with conditions), holiday calendar rows, and warnings evaluated by domain code. A country with no pack gets none of it, and the core works unchanged. The pack RECORDS decisions and evidence; it never makes a legal determination.
  gb:
    intake_fields:
      - home_address
      - ni_number
      - bank (account name
      - sort code
      - account number)
      - emergency_contact
      - right_to_work_evidence
      - vat_number (freelancer via a company)
      - company_number (freelancer via a company)
    compliance_records:
      - right_to_work_check
      - status_determination
      - written_statement_given
    steps:
      - right-to-work check before the start (HR-26)
      - status determination before a company freelancer's contract is sent (HR-27, condition pack_requires + via_company + client not small)
      - written statement in the employee's contract before day one
    warnings:
      - last day gives less than the statutory minimum notice (s.86)
      - a time-limited right to work ending within N days (HR-41)
    holidays: bank-holiday rows for England and Wales, Scotland and Northern Ireland loaded from the published list, never typed from memory
    citations: see customer_varies; every rule names its source, and anything we cannot cite stays a question
extension_points:
  - name: position_control
    what: budgets and approved headcount per position; positions are already optional per unit, so switching it on needs no migration
  - name: pay_scales
    what: pay scale type/area/group/level and progression; hr_pay_grade is the hook
  - name: absence
    what: a separate brick for holiday entitlement, bookings and quotas, reading the work schedule and holiday calendar
  - name: time
    what: a time brick that supplies approved minutes or days per engagement × period × component; hr_payroll_line.quantity_* is where they land, and the payable amount is rounded once there
  - name: concurrent_employment
    what: n active engagements per person; the model allows it, v1 refuses a second active one
  - name: multiple_legal_entities
    what: legal_entity_ref is on every engagement and org from day 1; v1 runs one
  - name: performance
    what: reviews, goals, succession
  - name: ownership_for_handover
    what: a capability each module could provide ('what does this person own here?', e.g. CRM accounts, projects) so the handover draft lists them; v1 lists what hr knows
  - name: equipment
    what: returnable assets (laptops) as configuration items, owned by itsm; v1 is a task step
  - name: expenses_supplier_role
    what: the supplier role on an employee's partner for expense reimbursement, when the expenses module arrives
  - name: freelancer_self_billing
    what: supplier invoices or self-bills against the supplier partner, in purchasing/payables; never the payroll extract
reference:
  repos:
    - name: brick-hr
      role: brick
      https: https://git.dodil.io/dodil/erp-brick-hr.git
      ssh: git@git.dodil.io:dodil/erp-brick-hr.git
      tag: v0.5.3
      read_first:
        - README.md
        - AGENTS.md
      clone: git clone --depth 1 --branch v0.5.3 https://git.dodil.io/dodil/erp-brick-hr.git
    - name: brick-business-partner
      role: brick
      https: https://git.dodil.io/dodil/erp-brick-business-partner.git
      ssh: git@git.dodil.io:dodil/erp-brick-business-partner.git
      tag: v0.3.2
      read_first:
        - README.md
        - AGENTS.md
      clone: git clone --depth 1 --branch v0.3.2 https://git.dodil.io/dodil/erp-brick-business-partner.git
    - name: erp-platform
      role: platform
      https: https://git.dodil.io/dodil/erp-platform.git
      ssh: git@git.dodil.io:dodil/erp-platform.git
      tag: v0.8.2
      read_first:
        - README.md
        - AGENTS.md
      clone: git clone --depth 1 --branch v0.8.2 https://git.dodil.io/dodil/erp-platform.git
  packages: []
  contracts: []
  build_guide: null
  known_gaps:
    - "not deployed: it has not run behind the gateway for a real person, so the self-check through ignite invoke and a sign-in per role are still to do"
    - "no screen: API and MCP only"
    - "absence and time are extension points, not built: hourly and daily payable amounts need the time brick's quantities, so v1 lines for those bases carry the rate and no amount (v3: the time-off and timesheets modules are specified, wave 4; payroll reads their quantities itself)"
    - "concurrent employment: the model allows it, v1 refuses a second active engagement"
    - one localisation pack only (gb)
    - documents are bytes in hr_object_chunk in the bucket until the platform has an object-store helper
    - "payroll calculation is out of scope here: the extract hands rates, slices and proration dates to a payroll provider, or (v3) to the payroll module, which reads it through HR-60"
    - freelancer invoices and self-bills are not here (purchasing/payables)
    - "v2: identity.revoke_app_user is hr's own capability contract (brick-hr capabilities.local.yaml) until erp-platform's capabilities.yaml has it; no provider brick for it exists yet, so it is a manual task today"
    - "v2: the open-task hand-over and the expenses settlement on a Left event (HR-54) are named seams, not built"
lifecycle: https://blog.dodil.io/modules/lifecycle.md
module_pattern: https://blog.dodil.io/modules/pattern.md
design_template: https://blog.dodil.io/modules/template.md
