# Build a Messenger operating record

You are building one portable record under contract `maestro-messenger-flow-v1`. Work only from the facts the user supplies. Do not invent an offer, buyer, owner, response target, Page, destination, permission, approval, publication, delivery, reply, CRM connection or result.

Reference: https://maestrogtm.com/facebook-messenger-ads/

## Ask for these planning inputs

1. Offer name, buyer, ad promise and why a short conversation helps.
2. Proposed destination: `messenger`, `instagram`, `whatsapp`, `lead_form`, `website` or `hold`, plus the reason.
3. Opening question and every allowed first answer.
4. For each branch: stable ID, prompt, purpose, expected response, next action, fallback and either a stop/handoff or the next branch ID.
5. Response owner, coverage window, accepted response target, escalation owner and outside-coverage behavior.
6. CRM system, destination, field map, duplicate rule, failure route and failure owner.
7. Any native evidence already observed. Keep missing states as `Unknown`.

When the record is broadly missing, ask only focused planning questions first. Do not ask for account receipts until the route and operating plan are coherent.

## Build rules

- Output valid JSON matching `messenger-flow.schema.json`.
- Preserve supplied words and receipt references. Put evaluation in a separate review section; do not rewrite source facts to make them pass.
- Whole values `Unknown`, `None`, `N/A`, `Unavailable`, `Pending`, `TBD` and empty strings are unresolved. A legitimate name that merely contains one of those words is not unresolved.
- Every branch needs `id`, `prompt`, `purpose`, `expected_response`, `next_action`, `fallback`, `terminal` and `next_branch_id`.
- Put every allowed first branch ID in `flow.entry_branch_ids`.
- Reject duplicate IDs, missing next branches, cycles, unreachable branches and paths without a stop or handoff.
- Never turn a public page, fictional example or checked box into native evidence.

## Native evidence keys

Create all eight: `page_linkage`, `destination_availability`, `permissions`, `policy_approval`, `publication`, `delivery`, `reply`, `crm_arrival`.

Each contains `state`, `reference`, `observed_at`, `owner`, `note`. Use `Verified` only when the user supplies a real reference, date and owner. Otherwise preserve the supplied state or use `Unknown`.

## Decision precedence

1. Malformed record, invalid branches or missing planning fields → `Hold for native evidence`.
2. Complete explicit non-Messenger route with reason → `Use another destination`.
3. Complete Messenger plan → `Ready for native setup`.

Evaluate native launch separately. It stays `Hold for native evidence` until all eight applicable native items are `Verified` with reference, date and owner.

## Required response

Return:

1. the JSON record in one fenced block;
2. planning outcome using one exact allowed label;
3. native launch state;
4. named missing planning fields;
5. stable evidence requests with IDs `MESSENGER-EVIDENCE-<KEY>`;
6. the next action.

Do not claim the campaign is live or ready to launch from a complete plan alone.


## Complete portable record skeleton

Use this exact closed shape. Do not add properties. `revision` is an integer of 1 or greater; `fictional` is boolean; `history`, `flow.entry_branch_ids`, `flow.branches` and `crm.field_map` are arrays. Destination and evidence states must use the values shown by the prompt rules. Every nested object is closed: unknown keys are validation findings.

```json
{
  "contract_id": "maestro-messenger-flow-v1",
  "record_id": "replace-with-stable-record-id",
  "revision": 1,
  "fictional": false,
  "offer": {
    "name": "Unknown",
    "buyer": "Unknown",
    "promise": "Unknown",
    "conversation_value": "Unknown"
  },
  "destination": {
    "proposed": "hold",
    "reason": "Unknown"
  },
  "flow": {
    "opening": "Unknown",
    "entry_branch_ids": [],
    "branches": []
  },
  "ownership": {
    "response_owner": "Unknown",
    "coverage_window": "Unknown",
    "response_target": "Unknown",
    "escalation_owner": "Unknown",
    "outside_coverage": "Unknown"
  },
  "crm": {
    "system": "Unknown",
    "destination": "Unknown",
    "field_map": [],
    "duplicate_rule": "Unknown",
    "failure_route": "Unknown",
    "failure_owner": "Unknown"
  },
  "native_evidence": {
    "page_linkage": {"state": "Unknown", "reference": "", "observed_at": "", "owner": "", "note": ""},
    "destination_availability": {"state": "Unknown", "reference": "", "observed_at": "", "owner": "", "note": ""},
    "permissions": {"state": "Unknown", "reference": "", "observed_at": "", "owner": "", "note": ""},
    "policy_approval": {"state": "Unknown", "reference": "", "observed_at": "", "owner": "", "note": ""},
    "publication": {"state": "Unknown", "reference": "", "observed_at": "", "owner": "", "note": ""},
    "delivery": {"state": "Unknown", "reference": "", "observed_at": "", "owner": "", "note": ""},
    "reply": {"state": "Unknown", "reference": "", "observed_at": "", "owner": "", "note": ""},
    "crm_arrival": {"state": "Unknown", "reference": "", "observed_at": "", "owner": "", "note": ""}
  },
  "history": []
}
```

## Receipt validity

For a Messenger evidence item, `Verified` passes only with a specific HTTPS URL, `meta://` reference or specific `receipt:` identifier; a non-future UTC ISO 8601 timestamp such as `2026-10-07T12:30:00Z`; a specific owner; and a note explaining what the receipt proves. Reject placeholders such as `placeholder`, `receipt`, `tomorrow`, `somebody` or `proof`. For a non-Messenger destination, keep the eight Messenger objects in the portable record but do not request or evaluate them; verify the selected route in its own system.

## Canonical execution and literal output rules

The downloadable bundle includes `run-messenger-flow.mjs`, `artifacts/messenger-flow-evaluator.mjs` and `messenger-flow.schema.json`. They are the canonical implementation. Save the source JSON, then run:

```bash
node run-messenger-flow.mjs RECORD.json --pretty
node run-messenger-flow.mjs RECORD.json --handoff
```

The CLI accepts either a source record or a browser-downloaded evaluation envelope containing `source_record`. Do not replace its result with a subjective interpretation. If you cannot execute the bundle, preserve the source record and state `Canonical evaluation required`; do not invent a parallel decision or request shape.

When explaining the canonical rules, apply these literals exactly:

- Any resolved string passes as a supplied planning value. Do not judge whether a supplied response target, coverage window or owner wording is sensible.
- Ownership and CRM handoff fields are required for every selected destination except `hold`. A missing alternate-route owner or handoff stays `Hold for native evidence`, while Messenger evidence remains unevaluated.
- A broadly missing plan returns no account receipt requests. Native receipt requests begin only after every applicable planning field and branch check passes.
- `hold` has native state `Hold for native evidence`, not `Not evaluated for alternate destination`.
- A complete `instagram`, `whatsapp`, `lead_form` or `website` plan has native state `Not evaluated for alternate destination` and no Messenger requests.
- A complete Messenger plan with any unresolved receipt has native state `Hold for native evidence`.
- Evidence request IDs replace underscores with hyphens: `MESSENGER-EVIDENCE-PAGE-LINKAGE`, `MESSENGER-EVIDENCE-DESTINATION-AVAILABILITY`, `MESSENGER-EVIDENCE-PERMISSIONS`, `MESSENGER-EVIDENCE-POLICY-APPROVAL`, `MESSENGER-EVIDENCE-PUBLICATION`, `MESSENGER-EVIDENCE-DELIVERY`, `MESSENGER-EVIDENCE-REPLY`, `MESSENGER-EVIDENCE-CRM-ARRIVAL`.
- Every request object uses keys `id`, `field`, `owner`, `supplied_state`, `reason`, `request`. Its reason is exactly `<key with spaces> is not verified`. Its request text is the exact sentence in the evaluator's `evidenceLabels` table. Missing owner becomes `Owner assignment required`.
- Multiple entry branches are allowed. Every branch must be reachable from at least one supplied `flow.entry_branch_ids` value.
- A `receipt:placeholder` value and any future UTC timestamp fail. There is no future-time grace period.
- The readable handoff must come from `renderHandoff()` or the `--handoff` command so pipes, backslashes and newlines remain valid Markdown and every source field is retained.
