The Draft Pipeline

[ Describe ] ----> [ Generate ] ----> [ Validate ] ----> [ Review card ] ----> [ Apply ] "/draft rule: ..." local-first AI closed action set, preview + errors, your own permissions, or the draft toggle (egress-policy safe grammar, caps Simulate on history the standard create in HxNexus chat guarded) > invalid never (rules), Discard endpoints > audit trail renders a card

Drafting is explicit only: the ✎ draft toggle or a /draft message. A normal chat message can never accidentally become a component, and nothing is ever created until a human clicks Apply.

What You Can Draft

ComponentBehaviour
Case-typeFull structure — stages, steps, and forms — using the same engine as the NLP Builder. Works offline via the heuristic fallback.
WHEN ruleConditions and actions, strictly validated (see below). No fallback: if AI is unavailable you get an honest error — a guessed rule is a wrong rule.
FormField list with a whitelisted type vocabulary. Degrades to a small, clearly-labelled template when AI is down.
SLA policyGoal + deadline durations on a case type (/draft sla: resolve in 48h, goal 24h). Rendered as a diff on the case type; a policy with a matching id becomes a before/after replace card. AI down: a deterministic parser uses only durations you typed — no durations, honest error.
User account/draft user: create jdoe for login — username, email, roles from a closed allowlist (never admin). The AI never produces a password: Apply (admin-only) generates a temp password server-side, shows it once, and forces a change at first login.
Escalation tree/draft escalation: page the manager at 80% of deadline, reassign to ops at breach. Closed trigger and action vocabularies, targets limited to what the escalation engine can actually resolve, at most 10 strictly-ordered levels. Stage it like a rule: created inactive, a reviewer's merge activates it.
Routing change/draft routing <case-type-id>: route approvals to the least-loaded agent. The AI proposes only which step and which strategy (from the production assignment registry); the platform surgically patches that one step — a routing draft can never rewrite the rest of the process.
Modify existingPass a target id (or /draft modify rule <id>: …) — rules, case types, forms, escalation trees, and connector config (never credentials). You review a red/green diff card, and Apply refuses stale drafts if the component changed since drafting.

Stage in HxBranch — Propose, Review, Merge

[ Draft rule ] ----> [ Stage ] ----> [ HxBranch review ] ----> [ Merge enables ] anyone may stage rule created reviewer != owner approval flips a valid draft DISABLED + a (separation of enabled to true; branch whose only duties), replay rejection leaves a diff is enabling evidence in comments disabled rule + audit

Staging is the governed path: any authenticated user can propose a rule or an escalation tree, because nothing can go live without a reviewer's approval — the artifact is created disabled (rules) or inactive (trees) and only the branch merge turns it on. Direct rule Apply remains admin/designer-only.

Draft Lint — "This Rule Can Never Fire"

A valid rule draft scoped to a case type is also linted deterministically against that case type — no AI involved. The card shows advisory findings such as:

Lint is advisory: it renders as its own list on the card and never blocks a reviewed Apply.

The Validation Gate

A draft that fails validation is shown as a list of reasons — never as an applyable card. For rules the gate is the security boundary:

Your permissions, not the AI's. Apply runs through the same privilege-checked endpoints Studio uses, under your own token. Applying a drafted rule additionally requires the admin or designer role.

Simulate Before You Apply

A drafted rule doesn't have to be trusted — it can be tested against reality. The card's Simulate on history button runs the draft as an HxReplay counterfactual over recent real cases of a case-type: cycle-time delta, auto-vs-manual shift, manual work removed, and the cost figure — before the rule exists anywhere. Describe the policy in English, see what it would have done last quarter, apply with evidence.

Using HxDraft in Studio

  1. Open Studio > HxNexus, enable the ✎ draft toggle and pick a kind — or just type /draft rule: auto-approve claims under 500 where kyc.status is passed.

  2. Review the card: WHEN/THEN lines for rules, the stage chain for case-types, the field list for forms. Validation problems appear in amber instead of buttons.

  3. For a rule, paste a case-type id and click Simulate on history; open HxReplay to read the run (coverage, deltas, cost).

  4. Click Apply — the card flips to Created ✓ and the transcript doubles as your authoring audit trail. Or Discard, and nothing ever happened.

API Reference

# Draft a rule (generation only — creates nothing)
curl -s -X POST http://localhost:8200/api/v1/hxnexus/draft \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '{"kind":"rule","description":"auto-approve claims under 500 where kyc.status is passed"}'

# Apply the reviewed draft (re-validated server-side; admin/designer for rules)
curl -s -X POST http://localhost:8200/api/v1/hxnexus/draft/apply \
  -H "Authorization: Bearer $TOKEN" \
  -d '{"kind":"rule","draft":{ ...the draft from the previous call... }}'

# Simulate a drafted rule on real history first (HxReplay, zero persistence)
curl -s -X POST http://localhost:8200/api/v1/hxreplay/runs \
  -H "Authorization: Bearer $TOKEN" \
  -d '{"kind":"cohort","candidate":{"rules":[ ...draft... ]},
       "cohort_filter":{"case_type_id":"...","max_cases":500}}'

# Stage a drafted rule in HxBranch (created disabled; a reviewer's merge enables it)
curl -s -X POST http://localhost:8200/api/v1/hxnexus/draft/stage \
  -H "Authorization: Bearer $TOKEN" \
  -d '{"kind":"rule","draft":{ ...the draft... }}'

# Modify an existing component as a diff card (target_id = modify mode)
curl -s -X POST http://localhost:8200/api/v1/hxnexus/draft \
  -H "Authorization: Bearer $TOKEN" \
  -d '{"kind":"rule","target_id":"<rule-uuid>",
       "description":"also require kyc.status = passed"}'

# Draft an escalation tree / a routing change
curl -s -X POST http://localhost:8200/api/v1/hxnexus/draft \
  -H "Authorization: Bearer $TOKEN" \
  -d '{"kind":"escalation","description":"page the manager at 80% of deadline"}'
curl -s -X POST http://localhost:8200/api/v1/hxnexus/draft \
  -H "Authorization: Bearer $TOKEN" \
  -d '{"kind":"routing","target_id":"<case-type-uuid>",
       "description":"route approvals to the least-loaded agent"}'
Drafts are proposals. HxDraft never auto-applies, never bulk-applies, and never lets retrieved case content steer a draft — the only instruction channel is what you type. Review every card before applying.