@salesforce/afv-skills 1.71.0 → 1.72.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/package.json +1 -1
  2. package/skills/agentforce-generate/SKILL.md +8 -0
  3. package/skills/agentforce-generate/assets/agents/README.md +1 -1
  4. package/skills/agentforce-generate/references/actions-reference.md +4 -0
  5. package/skills/agentforce-generate/references/mcp-actions-in-agent-script.md +233 -0
  6. package/skills/agentforce-generate/references/reference-map.md +1 -0
  7. package/skills/dx-packaging-convert-1gp-to-2gp-create/SKILL.md +9 -7
  8. package/skills/dx-packaging-convert-1gp-to-2gp-create/references/conversion-operations.md +78 -4
  9. package/skills/dx-packaging-move-to-2gp-migrate/SKILL.md +17 -13
  10. package/skills/dx-packaging-move-to-2gp-migrate/references/api-operations.md +110 -9
  11. package/skills/experience-app-mcp-generate/references/troubleshooting.md +1 -1
  12. package/skills/experience-app-mcp-generate/scripts/merge_tools.mjs +49 -18
  13. package/skills/experience-app-mcp-generate/scripts/render_eca.mjs +1 -1
  14. package/skills/experience-app-mcp-generate/scripts/render_mcp_server.mjs +1 -1
  15. package/skills/experience-app-mcp-generate/scripts/scan_tool_candidates.mjs +3 -1
  16. package/skills/experience-ui-bundle-custom-app-generate/SKILL.md +32 -26
  17. package/skills/experience-ui-bundle-custom-app-generate/references/configure-metadata-custom-application.md +6 -24
  18. package/skills/nonprofit-fundraising-configure/references/mcp-invocation.md +4 -6
  19. package/skills/platform-apex-generate/SKILL.md +2 -1
  20. package/skills/platform-apex-generate/assets/abstract.cls +0 -4
  21. package/skills/platform-apex-generate/assets/invocable-action-extension.invocableactionextension-meta.xml +28 -0
  22. package/skills/platform-apex-generate/assets/invocable.cls +2 -0
  23. package/skills/platform-apex-generate/references/dml-declarations.md +69 -0
  24. package/skills/platform-metadata-discovery-get/SKILL.md +15 -10
  25. package/skills/platform-metadata-grounding-get/SKILL.md +5 -3
  26. package/skills/service-add-agents-to-contact-center-create/SKILL.md +138 -0
  27. package/skills/service-agentforce-contact-center-coordinate/SKILL.md +5 -5
  28. package/skills/service-agentforce-contact-center-coordinate/references/omni-flow-routing.md +3 -3
  29. package/skills/service-agentforce-contact-center-coordinate/scripts/create-routing-flows.sh +8 -3
  30. package/skills/service-agentforce-contact-center-coordinate/scripts/create-voice-agent.sh +5 -5
  31. package/skills/service-agentforce-contact-center-coordinate/scripts/resolve-acc-queue.sh +10 -1
  32. package/skills/service-agentforce-contact-center-coordinate/scripts/resolve-channel-line.sh +4 -0
  33. package/skills/service-agentforce-contact-center-coordinate/scripts/resolve-flow-definition.sh +5 -0
  34. package/skills/service-agentforce-contact-center-coordinate/scripts/verify-number-live.sh +6 -1
  35. package/skills/service-concierge-portal-generate/SKILL.md +1 -1
  36. package/skills/service-concierge-portal-generate/references/portal-deploy-runbook.md +21 -8
  37. package/skills/service-digital-engagement-channel-configure/SKILL.md +45 -32
  38. package/skills/service-digital-engagement-channel-configure/assets/public_key_certificate_set_jwks_template.xml +20 -0
  39. package/skills/service-digital-engagement-channel-configure/assets/public_key_certificate_set_jwks_url_template.xml +23 -0
  40. package/skills/service-digital-engagement-channel-configure/assets/public_key_certificate_template.xml +15 -0
  41. package/skills/service-digital-engagement-channel-configure/examples/asa_agent_channel.xml +1 -1
  42. package/skills/service-digital-engagement-channel-configure/examples/auth_queue_channel.xml +3 -3
  43. package/skills/service-digital-engagement-channel-configure/examples/jwks_upload_key.xml +11 -0
  44. package/skills/service-digital-engagement-channel-configure/examples/jwks_upload_keyset.xml +13 -0
  45. package/skills/service-digital-engagement-channel-configure/examples/jwks_url_keyset.xml +17 -0
  46. package/skills/service-digital-engagement-channel-configure/examples/omni_flow_channel.xml +3 -3
  47. package/skills/service-digital-engagement-channel-configure/examples/omni_queue_channel.xml +3 -3
  48. package/skills/service-digital-engagement-channel-configure/examples/user_channel.xml +1 -1
  49. package/skills/service-digital-engagement-channel-configure/references/_vendored/service-onboarding-delegation-guidelines.md +43 -0
  50. package/skills/service-digital-engagement-channel-configure/references/channel_settings.md +1 -1
  51. package/skills/service-digital-engagement-channel-configure/references/keyset_settings.md +46 -0
  52. package/skills/service-digital-engagement-channel-configure/references/keyset_setup.md +42 -0
  53. package/skills/service-digital-engagement-channel-configure/references/onboarding_contract.md +28 -27
  54. package/skills/service-digital-engagement-channel-configure/references/recaptcha_handoff.md +2 -5
  55. package/skills/service-digital-engagement-channel-configure/references/routing_transitions.md +2 -2
  56. package/skills/service-digital-engagement-channel-configure/references/user_verification.md +3 -4
  57. package/skills/service-digital-engagement-channel-configure/references/user_verification_client.md +51 -0
  58. package/skills/service-digital-engagement-channel-configure/scripts/check-api-version.sh +7 -0
  59. package/skills/service-digital-engagement-deployment-configure/SKILL.md +28 -10
  60. package/skills/service-digital-engagement-deployment-configure/references/_vendored/service-onboarding-delegation-guidelines.md +43 -0
  61. package/skills/service-digital-engagement-deployment-configure/references/branding_and_tooling.md +2 -2
  62. package/skills/service-digital-engagement-deployment-configure/references/code_snippet.md +2 -2
  63. package/skills/service-digital-engagement-deployment-configure/references/connect_api_creation.md +13 -7
  64. package/skills/service-digital-engagement-deployment-configure/references/custom_labels.md +127 -0
  65. package/skills/service-digital-engagement-deployment-configure/references/deployment_settings.md +2 -1
  66. package/skills/service-digital-engagement-deployment-configure/references/onboarding_contract.md +24 -25
  67. package/skills/service-digital-engagement-deployment-configure/references/prechat_forms.md +1 -1
  68. package/skills/service-digital-engagement-deployment-configure/scripts/check-api-version.sh +7 -0
  69. package/skills/service-email-to-case-configure/SKILL.md +89 -80
  70. package/skills/service-email-to-case-configure/assets/CaseSettings.settings-meta.xml +1 -1
  71. package/skills/service-email-to-case-configure/examples/CaseSettings-two-addresses.settings-meta.xml +6 -3
  72. package/skills/service-email-to-case-configure/references/_vendored/service-onboarding-delegation-guidelines.md +43 -0
  73. package/skills/service-email-to-case-configure/references/agent-delegation.md +22 -0
  74. package/skills/service-email-to-case-configure/references/apply-mechanics.md +15 -12
  75. package/skills/service-email-to-case-configure/references/end-to-end-proof.md +14 -0
  76. package/skills/service-email-to-case-configure/references/onboarding-delegated-run.md +66 -0
  77. package/skills/service-email-to-case-configure/references/routing_address_reference.md +6 -2
  78. package/skills/service-email-to-case-configure/references/troubleshooting.md +17 -9
  79. package/skills/service-email-to-case-configure/scripts/apply-casesettings.py +863 -925
  80. package/skills/service-email-to-case-configure/scripts/tests/_agent.py +162 -0
  81. package/skills/service-email-to-case-configure/scripts/tests/_fakeorg.py +119 -155
  82. package/skills/service-email-to-case-configure/scripts/tests/_run.py +10 -17
  83. package/skills/service-email-to-case-configure/scripts/tests/test_apply_org_scenarios.py +14 -14
  84. package/skills/service-email-to-case-configure/scripts/tests/test_dispatch_contract.py +316 -0
  85. package/skills/service-email-to-case-configure/scripts/tests/test_new_capabilities.py +12 -43
  86. package/skills/service-email-to-case-configure/scripts/tests/test_validate_casesettings.py +13 -0
  87. package/skills/service-email-to-case-configure/scripts/validate-casesettings.py +17 -5
  88. package/skills/service-itsm-agentic-setup-incident-management/references/status-checks.md +11 -11
  89. package/skills/service-remove-agents-from-contact-center-assign/SKILL.md +145 -0
  90. package/skills/service-voice-configuration-manage/SKILL.md +206 -0
  91. package/skills/service-voice-configuration-manage/assets/regions.json +23 -0
  92. package/skills/service-voice-configuration-manage/references/lookups.md +91 -0
  93. package/skills/service-voice-configuration-manage/references/voice_config_api.md +169 -0
  94. package/skills/service-voice-configuration-manage/scripts/create-configuration.sh +20 -0
  95. package/skills/service-voice-configuration-manage/scripts/delete-configuration.sh +31 -0
  96. package/skills/service-voice-configuration-manage/scripts/get-configuration.sh +18 -0
  97. package/skills/service-voice-configuration-manage/scripts/lib.sh +22 -0
  98. package/skills/service-voice-configuration-manage/scripts/list-configurations.sh +18 -0
  99. package/skills/service-voice-configuration-manage/scripts/lookup-caller-lines.sh +30 -0
  100. package/skills/service-voice-configuration-manage/scripts/lookup-flows.sh +29 -0
  101. package/skills/service-voice-configuration-manage/scripts/lookup-profiles.sh +29 -0
  102. package/skills/service-voice-configuration-manage/scripts/lookup-users.sh +29 -0
  103. package/skills/service-voice-configuration-manage/scripts/update-configuration.sh +20 -0
  104. package/skills/tableau-next-asset-create/SKILL.md +10 -4
  105. package/skills/tableau-next-asset-create/references/dashboard-design-principles.md +133 -0
  106. package/skills/tableau-next-asset-create/references/data-transform-gotchas.md +284 -128
  107. package/skills/tableau-next-asset-create/references/deep-reference-index.md +3 -3
  108. package/skills/tableau-next-asset-create/references/edit-dashboard.md +1 -1
  109. package/skills/tableau-next-asset-create/references/edit-visualization.md +678 -468
  110. package/skills/tableau-next-asset-create/references/shared-gates.md +1 -1
  111. package/skills/tableau-next-asset-create/references/tasks/create-data-transform.md +120 -42
  112. package/skills/tableau-next-asset-create/references/tasks/create-viz.md +8 -0
  113. package/skills/tableau-next-asset-create/references/tasks/edit-viz.md +7 -4
  114. package/skills/tableau-next-asset-create/references/tasks/promote-or-reuse.md +9 -4
  115. package/skills/tableau-next-asset-create/references/viz-authoring.md +1 -1
  116. package/skills/service-email-to-case-configure/scripts/tests/test_get_session.py +0 -134
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: service-email-to-case-configure
3
- description: "Use to configure Salesforce Email-to-Case headlessly via the Metadata API. Reads CaseSettings, applies the emailToCase config with updateMetadata, and verifies by re-reading. Also the entry point for attaching an Agentforce agent to Email-to-Case: configures the E2C base, then delegates agent creation and channel wiring. TRIGGER on set up/configure Email-to-Case, enable E2C routing addresses, add a routing address, or E2C with an Agentforce agent. DO NOT TRIGGER for the interactive Easy Setup wizard, On-Demand E2C only, general Case/web-to-case setup, or an agent with no E2C involved."
3
+ description: "Use to configure Salesforce Email-to-Case headlessly via the Metadata API. Reads CaseSettings, applies the emailToCase config with a Metadata CRUD update, and verifies by re-reading. Use this instead of generic CaseSettings metadata CRUD for any Email-to-Case task. Also the entry point for attaching an Agentforce agent to Email-to-Case: configures the E2C base, then delegates agent creation and channel wiring. TRIGGER on set up/configure Email-to-Case, enable E2C routing addresses, add a routing address, turn HTML email, email drafts, word count or other Email-to-Case defaults on or off (opt out of the default toggles), or E2C with an Agentforce agent. DO NOT TRIGGER for the interactive Easy Setup wizard, On-Demand E2C only, general Case/web-to-case setup, or an agent with no E2C involved."
4
4
  metadata:
5
5
  version: "1.1"
6
6
  domains: ["Service", "Agentforce"]
@@ -16,34 +16,63 @@ metadata:
16
16
  accessCheck: "(OrgPermissions.HasEmailToCase) && (UserPermissions.CustomizeApplication)"
17
17
  ---
18
18
 
19
- # Configure Email-to-Case (Metadata API)
19
+ # Configure Email-to-Case (dispatch)
20
20
 
21
- Configure Salesforce Email-to-Case entirely through the Metadata API (no Setup UI), for headless org configuration. The skill builds a `CaseSettings` source file for the desired `emailToCase` state, then applies it with `scripts/apply-casesettings.py`, which runs `updateMetadata` in **two phases** — the full `emailToCase` block + Support Settings (Phase A), then routing addresses (Phase B) — and verifies by re-reading. Two phases because a single deploy **fails on a fresh org**: On-Demand must be live before an address binds (see Rules / Constraints).
21
+ Configure Salesforce Email-to-Case entirely through the project-codey `dispatch` / `dispatch_readonly` tools (no Setup UI, no `sf` CLI for org calls, except the optional Agentforce probe, whose `sf` alias must point at the org the server is bound to). The skill builds a `CaseSettings` source file for the desired `emailToCase` state, applies it in **two phases** (the full `emailToCase` block + Support Settings, then routing addresses; a single write fails on a fresh org), and verifies by re-reading. `scripts/apply-casesettings.py` makes **no org calls**: it prints each request for you to dispatch, validates the response you save, and builds the next write (see Dispatch protocol).
22
+
23
+ **Entry modes.** A direct user and an orchestrator (`delegationFrom` set, with an `intent`) run the same Workflow; what the `intent` or first message already states is not asked again. Pre-scan, the single confirmation, wording by `discoveryMode`, and the hand-back are in `references/onboarding-delegated-run.md`: read it at step 1.
24
+
25
+ ## How delegation is handled
26
+
27
+ <!-- BEGIN delegation-pointer (managed by stamp_delegation_boilerplate.py -- do not edit by hand) -->
28
+
29
+ ### Service-Onboarding delegation
30
+
31
+ When `delegationFrom` is set to service-onboarding, fetch and follow
32
+ [the Service-Onboarding delegation guidelines](references/_vendored/service-onboarding-delegation-guidelines.md) before acting — it is the single
33
+ source of truth, identical across every service-onboarding delegate. When it is absent, ignore this
34
+ and run as a normal standalone conversation.
35
+
36
+ <!-- END delegation-pointer -->
37
+
38
+ ---
22
39
 
23
40
  ## Scope
24
41
 
25
- - **In scope**: Enabling Email-to-Case org-wide and setting its toggles (full field lists in Required Inputs and step 4); creating `EmailToCase`, `Outlook`, and `GmailOAuth` routing addresses; applying the change to an sf-CLI-authenticated org via `apply-casesettings.py`; verifying by re-reading.
42
+ - **In scope**: Enabling Email-to-Case org-wide and setting its toggles; creating `EmailToCase`, `Outlook`, and `GmailOAuth` routing addresses; applying the change to the org the dispatch server is bound to; verifying by re-reading.
26
43
  - **Out of scope**:
27
44
  - **`E2cEasy` routing addresses** — created only through the Service Easy Setup wizard, not the Metadata API; route the user there.
28
- - Authenticating the org — the user authenticates out-of-band (e.g. `sf org login web`); the script reuses that session and never handles passwords or tokens.
45
+ - Choosing or authenticating the org: the skill touches only the org the project-codey MCP server is bound to and never handles passwords or tokens. To target another org the user reconfigures the server.
29
46
  - Case object schema, layouts, assignment rules, or Web-to-Case.
47
+ - Creating a queue or an Org-Wide Email Address, verifying a mailbox, or forwarding mail: the user does these (see After setup).
48
+ - Editing or deleting an existing routing address (new addresses are appended).
30
49
 
31
50
  ---
32
51
 
33
52
  ## Attaching an Agentforce service agent (delegation)
34
53
 
35
- When the user wants an Agentforce Service Agent to answer these emails, configure the Email-to-Case base (the Workflow below), then delegate — this skill never creates or modifies agents.
54
+ When the user wants an Agentforce Service Agent to answer these emails, configure the Email-to-Case base (the Workflow below), then delegate; this skill never creates or modifies agents. **Before delegating, run `scripts/check-agent-email-capability.sh <target-org-alias>`**. Exit **3** means the org is not entitled: **stop, tell the user, and configure the plain base only.** Any other non-zero means the org is unreachable. On exit **0**, delegate agent creation to `agentforce-generate` and wiring to `service-agentforce-channel-configure` Branch C. Details: `references/agent-delegation.md`.
55
+
56
+ ---
36
57
 
37
- **Gate on org capability first.** Attaching an agent needs the org entitled for Agentforce Email-to-Case; that entitlement surfaces as the `BotEmailDefinition` metadata type, so probe read-only **before delegating**:
58
+ ## Dispatch protocol
38
59
 
39
- ```bash
40
- scripts/check-agent-email-capability.sh <target-org-alias> # pins describe to the org's API version
41
- ```
60
+ Every org call is a project-codey tool call that **you** make; `scripts/apply-casesettings.py` never touches the org. The loop is always the same:
42
61
 
43
- Exit **3** → not entitled: **stop, tell the user, and configure the plain Email-to-Case base only — make no Agentforce agent or channel-wiring changes.** Any other non-zero is an unreachable org, not "not entitled" — fix auth and re-run. On exit **0**, delegate:
62
+ 1. Run `python3 scripts/apply-casesettings.py requests <kind> ...` (or a `phase-a` / `phase-b` command). It prints `{"requests": [...]}` or `{"request": {...}}`. Each request names the `tool` (`dispatch_readonly` for GET, `dispatch` for the PUT), `method`, `path`, and `query_params` or `body`.
63
+ 2. Make **exactly that call**: copy `path`, `query_params`, and `body` verbatim, never edit the `xmlRep`, and use `dispatch` only when the request says so.
64
+ 3. Save the tool's result **verbatim** to a file (the `{status_code, body}` JSON, or the path the tool saved it to) and pass it to the next subcommand.
65
+ 4. If a subcommand exits non-zero, relay its stderr to the user and stop or re-prompt as it says.
44
66
 
45
- 1. **Agent creation → `agentforce-generate`,** omitting the **Service Customer Verification topic** (unsupported on the email channel) and including an **Escalation subagent** so the agent can hand off to a human — on email, escalation transfers the case to a service rep, and without the subagent the agent can't escalate.
46
- 2. **Wiring → `service-agentforce-channel-configure` Branch C.**
67
+ | Subcommand | Use |
68
+ |---|---|
69
+ | `requests org` → `gate --org F [--confirm-production]` | Production-org verdict; non-zero on production without confirmation and **always** when the org type is unreadable. |
70
+ | `requests settings` → `read --response F` | The current `CaseSettings`. |
71
+ | `requests lookups --input F --current F ...` | User/queue validation queries; pass the results on as `--users F` / `--queues F`. |
72
+ | `phase-a`, `phase-b` | Build the PUT request. `phase-b` may print `{"skip": true}` when there is nothing new to add. |
73
+ | `check-write --response F` | Validates a PUT result. Run it after **every** write. |
74
+ | `verify --initial F --after F` | Preservation guard + verified summary; pass the same flags and lookup files as `phase-a`. |
75
+ | `requests cases` / `messages` → `cases` | Act 3 proof. |
47
76
 
48
77
  ---
49
78
 
@@ -51,18 +80,17 @@ Exit **3** → not entitled: **stop, tell the user, and configure the plain Emai
51
80
 
52
81
  Gather or infer before applying. Ask only when a wrong assumption would produce a broken or incorrect result:
53
82
 
54
- - **Target org alias** — the sf CLI alias/username of an already-authenticated org. The script obtains the session with `sf org display` and `sf org auth show-access-token`; it does not log in for you.
83
+ - **Target org** — none to collect: dispatch acts on the org the server is bound to. Only the optional Agentforce probe needs that org's `sf` CLI alias.
55
84
  - **Routing address(es)** — for each: `routingName` (unique label), `addressType` (`EmailToCase` default, or `Outlook` / `GmailOAuth`), `caseOrigin`, and `casePriority`. The platform rejects the address if `caseOrigin` or `casePriority` is missing, so treat all four as required in the source file.
56
- - **Customer-facing email address per routing address** — **ask explicitly for each, in address order**; never guess, default, or reuse from earlier context. Not stored in the source file — passed at apply time via `--routing-email` (one per address; the script fails closed on a count mismatch).
85
+ - **Customer-facing email address per routing address** — **take it from the `intent` or the user's message when stated, otherwise ask explicitly for each, in address order**; never guess, default, or reuse from earlier context. Not stored in the source file — passed at apply time via `--routing-email` (one per address that takes an email — **`Outlook` addresses take none**; the script fails closed on a count mismatch).
57
86
  - **Support Settings — Default Case Owner & Automated Case User** — preserve-first, never assumed:
58
87
  - **Independent, preserved per field.** Each configured field is left untouched; change one only if the user asks (`--overwrite-support-settings`). Ask **only for the field(s) unset**.
59
- - **For each unset field, ask** (never default to the authenticated user): Default Case Owner **type** (`User`/`Queue`) + **value** (active Username or Queue DeveloperName) → `--owner-type`/`--owner-value`; Automated Case User **type** (`User`/`System`) — `User` needs a **username**, `System` needs no value → `--automated-type`/`--automated-value` (+ optional `--system-user-email` for System when the org's automated user doesn't exist yet).
60
- - **If any value is invalid**, the script fails — get a valid value and re-run; never substitute or guess.
61
- - Pass `--use-authenticated-user` **only** if the user explicitly asks.
62
- - **Case defaults per address** (optional) — `createTask`, `saveEmailHeaders`, and an optional **per-address Default Case Owner** (`caseOwner` + `caseOwnerType`), **opt-in per address** (see step 6): omitted by default so cases fall to the org Default Case Owner / assignment rules. When set, `caseOwner` (active Username or Queue DeveloperName) must be paired with `caseOwnerType` (`User`/`Queue`); the script validates it against the org, failing closed if absent.
63
- - **Org-level toggles** (optional) — set only if the user asks. Two containers: the **`emailToCase` section** (`enableHtmlEmail`, `notifyOwnerOnNewCaseEmail`, `enableE2CDeduplicateAttachments`, `showWordCountInComposer`, plus `enableE2CSourceTracking`, `overEmailLimitAction`, `unauthorizedSenderAction`), and **top-level Support Settings** (`enableDraftEmails` — plural element name, a sibling of `emailToCase`). See step 4's table for container/UI-label mapping; top-level scalar toggles apply in Phase A.
88
+ - **For each unset field, use the `intent` or ask** (never assume a default user): Default Case Owner **type** (`User`/`Queue`) + **value** (active Username or Queue DeveloperName) → `--owner-type`/`--owner-value`; Automated Case User **type** (`User`/`System`) — `User` needs a **username**, `System` needs no value → `--automated-type`/`--automated-value` (+ optional `--system-user-email` for System when the org's automated user doesn't exist yet).
89
+ - **If a value is invalid**, the script fails: get a valid one and re-run; never guess. If the user says "use me", ask for their exact username.
90
+ - **Case defaults per address** (optional) — `createTask`, `saveEmailHeaders`, and the opt-in per-address Default Case Owner (`caseOwner` + `caseOwnerType`, both or neither; see step 6). Omitted by default so cases fall to the org Default Case Owner / assignment rules.
91
+ - **Org-level toggles** (optional) — set only if the user asks, beyond the defaults in step 4 (which apply to a fresh setup only). They live in the `emailToCase` section (`enableHtmlEmail`, `notifyOwnerOnNewCaseEmail`, `enableE2CDeduplicateAttachments`, `showWordCountInComposer`, `enableE2CSourceTracking`, `overEmailLimitAction`, `unauthorizedSenderAction`) or at the top level (`enableDraftEmails`).
64
92
 
65
- Defaults: `enableEmailToCase` and `enableOnDemandEmailToCase` default to `true` (both required — On-Demand before routing addresses); `addressType` defaults to `EmailToCase`. Support Settings have **no default** — preserved if set, otherwise elicited (never the authenticated user).
93
+ Defaults: `enableEmailToCase` and `enableOnDemandEmailToCase` default to `true` (both required — On-Demand before routing addresses); `addressType` defaults to `EmailToCase`. Support Settings have **no default** — preserved if set, otherwise elicited (never assumed).
66
94
 
67
95
  ---
68
96
 
@@ -70,47 +98,37 @@ Defaults: `enableEmailToCase` and `enableOnDemandEmailToCase` default to `true`
70
98
 
71
99
  All steps are sequential.
72
100
 
73
- 1. **Confirm the org (and its type)** — confirm the target org alias is authenticated (`sf org display --target-org <alias>`). The apply script checks the `Organization` row and **refuses to mutate a production org** (non-sandbox, non-trial) unless `--confirm-production` is passed — enabling Email-to-Case is permanent and org-wide. If production, tell the user and confirm before re-running with `--confirm-production`. Sandboxes, scratch orgs, and trials deploy without the flag.
101
+ 1. **Confirm the org, pre-scan it, and confirm once** — run `requests org` and dispatch it (a failure usually means the server is not connected or bound to the intended org: tell the user and stop). Then run `gate --org <file>`; on production it exits non-zero until confirmed, so pre-scan anyway and re-run it with the flag after the yes. The gate **refuses to mutate a production org** (non-sandbox, non-trial) unless `--confirm-production` is passed, and refuses an org whose type it cannot read even with the flag — enabling Email-to-Case is permanent and org-wide. **Send no write before `gate` succeeds.** Pre-scan (read-only): `requests settings`, dispatch, save as the **initial read** (keep it unchanged until `verify`), `read --response <file>`, and classify it with `references/onboarding-delegated-run.md` §1 (nothing set up / no change / add / override / ask once). Before the first write, ask **one** confirmation for every org type, naming the org and its type, and adding that enabling is permanent only when Email-to-Case is not yet on (§2); on production the same yes covers `--confirm-production`, which you never add before it. No change needed: report, run `verify`, hand back, with no write.
74
102
 
75
- 2. **Elicit the routing email(s)** — ask the user for the exact customer-facing email address for each routing address (never assume, default, or carry a value over from earlier). Pass them to the script via `--routing-email` in the order the addresses appear in the source file.
103
+ 2. **Elicit the routing email(s)** — take the exact customer-facing email for each routing address except `Outlook` ones from the `intent` or the user's message when stated, otherwise ask (never assume or reuse a value). Pass them to every `phase-a` / `phase-b` / `verify` command via `--routing-email`, in source-file order.
76
104
 
77
- 3. **Load the template** — read `assets/CaseSettings.settings-meta.xml` for structure and field placement. Its comments are authoring guidance **for you** — never copy them into the output. Emit only the elements you set; the output must be comment-free, matching `examples/CaseSettings-two-addresses.settings-meta.xml`.
105
+ 3. **Load the template** — read `assets/CaseSettings.settings-meta.xml` for structure and field placement. Its comments are guidance for you; never copy them. Emit only the elements you set, comment-free, as in `examples/CaseSettings-two-addresses.settings-meta.xml`.
78
106
 
79
107
  4. **Enable the E2C switches, then confirm the optional toggles** — set both `enableEmailToCase` and `enableOnDemandEmailToCase` to `true` (both required; On-Demand must be on before routing addresses can be created — the script enables it in Phase A before Phase B). Then handle the **non-required convenience settings**, which the template turns on by default:
80
108
 
81
- | UI label | Field | Container |
82
- |----------|-------|-----------|
83
- | Enable HTML email | `enableHtmlEmail` | `emailToCase` |
84
- | Eliminate duplicate email attachments | `enableE2CDeduplicateAttachments` | `emailToCase` |
85
- | Show word count in composer | `showWordCountInComposer` | `emailToCase` |
86
- | Notify case owners on new emails | `notifyOwnerOnNewCaseEmail` | `emailToCase` |
87
- | Enable Email Drafts | `enableDraftEmails` (top-level `CaseSettings`) | Support Settings |
109
+ Enable HTML email (`enableHtmlEmail`), Eliminate duplicate email attachments (`enableE2CDeduplicateAttachments`), Show word count in composer (`showWordCountInComposer`) and Notify case owners on new emails (`notifyOwnerOnNewCaseEmail`) all go inside `<emailToCase>`. Enable Email Drafts (`enableDraftEmails`) is a top-level Support Settings field at the `CaseSettings` root.
88
110
 
89
- **Before enabling these, tell the user exactly which will be turned on and let them opt out** (e.g. "I'll also enable these optional settings: … — let me know if you'd like to skip any."). Remove any the user opts out of; keep the rest in their correct container (four inside `<emailToCase>`, `enableDraftEmails` at the root). Never silently enable these or any other optional flag the user didn't agree to. Confirmed toggles apply in Phase A.
111
+ **On a fresh setup, tell the user exactly which will be turned on (in the guided wording of `references/onboarding-delegated-run.md` §3 when `discoveryMode` is `"guided"`) and let them opt out;** an opt-out already in the `intent` is not asked again. Remove any they decline; keep the rest in place (four inside `<emailToCase>`, `enableDraftEmails` at the root). Never enable an optional flag the user didn't agree to. **On an org that already has Email-to-Case, do not apply these defaults:** include only the toggles the user chose to change. Confirmed toggles apply in Phase A.
90
112
 
91
113
  5. **Pick the correct surface per routing address** — for each address, decide by `addressType` using `references/routing_address_reference.md`. If any requested address is `E2cEasy`, stop and route the user to the Service Easy Setup wizard instead of emitting Metadata for it.
92
114
 
93
- 6. **Populate routing-address fields** — for each `EmailToCase` / `Outlook` / `GmailOAuth` address, set `addressType`, `routingName`, `caseOrigin`, and `casePriority` (all required — the platform rejects the operation with "Missing caseOrigin"/"Missing casePriority" if either is absent), plus any optional case defaults. Do **not** put `emailAddress` in the source file — it is supplied at apply time via `--routing-email`. Do **not** set the read-only fields `emailServicesAddress` or `isVerified` — the platform manages them. See `examples/CaseSettings-two-addresses.settings-meta.xml` for a complete multi-address example.
115
+ 6. **Populate routing-address fields** — for each `EmailToCase` / `Outlook` / `GmailOAuth` address, set `addressType`, `routingName`, `caseOrigin`, and `casePriority` (all required; the platform rejects the write without `caseOrigin` or `casePriority`), plus any optional case defaults. An `Outlook` address **must** also set `caseOwner` + `caseOwnerType` (the platform rejects it with "Missing caseOwner") and takes **no** email — the platform rejects `emailAddress` on it. Do **not** put `emailAddress` in the source file (it comes from `--routing-email`), and do **not** set the read-only `emailServicesAddress` or `isVerified`. See `examples/CaseSettings-two-addresses.settings-meta.xml` for a multi-address example.
94
116
 
95
- **Per-address Default Case Owner (opt-in).** Ask one address at a time whether cases from *this* address go to a specific owner or fall to the org Default Case Owner / assignment rules (the default) — different addresses can route to different owners. If the user **declines**, leave `caseOwner`/`caseOwnerType` out of the source file entirely (the template ships them commented out). If the user **opts in**, ask for the **type** (`User`/`Queue`) and **value** (active Username or Queue DeveloperName) and set **both** `<caseOwnerType>` and `<caseOwner>` — the platform rejects `caseOwner` without its type. `apply-casesettings.py` validates it against the org and fails closed if absent. Do not guess or reuse the top-level Default Case Owner.
117
+ **Per-address Default Case Owner is opt-in.** Ask one address at a time whether its cases go to a specific owner or fall to the org Default Case Owner / assignment rules (the default). If the user declines, leave `caseOwner`/`caseOwnerType` out of the source file; if they opt in, set **both**.
96
118
 
97
- 7. **Determine Support Settings (Default Case Owner + Automated Case User)** — run `python3 scripts/apply-casesettings.py --target-org <alias> --input <source-file> --verify-only` and inspect `defaultCaseOwner` / `defaultCaseUser` / `useSystemUserAsDefaultCaseUser`. **When the user names a value, write it into the source file** (`defaultCaseOwner` + `defaultCaseOwnerType`; `defaultCaseUser`, or `useSystemUserAsDefaultCaseUser` + optional `systemUserEmail`) — the scored, versionable artifact; the script also accepts these as flags. **Leave each field the org already has as-is** — omit it and it is preserved (override only if the user asks — then `--overwrite-support-settings`). For a field unset **and** unnamed, ask; never assume the authenticated user (`--use-authenticated-user` only if explicitly asked).
119
+ 7. **Determine Support Settings (Default Case Owner + Automated Case User)** — from the step 1 read, inspect `defaultCaseOwner` / `defaultCaseUser` / `useSystemUserAsDefaultCaseUser`. **When the user names a value, write it into the source file** (`defaultCaseOwner` + `defaultCaseOwnerType`; `defaultCaseUser`, or `useSystemUserAsDefaultCaseUser` + optional `systemUserEmail`); the script also accepts these as flags. **Leave each field the org already has as-is** (override only if the user asks, with `--overwrite-support-settings`). For a field unset **and** not named in the `intent` or by the user, ask; never assume a user.
98
120
 
99
- 8. **Validate the source file** — run `python3 scripts/validate-casesettings.py <path-to-source-file>` and resolve any reported errors before applying.
121
+ 8. **Validate the source file** — run `python3 scripts/validate-casesettings.py [--no-addresses-ok] <source-file>` (the flag for a toggle-only file) and fix any errors.
100
122
 
101
- 9. **Apply to the org** — run:
102
- ```bash
103
- python3 scripts/apply-casesettings.py --target-org <alias> --input <source-file> \
104
- --routing-email <email-for-address-1> [--routing-email <email-for-address-2> ...] \
105
- [--owner-type User|Queue --owner-value <username-or-queue-devname>] \
106
- [--automated-type User --automated-value <username> | --automated-type System [--system-user-email <email>]] \
107
- [--confirm-production]
108
- ```
109
- Provide exactly one `--routing-email` per routing address, in document order. Supply the owner/automated flags **only when the org's Support Settings are not already configured** (step 7); if configured, omit them and they are preserved. If the script rejects a value as invalid, relay it, get a valid value, and re-run — never fall back to the authenticated user. **If the script reports production and exits, do not add `--confirm-production` yourself** — confirm with the user first (step 1). The script applies Phase A (support settings + toggles), then Phase B (routing addresses), re-reads to verify, and exits non-zero on any fault.
123
+ 9. **Apply to the org** — with `<flags>` = `--input <source-file> --routing-email <email-1> [--routing-email <email-2> ...]` (exactly one per non-`Outlook` routing address, in document order) plus, **only when Support Settings are not already configured** (step 7), `[--owner-type User|Queue --owner-value <username-or-queue-devname>] [--automated-type User --automated-value <username> | --automated-type System [--system-user-email <email>]]` (add `--overwrite-support-settings` only if the user asked to change a configured field):
124
+ 1. `requests lookups --current <initial-read> <flags>`; dispatch each printed request (it is empty when there is nothing to validate) and keep the results as `--users` / `--queues`.
125
+ 2. `phase-a --current <initial-read> <flags> [--users F] [--queues F]` → dispatch its `request` (a PUT), then `check-write`. Keep its `summary`.
126
+ 3. `requests settings`, dispatch, save as the **fresh read** → `phase-b --current <fresh-read> <flags> [--users F] [--queues F]` → if it prints a `request`, dispatch it and `check-write`; if it prints `skip`, there is nothing to add. Keep its `phaseB` list.
127
+ 4. `requests settings`, dispatch, save as the **final read** → `verify --initial <initial-read> --after <final-read> <flags> [--users F] [--queues F]` (the same lookup files as `phase-a`; `verify` re-resolves Support Settings against them).
110
128
 
111
- 10. **Confirm the result** — check the JSON summary: `verified.enableEmailToCase` / `verified.enableOnDemandEmailToCase` are `true`, `verified.routingAddressCount` matches the address count, each `phaseB` entry is `status: created` (or `already_exists`), and `supportSettings.action` is `preserved-existing` / `set-from-input` / `set-from-authenticated-user`. Use `--verify-only` to re-read without writing.
129
+ If a script command rejects a value, relay it, get a valid one, and re-run from that command. Add `--confirm-production` only after the user's yes (step 1). A failed `check-write` stops the run: report the platform message verbatim (see `references/troubleshooting.md`) and do not re-send an edited payload.
112
130
 
113
- Configuration is complete after step 10.
131
+ 10. **Confirm the result** — check the `verify` output and the kept summaries: `verified.enableEmailToCase` / `verified.enableOnDemandEmailToCase` are `true`, `verified.routingAddressCount` matches the expected count, each `phaseB` entry is `status: created` (or `already_exists`), and `supportSettings.action` is `preserved-existing` / `set-from-input` / `overwrote-existing`. Use `requests settings` + `read` to re-read without writing. When called by an orchestrator, report what was set, what was left as it was, and what remains for the user, then hand control back (`references/onboarding-delegated-run.md` §5).
114
132
 
115
133
  ---
116
134
 
@@ -120,20 +138,13 @@ The items below are **not** workflow steps — present them to the user once set
120
138
 
121
139
  ### Forwarding (required for real inbound mail)
122
140
 
123
- Always give the user this guidance — it is how inbound mail to the customer-facing address actually reaches Salesforce:
141
+ Always give the user this guidance; it is how inbound mail actually reaches Salesforce:
124
142
 
125
- > Your routing address now has a Salesforce-generated **email services address**. To receive inbound mail, configure your email system to forward mail sent to your customer-facing address (e.g. `support@company.com`) to that generated services address.
143
+ > Your routing address now has a Salesforce-generated **email services address**. To receive inbound mail, forward mail sent to your customer-facing address (e.g. `support@company.com`) to that address.
126
144
 
127
145
  ### End-to-end proof (Act 3)
128
146
 
129
- Offer to prove inbound email creates Cases — a live round-trip; skip it if the user declines. The skill never sends email — it orchestrates two human actions, then verifies with SOQL: (1) **Address ownership** — Salesforce emails a confirmation link; `isVerified` flips only when the human clicks it. Tell the user to click it and **wait**. (2) **Send a test email** — ask the user to send one real email from an external mailbox to the routing address's Salesforce-generated **email services address** (not the customer-facing address, which only receives mail once forwarding is configured), report the sender, and **wait**. (3) **Verify with evidence** — then run:
130
-
131
- ```bash
132
- python3 scripts/apply-casesettings.py --target-org <alias> --verify-cases \
133
- [--supplied-email <external-sender-address>]
134
- ```
135
-
136
- Read-only: it queries `Case` where `Origin='Email'` (last 3 days, optionally narrowed by sender) plus the linked incoming `EmailMessage` rows (`Incoming=true`, `ParentId` = the new Case), and exits **non-zero if no matching Case has a linked incoming email** (mail not processed yet — wait and re-run — or address not verified). On success it prints the `Case` + `EmailMessage` evidence with `proven: true`.
147
+ Offer once, on a direct run only, to prove that inbound email creates Cases (a live round-trip; skip it if declined); on a delegated run, only if asked. The skill never sends email: the user verifies the address and sends a test email, then a read-only check looks for the Case. Follow `references/end-to-end-proof.md`.
137
148
 
138
149
  ---
139
150
 
@@ -141,33 +152,29 @@ Read-only: it queries `Case` where `Origin='Email'` (last 3 days, optionally nar
141
152
 
142
153
  | Constraint | Rationale |
143
154
  |-----------|-----------|
144
- | Apply via `apply-casesettings.py` (two-phase `updateMetadata`), never a plain deploy or a minimal `emailToCase` patch | A single deploy fails on a fresh org; the full `emailToCase` block (not a field-level flip) is what provisions On-Demand before addresses bind. See `references/apply-mechanics.md`. |
145
- | Write only the top-level fields the skill owns; never echo the whole `CaseSettings` record | The platform re-validates every top-level field in the payload (e.g. Case Feed → Chatter); sending only `emailToCase` + `enableDraftEmails` + Support Settings avoids unrelated failures and needs no Chatter prerequisite. Omitted fields keep their values via field-level merge. |
146
- | The customer-facing email must be explicit user input (`--routing-email`), never in the source file and never assumed | Prevents a guessed or stale address from being provisioned. The script fails closed if `--routing-email` count ≠ address count. |
147
- | `CaseSettings` `fullName` is always `Case` | It is an org singleton settings type; the script targets `Case` automatically. |
148
- | Support Settings are preserved **per field** if configured; never assumed if not | Default Case Owner and Automated Case User are independent — each configured field is left untouched (unless `--overwrite-support-settings`), and only an unset field requires an explicit, org-validated value (fails closed otherwise). The authenticated user is used only with `--use-authenticated-user`. |
155
+ | Apply in two phases built by `apply-casesettings.py` (PUT to `/headless/metadata`), never a single combined write or a minimal `emailToCase` patch | A single write fails on a fresh org, and only the full `emailToCase` block provisions On-Demand before addresses bind. See `references/apply-mechanics.md`. |
156
+ | All org reads and writes go through `dispatch_readonly` / `dispatch`; the only `sf` use is the Agentforce capability probe | The MCP server owns auth and org binding. Do not fall back to the `sf` CLI, SOAP, or a hand-built token if dispatch is unavailable — stop and tell the user. |
157
+ | Make each dispatch call exactly as the script printed it, and send no write before `gate` succeeds | The payloads encode the validated two-phase mechanism and the production safety check; an edited `xmlRep` or a skipped gate defeats both. |
158
+ | Write only the top-level fields the skill owns; never echo the whole `CaseSettings` record | The platform re-validates every top-level field sent (e.g. Case Feed needs Chatter). Omitted fields keep their values. See `references/apply-mechanics.md`. |
159
+ | The customer-facing email must be explicit input (`--routing-email`, from the user or the `intent`), never in the source file and never assumed | Prevents a guessed or stale address from being provisioned. The script fails closed if `--routing-email` count ≠ address count. |
160
+ | Support Settings are preserved **per field** if configured; never assumed if not | Each configured field is left untouched (unless `--overwrite-support-settings`); an unset field needs an explicit, org-validated value, or the script fails closed. |
149
161
  | Automated Case User "System" and a named `defaultCaseUser` are mutually exclusive | `--automated-type System` sets `useSystemUserAsDefaultCaseUser` and must not carry a user value; the platform rejects both. |
150
- | The script reads → patches → updates (append-only for addresses) | It merges onto current settings, so existing routing addresses are preserved; a duplicate `routingName`/`emailAddress` is reported as `already_exists`. New addresses are emitted **before** existing ones (`updateMetadata` replaces the collection wholesale and would drop an existing address that a new one follows; a runtime guard fails the run if any existing address is dropped). See `references/apply-mechanics.md`. |
162
+ | The script reads → patches → updates (append-only for addresses) | Existing routing addresses are preserved; a duplicate `routingName`/`emailAddress` is reported as `already_exists`. New addresses are emitted before existing ones, and a runtime guard fails the run if any existing address is dropped. See `references/apply-mechanics.md`. |
151
163
  | `EmailToCaseSettings` is never applied directly; `enableEmailToCase` cannot be turned off once on | It is written only as the `emailToCase` child of `CaseSettings`. The platform permanently enables the feature after the first `true` apply; never rely on setting it back to `false`. |
152
- | Production orgs require explicit `--confirm-production`; never add the flag unprompted | Enabling Email-to-Case is permanent and org-wide. The script fails closed on a non-sandbox, non-trial org (and one whose type it can't read) until the user confirms. Sandboxes and trials are exempt. |
153
- | Proving inbound Cases is a read-only step the user triggers; the skill never sends email | `--verify-cases` only queries `Case`/`EmailMessage` after the human verified the address and sent a test email. Fails closed until a Case with a linked incoming email exists. |
164
+ | Production orgs require explicit `--confirm-production`; never add the flag unprompted, and never before the single confirmation of step 1 | Enabling Email-to-Case is permanent and org-wide. The script fails closed on a non-sandbox, non-trial org (and one whose type it can't read) until the user confirms. Sandboxes and trials are exempt. |
154
165
  | `E2cEasy` addresses must use the Service Easy Setup wizard | The prebuilt `service_case` queue binding and `isVerified` flip are not reproducible through the Metadata API. |
155
- | Never write `emailServicesAddress` or `isVerified` | Both are read-only, platform-generated; the script strips them if present. |
156
- | The generated source file contains only the elements being set — **no XML comments** | Template/example comments are authoring guidance, not output. Copying them bloats the file (gold is comment-free) and CLI-example comments with `<placeholder>` tokens can fail XML validation. Put explanation in your chat reply, never in the `.settings-meta.xml`. |
157
166
 
158
167
  ---
159
168
 
160
169
  ## Gotchas
161
170
 
162
- For the full symptom → resolution table (Phase B provisioning errors, Case Feed/Chatter, per-address owner half-fills, `GmailOAuth` conflicts, `--verify-cases` failures, and every toggle-placement pitfall), read `references/troubleshooting.md`.
171
+ For the full symptom → resolution table (Phase B errors, Case Feed/Chatter, owner half-fills, `GmailOAuth`, the cases proof, toggle placement), read `references/troubleshooting.md`.
163
172
 
164
173
  ---
165
174
 
166
175
  ## Output Expectations
167
176
 
168
- Deliverables:
169
- - A `CaseSettings` source file (e.g. `Case.settings-meta.xml`) for the desired `emailToCase` state — toggles and routing-address fields, **without** `emailAddress` (supplied at apply time), read-only fields, or XML comments. Structure follows `assets/CaseSettings.settings-meta.xml`.
170
- - The applied org state from `apply-casesettings.py`, plus its JSON summary (resolved owner, per-address status, verification read).
177
+ A comment-free `CaseSettings` source file, the applied org state, and the script's JSON summaries.
171
178
 
172
179
  ---
173
180
 
@@ -175,12 +182,14 @@ Deliverables:
175
182
 
176
183
  | File | When to read / run |
177
184
  |------|-------------|
178
- | `assets/CaseSettings.settings-meta.xml` | Step 3 — the starting template for the source file |
179
- | `references/apply-mechanics.md` | Read before touching how the script builds or sequences its `updateMetadata` payloads |
180
- | `references/troubleshooting.md` | When the apply or verify step reports an error, or a configured setting doesn't behave — full symptom → resolution table |
181
- | `references/routing_address_reference.md` | Steps 5–6 — routing-address field semantics and the `addressType` surface-selection rule |
182
- | `examples/CaseSettings-two-addresses.settings-meta.xml` | Step 6 — to verify the source-file structure for multiple routing addresses |
183
- | `scripts/check-agent-email-capability.sh` | Attaching an Agentforce service agent — the pre-delegation capability gate (probes for `BotEmailDefinition`) |
184
- | `scripts/validate-casesettings.py` | Step 8 — deterministic structural validation before applying |
185
- | `scripts/apply-casesettings.py` | Step 9 — applies the settings via two-phase `updateMetadata` and verifies |
186
- | `scripts/tests/test_get_session.py` | Run when changing session-token acquisition (`get_session` / `_usable_access_token`) — the unit suite guarding token extraction and API-version resolution |
185
+ | `references/onboarding-delegated-run.md` | Step 1 — pre-scan, single confirmation, guided wording, permission message, hand-back |
186
+ | `references/apply-mechanics.md` | Before changing how the script builds or sequences writes |
187
+ | `references/troubleshooting.md` | An apply or verify error, or a setting that doesn't behave |
188
+ | `references/agent-delegation.md` | Attaching an Agentforce service agent |
189
+ | `references/end-to-end-proof.md` | After setup, the optional inbound-email proof |
190
+ | `references/routing_address_reference.md` | Steps 5–6 — address fields and `addressType` surface |
191
+ | `assets/CaseSettings.settings-meta.xml` | Step 3 — the source-file template |
192
+ | `examples/CaseSettings-two-addresses.settings-meta.xml` | Step 6 — multi-address structure |
193
+ | `scripts/check-agent-email-capability.sh` | The pre-delegation capability gate |
194
+ | `scripts/validate-casesettings.py` | Step 8 |
195
+ | `scripts/apply-casesettings.py` | Steps 1, 7, 9, 10 |
@@ -1,7 +1,7 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <!-- Template for headless Email-to-Case config. Fill in, then emit a COMMENT-FREE
3
3
  source file (see SKILL.md step 3). fullName is implicitly "Case". Do not set
4
- emailAddress (supply via --routing-email), emailServicesAddress, or isVerified. -->
4
+ emailAddress (supply via the routing-email option), emailServicesAddress, or isVerified. -->
5
5
  <CaseSettings xmlns="http://soap.sforce.com/2006/04/metadata">
6
6
  <!-- Support Settings (siblings of emailToCase). Set inline whatever the user
7
7
  names; omit the rest. Default Case Owner: defaultCaseOwner (a Username or
@@ -6,9 +6,10 @@
6
6
  Note what is and is NOT here:
7
7
  1. The two required emailToCase switches (enableEmailToCase + enableOnDemandEmailToCase)
8
8
  and, on each address, the required addressType / routingName / caseOrigin / casePriority.
9
- 2. NO emailAddress on either address. The customer-facing emails are supplied at apply
10
- time via one routing-email option per address, in this document order (first the
11
- Support Inbox email, then the Sales Outlook Inbox email). See SKILL.md step 9.
9
+ 2. NO emailAddress on either address; the Outlook address takes none at all and needs a
10
+ caseOwner + caseOwnerType (the platform rejects it otherwise). Replace the owner value.
11
+ The customer-facing email of the EmailToCase address (Support Inbox) is supplied at apply
12
+ time via one routing-email option. See SKILL.md step 9.
12
13
  3. Support Settings (Default Case Owner / Automated Case User) appear here only when the
13
14
  user names them — this example names none, so none are set. When named, write the
14
15
  paired fields (defaultCaseOwner + defaultCaseOwnerType, etc.); fields the org already
@@ -31,6 +32,8 @@
31
32
  <routingName>Sales Outlook Inbox</routingName>
32
33
  <caseOrigin>Email</caseOrigin>
33
34
  <casePriority>High</casePriority>
35
+ <caseOwner>OWNER_USERNAME_OR_QUEUE</caseOwner>
36
+ <caseOwnerType>User</caseOwnerType>
34
37
  </routingAddresses>
35
38
  </emailToCase>
36
39
  </CaseSettings>
@@ -0,0 +1,43 @@
1
+ # Delegation contract — how to behave when an orchestrator delegates to you
2
+
3
+ This is the shared definition of how a skill behaves when it is driven as a leaf by an
4
+ orchestrator (for example Service Onboarding). Follow it verbatim when `delegationFrom` is
5
+ set on the call.
6
+
7
+ ## Entry modes
8
+
9
+ This skill stands on its own for a direct user, **and** can be driven as a leaf by an orchestrator.
10
+ It is one skill with two entry modes, decided by a single **runtime** signal, `delegationFrom`.
11
+ Branch on `delegationFrom`: when it is set, you were called this turn by an orchestrator; when it is absent, treat the run as a direct, standalone
12
+ conversation and use the skill's normal opening.
13
+
14
+ When delegated, three runtime values arrive with the call:
15
+
16
+ | Value | Meaning | Source |
17
+ |---|---|---|
18
+ | `intent` | Prose of what to build this turn — cites the upstream facts the orchestrator already gathered. | The orchestrator's plan / feature-mapping row. |
19
+ | `delegationFrom` | Who's driving — e.g. `"service-onboarding"`. Set **only** when delegated this turn. | Constant the orchestrator passes. |
20
+ | `discoveryMode` | How the user is being guided — tunes how you phrase things (see below). | Carried from discovery. |
21
+
22
+ **When `delegationFrom` is set, adjust as follows (the skill's own write mechanics are unchanged —
23
+ delegation changes only the entry, the confirmation cadence, and the wording):**
24
+
25
+ - **Skip the standalone orientation + menu.** The orchestrator already oriented the user and chose
26
+ this skill; don't re-offer a top-level menu or re-explain what the feature is.
27
+ - **Read facts from `intent` first, ask only your own missing fields.** Only ask the user for a value
28
+ the `intent` genuinely leaves open; don't re-ask what's already been answered upstream.
29
+ - **Confirmation cadence:** announce every write as you do it, but **don't re-confirm each write** —
30
+ the upstream plan was already approved by the user. **Still explicitly confirm genuinely
31
+ irreversible actions**, and always confirm the **target org** before the first write.
32
+ - **Never fabricate values.** Defaults-yes, fabrication-no: if the `intent` doesn't carry a required
33
+ value, ask — don't invent one.
34
+ - **Single-hop leaf — return control, don't look ahead.** Do your work and hand control back to the
35
+ orchestrator. Don't ask "what would you like to do next?", and don't re-delegate onward.
36
+ - **Respect headless limits.** If part of the work needs a browser the current surface can't provide,
37
+ do what the API allows, report what remains, and hand back — never fabricate the result.
38
+
39
+ ## Language by `discoveryMode`
40
+
41
+ - **`"guided"` → plain business-user language.** Lead with the outcome, not Salesforce object/field/page names.
42
+ - **Any other mode (or a direct user) → normal Salesforce terms**, as elsewhere in this skill.
43
+ - Same writes either way — only the wording changes.
@@ -0,0 +1,22 @@
1
+ # Attaching an Agentforce service agent (delegation)
2
+
3
+ When the user wants an Agentforce Service Agent to answer these emails, configure the Email-to-Case base first (the Workflow in `SKILL.md`), then delegate. This skill never creates or modifies agents.
4
+
5
+ ## Gate on org capability first
6
+
7
+ Attaching an agent needs the org entitled for Agentforce Email-to-Case. That entitlement surfaces as the `BotEmailDefinition` metadata type, so probe read-only **before delegating**:
8
+
9
+ ```bash
10
+ scripts/check-agent-email-capability.sh <target-org-alias> # pins describe to the org's API version
11
+ ```
12
+
13
+ This probe is the **only** place the skill uses the `sf` CLI: no dispatch route can list the org's metadata types yet. It needs the CLI alias of the same org the dispatch server is bound to.
14
+
15
+ - Exit **3** → not entitled: **stop, tell the user, and configure the plain Email-to-Case base only. Make no Agentforce agent or channel-wiring changes.**
16
+ - Any other non-zero → the org is unreachable, which is not "not entitled". Fix auth and re-run.
17
+ - Exit **0** → delegate, as below.
18
+
19
+ ## Delegate
20
+
21
+ 1. **Agent creation → `agentforce-generate`.** Omit the **Service Customer Verification topic** (unsupported on the email channel) and include an **Escalation subagent** so the agent can hand off to a human. On email, escalation transfers the case to a service rep; without the subagent the agent can't escalate.
22
+ 2. **Wiring → `service-agentforce-channel-configure` Branch C.**
@@ -1,7 +1,7 @@
1
1
  # Email-to-Case Apply Mechanics (why the write is shaped this way)
2
2
 
3
3
  Load-bearing design rationale behind `apply-casesettings.py`. Read this before changing
4
- how the script builds or sequences its `updateMetadata` payloads. Do not substitute a
4
+ how the script builds or sequences its write payloads. Do not substitute a
5
5
  plain deploy or a minimal patch.
6
6
 
7
7
  ## Why two phases (and not a single file-based deploy)
@@ -10,9 +10,10 @@ Enabling On-Demand Email-to-Case provisions the org's internal email-service
10
10
  infrastructure, and a routing address can only bind to that infrastructure in a
11
11
  **subsequent** operation. A single file-based deploy (`sf project deploy`) that both
12
12
  enables On-Demand and declares a routing address **fails on a freshly-configured org** —
13
- verified on clean orgs. `apply-casesettings.py` therefore reads current settings, applies
14
- the **complete `emailToCase` block** (toggles) plus Support Settings in one `updateMetadata`
15
- call (Phase A), then re-reads and appends routing addresses in a second call (Phase B).
13
+ verified on clean orgs. The flow therefore reads current settings, applies the **complete
14
+ `emailToCase` block** (toggles) plus Support Settings in one PUT to `/headless/metadata`
15
+ (Phase A), then re-reads and appends routing addresses in a second PUT (Phase B).
16
+ `apply-casesettings.py` builds each PUT and validates each response; the agent dispatches them.
16
17
 
17
18
  ## Two load-bearing properties of the write
18
19
 
@@ -52,10 +53,12 @@ separately for exactly this reason.
52
53
 
53
54
  ## Routing-address ordering (multi-address preservation)
54
55
 
55
- The `updateMetadata` call **replaces the `routingAddresses` collection wholesale**.
56
+ The write **may replace the `routingAddresses` collection wholesale**.
56
57
  An already-provisioned address is **dropped** if a brand-new address follows it in
57
58
  document order. Therefore the script **emits new addresses before** the carried-over
58
- existing ones, so existing addresses always survive.
59
+ existing ones, so existing addresses always survive. (A PUT on a fresh test org kept an
60
+ existing address regardless of order; the ordering is retained as a cheap safeguard until
61
+ more orgs confirm it is unnecessary.)
59
62
 
60
63
  The platform-managed read-only fields (`emailServicesAddress` / `isVerified`) do **not**
61
64
  affect this — only document order does. As defensive hygiene the script still strips those
@@ -64,10 +67,10 @@ preservation mechanism; ordering is. A runtime **preservation guard** baselines
64
67
  expected address count (`initial address count + created count`) captured before Phase A and
65
68
  **fails the run loudly** if any existing address is dropped anyway.
66
69
 
67
- ## API version derivation
70
+ ## API version
68
71
 
69
- The Metadata API version is `max(org apiVersion, 67.0)` — derived from the org and floored
70
- at the skill's `minApiVersion` (`67.0`). This keeps every field the skill sets valid while
71
- auto-adopting newer org features (e.g. a v68+ org that supports the `botEmailDefinition`
72
- binding for Agentforce for Service on Email is picked up automatically). It never claims a
73
- version the org doesn't report. `--api-version` forces a specific value.
72
+ Request paths are unversioned (`/headless/metadata` is `/services/data/headless/metadata`,
73
+ SOQL is `/services/data/query`); the dispatch server injects the org's own API version,
74
+ reported in the response `url`. Dispatch rejects `GET /services/data`, so the version
75
+ cannot be listed. To pin one (e.g. to force the v68+ `botEmailDefinition` binding), pass
76
+ `--api-version X.Y` to `requests`, `phase-a`, `phase-b`.
@@ -0,0 +1,14 @@
1
+ # End-to-end proof (Act 3)
2
+
3
+ On a direct run, offer once to prove that inbound email creates Cases; on a delegated run only if the user asks. It is a live round-trip; skip it if declined. The skill never sends email. It orchestrates two human actions, then verifies with read-only queries.
4
+
5
+ 1. **Address ownership.** Salesforce emails a confirmation link; `isVerified` flips only when the human clicks it. Tell the user to click it and **wait**.
6
+ 2. **Send a test email.** Ask the user to send one real email from an external mailbox to the routing address's Salesforce-generated **email services address** (not the customer-facing address, which only receives mail once forwarding is configured). Ask who the sender was, and **wait**.
7
+ 3. **Verify with evidence.** Run `requests cases [--supplied-email <external-sender-address>]` and dispatch it. Then run `requests messages --cases-response <file>`, dispatch that, and run:
8
+
9
+ ```bash
10
+ python3 scripts/apply-casesettings.py cases --cases <cases-file> --messages <messages-file> \
11
+ [--supplied-email <external-sender-address>]
12
+ ```
13
+
14
+ Read-only (`dispatch_readonly` only). It checks `Case` where `Origin='Email'` (last 3 days, optionally narrowed by sender) plus the linked incoming `EmailMessage` rows (`Incoming=true`, `ParentId` = the new Case). It exits **non-zero if no matching Case has a linked incoming email**: the mail isn't processed yet (wait and re-run), or the address isn't verified. On success it prints the `Case` + `EmailMessage` evidence with `proven: true`.
@@ -0,0 +1,66 @@
1
+ # Pre-scan, delegated runs, and wording
2
+
3
+ Read this at step 1 of the Workflow, in both entry modes. The generic delegation rules (skip the orientation menu, announce writes, hand control back, never fabricate a value) apply as the orchestrator defines them. This file holds only what is specific to Email-to-Case.
4
+
5
+ **Entry mode.** `delegationFrom` set means an orchestrator called you this turn and `intent` carries what to build; anything the `intent` states (a routing email, an owner, a toggle choice) counts as the user's answer and is not asked again. `delegationFrom` absent means a direct user: their first message plays the role of the `intent`, and anything it leaves out is asked. Either way, a value that is neither in the `intent` nor given by the user is asked for. It is never invented.
6
+
7
+ ## 1. Pre-scan: what is already set up
8
+
9
+ After the org read (the read-only pre-scan does not wait for `gate`), run `requests settings`, dispatch it, save the response as the **initial read**, and run `read --response <file>`. The output is the whole `CaseSettings` record. Classify with these fields:
10
+
11
+ | Field in `read` output | Means |
12
+ |---|---|
13
+ | `emailToCase.enableEmailToCase` | Email-to-Case is on. Once true it stays on. |
14
+ | `emailToCase.enableOnDemandEmailToCase` | On-Demand is on. Addresses need it. |
15
+ | `emailToCase.enableHtmlEmail`, `notifyOwnerOnNewCaseEmail`, `enableE2CDeduplicateAttachments`, `showWordCountInComposer`, and top-level `enableDraftEmails` | The optional toggles as they are now. |
16
+ | `emailToCase.routingAddresses` (one object or a list) | Existing addresses. A requested address already exists when its `routingName` or `emailAddress` matches. |
17
+ | `defaultCaseOwner`, `defaultCaseUser`, `useSystemUserAsDefaultCaseUser` | Support Settings already configured. |
18
+
19
+ | Pre-scan finds | The intent says | Action |
20
+ |---|---|---|
21
+ | `enableEmailToCase` absent or false | n/a | Nothing set up. Proceed; announce each write. If only `enableOnDemandEmailToCase` is missing while Email-to-Case is on, proceed the same way and leave out the permanence sentence. |
22
+ | On, and every requested toggle and address is already there | n/a | **No change.** Say what is there, run `verify`, hand back. No write, no confirmation. |
23
+ | On, and the intent only adds an address that is not there | Implies "add" | Announce the existing setup and add it. No question beyond the single confirmation (§2). |
24
+ | On, and the intent wants a different value for a setting that already has one | Implies "override" | Ask once, naming the old and new value. |
25
+ | On, and the intent does not say what to do | Silent | Ask once: make no changes, override the previous settings, or just add to them. |
26
+
27
+ On an org that already has Email-to-Case, build the source file from **only what the user chose to change** plus the two required switches (already on). Do not copy the template's default toggles: they would switch back on a toggle an admin turned off. A source file that adds no address needs `--no-addresses-ok` on `validate-casesettings.py` (step 8), and `phase-b` then skips. Support Settings keep their current values unless the user asks to change one (`--overwrite-support-settings`). Editing or deleting an existing routing address is not supported here: say so and offer to add a new one.
28
+
29
+ ## 2. One confirmation before the first write
30
+
31
+ Ask once, before the first write, in every mode and for every org type. Plan approval upstream does not replace it.
32
+
33
+ - Name the org and its type (`gate` read it): "I'll set up email support on `<org>` (`<sandbox | production>`)."
34
+ - Only when `enableEmailToCase` is not yet on, add that turning it on is permanent and affects the whole org.
35
+ - Production, or an org type `gate` cannot read: the same yes unlocks `--confirm-production`. Never add the flag before the user says yes in this run.
36
+ - Nothing to change: no write, so no confirmation.
37
+
38
+ ## 3. Wording by `discoveryMode`
39
+
40
+ `"guided"` means ask about the process in the customer's words and keep Salesforce terms out of the question. Any other mode, or a direct user, uses the Salesforce terms in the Workflow. The writes are the same either way.
41
+
42
+ | Salesforce terms | Guided wording |
43
+ |---|---|
44
+ | Customer-facing email address for the routing address | What email address do your customers write to for support? |
45
+ | Address type `EmailToCase` / `Outlook` / `GmailOAuth` | Where does this mailbox live: will you forward its mail to Salesforce, or connect a Microsoft 365 or Gmail account? |
46
+ | Case origin and case priority for the address | What should show as the source of cases from this address (usually Email), and how urgent should they be by default? |
47
+ | Per-address Default Case Owner | Should emails to this address go to a specific person or team, or follow your usual case assignment? |
48
+ | Default Case Owner | When a new case arrives and no assignment rule claims it, who should it land with: a person or a team's queue? |
49
+ | Automated Case User | Automatic case actions such as escalations and rule-based assignment are recorded under one user. Should that be a named person or the standard system user? |
50
+ | Enable HTML email | Let agents send formatted emails with images and styling. |
51
+ | Eliminate duplicate email attachments | Don't save an attachment again if it is already on the case. |
52
+ | Show word count in composer | Show a word count while agents write a reply. |
53
+ | Notify case owners on new emails | Tell the case owner when a new email arrives on their case. |
54
+ | Enable Email Drafts | Let agents save a reply as a draft. |
55
+ | Turning on Email-to-Case is permanent and org-wide | Once email support is on it can't be switched off, and it applies to the whole org. |
56
+
57
+ Guided mode never says Metadata API, `CaseSettings`, On-Demand, or a field name. When you state the optional toggles that will be turned on, state them in the guided wording above.
58
+
59
+ ## 4. Permission and availability messages
60
+
61
+ - **The user lacks the setup permission** (the Customize Application check fails, or a write is refused for permissions): "Please ask your admin to enable the setup permission for Email-to-Case for you, using https://help.salesforce.com/s/articleView?id=service.setting_up_email-to-case.htm&type=5". Make no further writes.
62
+ - **Email-to-Case is not available in the org** (the skill is unavailable or cannot run): give the same article so the user can set it up from Setup, and stop.
63
+
64
+ ## 5. After the write: validate and hand back
65
+
66
+ Run `verify`, then report in the mode's wording: what is now set, what was left as it was, and what the user still has to do (forward mail to the generated address, verify the routing address). The inbound-email proof (`references/end-to-end-proof.md`) is optional: offer it once on a direct run, never on a delegated run (only if asked). When delegated, then hand control back: no "what next?", no offer to configure another feature.