@salesforce/afv-skills 1.31.0 → 1.32.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 (98) hide show
  1. package/package.json +1 -1
  2. package/skills/agentforce-bot-upgrade/SKILL.md +217 -0
  3. package/skills/agentforce-bot-upgrade/references/extraction-blueprint.md +242 -0
  4. package/skills/agentforce-bot-upgrade/references/generate-agent-spec.md +128 -0
  5. package/skills/agentforce-bot-upgrade/references/handoff-output-format.md +208 -0
  6. package/skills/agentforce-bot-upgrade/references/input-contract.md +101 -0
  7. package/skills/agentforce-bot-upgrade/references/mapping-rules.md +113 -0
  8. package/skills/agentforce-bot-upgrade/references/planner-workflow-reference.md +78 -0
  9. package/skills/agentforce-bot-upgrade/references/post-conversion-enhancements-reference.md +67 -0
  10. package/skills/agentforce-bot-upgrade/references/quality-checklist.md +33 -0
  11. package/skills/agentforce-bot-upgrade/references/sf-cli-bot-reference.md +116 -0
  12. package/skills/dx-devops-work-item-manage/SKILL.md +270 -0
  13. package/skills/dx-devops-work-item-manage/examples/common-workflows.md +479 -0
  14. package/skills/dx-devops-work-item-manage/references/cli-commands.md +476 -0
  15. package/skills/dx-org-manage/SKILL.md +8 -5
  16. package/skills/dx-org-trial-expiration-check/SKILL.md +239 -0
  17. package/skills/dx-org-trial-expiration-check/scripts/check_expiration.sh +588 -0
  18. package/skills/experience-ui-bundle-app-coordinate/SKILL.md +12 -9
  19. package/skills/experience-ui-bundle-custom-app-generate/SKILL.md +29 -5
  20. package/skills/experience-ui-bundle-custom-app-generate/references/configure-metadata-custom-application.md +1 -1
  21. package/skills/experience-ui-bundle-custom-app-generate/scripts/resolve-uibundle-path.sh +30 -0
  22. package/skills/experience-ui-bundle-features-generate/SKILL.md +86 -11
  23. package/skills/experience-ui-bundle-features-generate/references/conflict-resolution-schema.json +20 -0
  24. package/skills/experience-ui-bundle-features-generate/scripts/verify-react-bundle.sh +14 -0
  25. package/skills/experience-ui-bundle-frontend-generate/SKILL.md +6 -1
  26. package/skills/experience-ui-bundle-frontend-generate/references/component.md +34 -1
  27. package/skills/experience-ui-bundle-frontend-generate/references/page.md +1 -1
  28. package/skills/experience-ui-bundle-project-generate/SKILL.md +111 -0
  29. package/skills/experience-ui-bundle-project-generate/scripts/flatten-project.mjs +33 -0
  30. package/skills/platform-custom-lightning-type-generate/SKILL.md +9 -14
  31. package/skills/platform-custom-lightning-type-generate/references/widget-rendition.md +27 -111
  32. package/skills/platform-lightning-type-widget-coordinate/SKILL.md +214 -0
  33. package/skills/platform-lightning-type-widget-coordinate/examples/existing-lightning-type-with-widget-prompt.md +80 -0
  34. package/skills/platform-lightning-type-widget-coordinate/examples/new-lightning-type-with-widget-prompt.md +75 -0
  35. package/skills/platform-lightning-type-widget-coordinate/references/build-plan-format.md +67 -0
  36. package/skills/platform-lightning-type-widget-coordinate/references/lightning-type-discovery.md +124 -0
  37. package/skills/platform-lightning-type-widget-coordinate/references/validation-gates.md +130 -0
  38. package/skills/platform-sharing-owd-configure/SKILL.md +142 -0
  39. package/skills/platform-sharing-owd-configure/examples/get_owd_output.md +38 -0
  40. package/skills/platform-sharing-owd-configure/examples/update_owd_output.md +44 -0
  41. package/skills/platform-sharing-owd-configure/references/access_levels.md +49 -0
  42. package/skills/platform-sharing-owd-configure/references/metadata_api_approach.md +69 -0
  43. package/skills/platform-sharing-rules-generate/SKILL.md +89 -19
  44. package/skills/platform-sharing-rules-generate/examples/test-cases.md +381 -0
  45. package/skills/platform-widget-generate/SKILL.md +241 -0
  46. package/skills/platform-widget-generate/examples/conditional.json +73 -0
  47. package/skills/platform-widget-generate/examples/list-with-foreach.json +66 -0
  48. package/skills/platform-widget-generate/examples/single-object.json +64 -0
  49. package/skills/platform-widget-generate/references/schema-from-lightning-type.md +76 -0
  50. package/skills/platform-widget-generate/references/widget-bundle-layout.md +116 -0
  51. package/skills/platform-widget-generate/references/widget-meta-directives.md +130 -0
  52. package/skills/sales-agentforce-pipeline-management-configure/SKILL.md +268 -0
  53. package/skills/sales-agentforce-pipeline-management-configure/assets/field-completion-template.genAiPromptTemplate-meta.xml +141 -0
  54. package/skills/sales-agentforce-pipeline-management-configure/assets/pipeline_management_flow.flow-meta.xml +548 -0
  55. package/skills/sales-agentforce-pipeline-management-configure/assets/sales_management_agent.agent +2938 -0
  56. package/skills/sales-agentforce-pipeline-management-configure/assets/sales_management_agent.bundle-meta.xml +4 -0
  57. package/skills/sales-agentforce-pipeline-management-configure/assets/sfdx-project.json +12 -0
  58. package/skills/sales-agentforce-pipeline-management-configure/assets/stage-descriptions/bant.txt +11 -0
  59. package/skills/sales-agentforce-pipeline-management-configure/assets/stage-descriptions/meddic.txt +11 -0
  60. package/skills/sales-agentforce-pipeline-management-configure/assets/stage-descriptions/spiced.txt +11 -0
  61. package/skills/sales-agentforce-pipeline-management-configure/examples/custom-prompt-instructions.md +317 -0
  62. package/skills/sales-agentforce-pipeline-management-configure/references/admin-communication.md +355 -0
  63. package/skills/sales-agentforce-pipeline-management-configure/references/agent-creation.md +383 -0
  64. package/skills/sales-agentforce-pipeline-management-configure/references/auth-and-cli.md +146 -0
  65. package/skills/sales-agentforce-pipeline-management-configure/references/automation-matrix.md +23 -0
  66. package/skills/sales-agentforce-pipeline-management-configure/references/autonomous-updates.md +215 -0
  67. package/skills/sales-agentforce-pipeline-management-configure/references/canonical-agent-path.md +75 -0
  68. package/skills/sales-agentforce-pipeline-management-configure/references/data-sources.md +155 -0
  69. package/skills/sales-agentforce-pipeline-management-configure/references/field-completion-prompt-template.md +120 -0
  70. package/skills/sales-agentforce-pipeline-management-configure/references/field-completion-prompts.md +149 -0
  71. package/skills/sales-agentforce-pipeline-management-configure/references/flags.md +13 -0
  72. package/skills/sales-agentforce-pipeline-management-configure/references/flow-clone-from-template.md +447 -0
  73. package/skills/sales-agentforce-pipeline-management-configure/references/metadata-inventory.md +330 -0
  74. package/skills/sales-agentforce-pipeline-management-configure/references/opportunity-stages.md +246 -0
  75. package/skills/sales-agentforce-pipeline-management-configure/references/repair-diagnostics.md +265 -0
  76. package/skills/sales-agentforce-pipeline-management-configure/references/setup-order.md +263 -0
  77. package/skills/sales-agentforce-pipeline-management-configure/references/soap-api-enablement.md +528 -0
  78. package/skills/sales-agentforce-pipeline-management-configure/scripts/CHANGES.md +180 -0
  79. package/skills/sales-agentforce-pipeline-management-configure/scripts/README.md +56 -0
  80. package/skills/sales-agentforce-pipeline-management-configure/scripts/add-field-suggestion.sh +679 -0
  81. package/skills/sales-agentforce-pipeline-management-configure/scripts/create-agent.sh +302 -0
  82. package/skills/sales-agentforce-pipeline-management-configure/scripts/create-flow.sh +250 -0
  83. package/skills/sales-agentforce-pipeline-management-configure/scripts/define-agent-access.sh +430 -0
  84. package/skills/sales-agentforce-pipeline-management-configure/scripts/deploy-settings.sh +77 -0
  85. package/skills/sales-agentforce-pipeline-management-configure/scripts/enable-deal-agent.sh +241 -0
  86. package/skills/sales-agentforce-pipeline-management-configure/scripts/enable-prerequisites.sh +538 -0
  87. package/skills/sales-agentforce-pipeline-management-configure/scripts/flow-debug-and-verify.sh +385 -0
  88. package/skills/sales-agentforce-pipeline-management-configure/scripts/retrieve-settings.sh +131 -0
  89. package/skills/sales-agentforce-pipeline-management-configure/scripts/setup-all.sh +2791 -0
  90. package/skills/sales-agentforce-pipeline-management-configure/scripts/shared/agent-bundle-publish.sh +189 -0
  91. package/skills/sales-agentforce-pipeline-management-configure/scripts/shared/agent-detection.sh +239 -0
  92. package/skills/sales-agentforce-pipeline-management-configure/scripts/shared/flow-builder.sh +238 -0
  93. package/skills/sales-agentforce-pipeline-management-configure/scripts/shared/psg.sh +48 -0
  94. package/skills/sales-agentforce-pipeline-management-configure/scripts/shared/soap.sh +140 -0
  95. package/skills/sales-agentforce-pipeline-management-configure/scripts/shared/stage-descriptions.sh +448 -0
  96. package/skills/sales-agentforce-pipeline-management-configure/scripts/shared/test-opp.sh +166 -0
  97. package/skills/sales-agentforce-pipeline-management-configure/scripts/verify-all.sh +636 -0
  98. package/skills/sales-agentforce-pipeline-management-configure/scripts/verify-prompt-generation.sh +346 -0
@@ -0,0 +1,383 @@
1
+ # Agent Creation and Activation
2
+
3
+ A standalone `BotDefinition:SalesAgent` is **REQUIRED** for Pipeline Management. Auto-provisioning creates it in most editions; where it does not, the setup scripts publish it from the authoring bundle. Users need the interactive chat surface, so treating "Platform Copilot only" as acceptable leaves setup incomplete — the scripts enforce this and will fail without it.
4
+
5
+ ---
6
+
7
+ ## Required Components
8
+
9
+ Every Pipeline Management org must have all three of the following:
10
+
11
+ - ✅ **Agent user** — `salesmanagementagentuser@<uuid>.ext`; runs the schedule-triggered suggestion flow
12
+ - ✅ **Permission set groups** — `SalesManagementUserPsg` (end users) and `SalesManagementAgentUserPsg` (agent user); the second must be assigned to the agent user so the flow can read/write opportunities
13
+ - ✅ **`BotDefinition:SalesAgent`** — active; enables the interactive chat interface
14
+
15
+ The schedule-triggered flow (`Process_Field_Update_Suggestions`) runs as the agent user and calls `getOrExecFieldUpdtSuggestion` actions directly. The BotDefinition is what lets users chat with the agent — it is not optional.
16
+
17
+ `create-agent.sh` and `setup-all.sh` enforce all three: if `BotDefinition:SalesAgent` is missing, they publish it via `sf agent publish authoring-bundle --api-name SalesAgent` (wrapped by `publish_and_activate_agent()` in `shared/agent-bundle-publish.sh`) and activate it. `GenAiPlannerDefinition:EmployeeCopilotPlanner` may still be present alongside the BotDefinition — that is fine, but it does not substitute for the BotDefinition.
18
+
19
+ ---
20
+
21
+ ## Agent Type Distinction
22
+
23
+ Pipeline Management's required agent is a **classic Bot agent** (metadata type: `BotDefinition`/`Bot`), developer name `SalesAgent`. `GenAiPlannerDefinition:EmployeeCopilotPlanner` (metadata type: `GenAiPlannerDefinition`) may also be present in the org; when it is, PM plugins wire into it, but the planner does not replace the required `BotDefinition`.
24
+
25
+ The `sf agent generate authoring-bundle` / `sf agent publish authoring-bundle` CLI commands publish an `AiAuthoringBundle` that creates the required `BotDefinition:SalesAgent`. The authoring bundle asset in `assets/` is the canonical fallback path when auto-provisioning did not create the BotDefinition — it is not a last-resort curiosity, it is what `create-agent.sh` and `setup-all.sh` invoke.
26
+
27
+ ---
28
+
29
+ ## Detection: Verify Required Components
30
+
31
+ ```bash
32
+ ORG="pipeline-mgmt-org"
33
+
34
+ # Step 1: Check for agent user (PRIMARY functional indicator)
35
+ sf data query -q "SELECT Id, Username FROM User WHERE Username LIKE '%salesmanagementagentuser%'" --target-org $ORG --json 2>/dev/null
36
+
37
+ # Step 2: Check for standalone BotDefinition (standard SOQL — NOT --use-tooling-api)
38
+ sf data query -q "SELECT Id, DeveloperName FROM BotDefinition WHERE DeveloperName = 'SalesAgent'" --target-org $ORG --json 2>/dev/null
39
+
40
+ # Step 3: Check for Platform Copilot planner (Tooling API) — informational only; presence does NOT substitute for BotDefinition
41
+ sf data query -q "SELECT Id, DeveloperName FROM GenAiPlannerDefinition WHERE DeveloperName = 'EmployeeCopilotPlanner'" --target-org $ORG --use-tooling-api --json 2>/dev/null
42
+
43
+ # Step 4: Check PSG assignment to agent user
44
+ AGENT_USER_ID=$(sf data query -q "SELECT Id FROM User WHERE Username LIKE '%salesmanagementagentuser%'" --target-org $ORG --json 2>/dev/null | jq -r '.result.records[0].Id')
45
+ sf data query -q "SELECT PermissionSetGroup.DeveloperName FROM PermissionSetAssignment WHERE AssigneeId = '${AGENT_USER_ID}' AND PermissionSetGroupId != null" --target-org $ORG --json 2>/dev/null
46
+ ```
47
+
48
+ **Decision matrix**:
49
+
50
+ | Agent User | BotDefinition | Planner | Result | Action |
51
+ |-----------|---------------|---------|--------|--------|
52
+ | ✅ | ✅ | any | **Complete** — all required components present | ✅ No action needed |
53
+ | ✅ | ❌ | any | **Missing BotDefinition** — required for chat surface | **Publish authoring bundle** (`sf agent publish authoring-bundle --api-name SalesAgent`) — this is the ONLY path that creates the BotDefinition |
54
+ | ❌ | any | any | **Provisioning failed** — no agent user | See Creation Methods below: SOAP toggle re-provisions agent user + PSGs; then publish the bundle to create the BotDefinition |
55
+
56
+ The Planner column is informational: `EmployeeCopilotPlanner` may or may not be present in the org, but its presence never substitutes for `BotDefinition:SalesAgent`.
57
+
58
+ ---
59
+
60
+ ## Creation Method 1: Auto-Provisioning + Bundle Publish (Primary)
61
+
62
+ When Pipeline Management (`SalesDealAgentSettings.enableDealAgent`) is enabled, the platform auto-provisions:
63
+ - Agent user (`salesmanagementagentuser@<uuid>.ext`)
64
+ - Permission set groups `SalesManagementUserPsg` and `SalesManagementAgentUserPsg` (the latter assigned to the agent user)
65
+
66
+ Enabling `enableDealAgent` does NOT create `BotDefinition:SalesAgent`. The BotDefinition must be created explicitly by publishing the authoring bundle:
67
+
68
+ ```bash
69
+ sf agent publish authoring-bundle --api-name SalesAgent --target-org $ORG --json
70
+ ```
71
+
72
+ `create-agent.sh` and `setup-all.sh` invoke this via `publish_and_activate_agent()` in `shared/agent-bundle-publish.sh`. **Publishing the bundle is the only path that creates the BotDefinition** — see Method 2 for cases where the agent user or PSGs are also missing.
73
+
74
+ ---
75
+
76
+ ## Creation Method 2: SOAP Toggle (agent user + PSGs only — does NOT create the BotDefinition)
77
+
78
+ If the **agent user** or **permission set groups** are missing (auto-provisioning did not complete), toggling `SalesDealAgentSettings.enableDealAgent` off and back on re-runs the platform provisioning and re-creates them. This does **NOT** create the `BotDefinition:SalesAgent` — you must still publish the authoring bundle (Method 1) afterward.
79
+
80
+ **When to use**: agent user query returns 0 records, or PSGs are missing. Do NOT use this to try to "re-provision" a missing BotDefinition — the toggle has never created a BotDefinition and never will.
81
+
82
+ **Warning**: Disabling Pipeline Management temporarily removes the agent user and PSGs, which stops in-flight suggestion generation.
83
+
84
+ ### Toggle Script
85
+
86
+ ```bash
87
+ ORG="pipeline-mgmt-org"
88
+ AUTH_INFO=$(sf org display --target-org $ORG --json 2>/dev/null)
89
+ ACCESS_TOKEN=$(echo "$AUTH_INFO" | jq -r '.result.accessToken')
90
+ INSTANCE_URL=$(echo "$AUTH_INFO" | jq -r '.result.instanceUrl')
91
+
92
+ echo "=== Step 1: Disable Pipeline Management ==="
93
+ curl -s "${INSTANCE_URL}/services/Soap/m/64.0" \
94
+ -H "Content-Type: text/xml; charset=UTF-8" \
95
+ -H "SOAPAction: update" \
96
+ -d "<?xml version='1.0' encoding='utf-8'?>
97
+ <soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:met='http://soap.sforce.com/2006/04/metadata'>
98
+ <soapenv:Header><met:SessionHeader><met:sessionId>${ACCESS_TOKEN}</met:sessionId></met:SessionHeader></soapenv:Header>
99
+ <soapenv:Body><met:updateMetadata>
100
+ <met:metadata xsi:type='met:SalesDealAgentSettings' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
101
+ <met:fullName>SalesDealAgent</met:fullName>
102
+ <met:enableDealAgent>false</met:enableDealAgent>
103
+ </met:metadata>
104
+ </met:updateMetadata></soapenv:Body>
105
+ </soapenv:Envelope>" | xmllint --format - 2>/dev/null | grep -E "(success|message)"
106
+
107
+ echo "=== Waiting 10 seconds for propagation ==="
108
+ sleep 10
109
+
110
+ echo "=== Step 2: Re-enable Pipeline Management ==="
111
+ curl -s "${INSTANCE_URL}/services/Soap/m/64.0" \
112
+ -H "Content-Type: text/xml; charset=UTF-8" \
113
+ -H "SOAPAction: update" \
114
+ -d "<?xml version='1.0' encoding='utf-8'?>
115
+ <soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:met='http://soap.sforce.com/2006/04/metadata'>
116
+ <soapenv:Header><met:SessionHeader><met:sessionId>${ACCESS_TOKEN}</met:sessionId></met:SessionHeader></soapenv:Header>
117
+ <soapenv:Body><met:updateMetadata>
118
+ <met:metadata xsi:type='met:SalesDealAgentSettings' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
119
+ <met:fullName>SalesDealAgent</met:fullName>
120
+ <met:enableDealAgent>true</met:enableDealAgent>
121
+ <met:enableDealAgentAutoApproveAllTasks>false</met:enableDealAgentAutoApproveAllTasks>
122
+ </met:metadata>
123
+ </met:updateMetadata></soapenv:Body>
124
+ </soapenv:Envelope>" | xmllint --format - 2>/dev/null | grep -E "(success|message)"
125
+
126
+ echo "=== Waiting 30 seconds for agent provisioning ==="
127
+ sleep 30
128
+
129
+ echo "=== Verifying agent exists ==="
130
+ sf data query -q "SELECT Id, DeveloperName FROM BotDefinition WHERE DeveloperName = 'SalesAgent'" --target-org $ORG --json 2>/dev/null
131
+ ```
132
+
133
+ **Why this works**: Disabling Pipeline Management deprovisions the auto-created agent user and PSGs; re-enabling triggers a fresh provisioning cycle that re-creates them. The `BotDefinition:SalesAgent` is **not** touched by this cycle in either direction — publishing the authoring bundle (Method 1) is the only way to create it.
134
+
135
+ **Risk**: If the org had custom configurations wired to the PSGs (permission set component additions, custom user assignments), these may be lost. Use this method **only when the agent user or PSGs are missing** — for a missing BotDefinition, go straight to Method 1.
136
+
137
+ ---
138
+
139
+ ## Creation Method 3: Metadata API Deploy (Manual)
140
+
141
+ If the SOAP toggle approach doesn't create the agent (rare — usually indicates missing prerequisites), deploy Bot metadata directly:
142
+
143
+ ```bash
144
+ ORG="pipeline-mgmt-org"
145
+
146
+ # 1. Check if another org has a working SalesAgent to use as reference
147
+ # Or create the metadata from scratch:
148
+ mkdir -p force-app/main/default/bots
149
+
150
+ cat > force-app/main/default/bots/SalesAgent.bot-meta.xml << 'EOF'
151
+ <?xml version="1.0" encoding="UTF-8"?>
152
+ <Bot xmlns="http://soap.sforce.com/2006/04/metadata">
153
+ <fullName>SalesAgent</fullName>
154
+ <label>Sales Management Agent</label>
155
+ <description>Provides opportunity field update suggestions based on notes, emails, and conversation insights.</description>
156
+ <type>Bot</type>
157
+ <status>Active</status>
158
+ </Bot>
159
+ EOF
160
+
161
+ # 2. Deploy
162
+ sf project deploy start --metadata "Bot:SalesAgent" --target-org $ORG --json 2>/dev/null
163
+ ```
164
+
165
+ **Note**: This method requires that all prerequisites are already enabled (Einstein GenAI, Agentforce, Pipeline Management settings). The deployed agent may lack auto-provisioned topics/actions — these must be configured separately. Also, the `<status>Active</status>` above does **not** actually activate the BotVersion (metadata-deploy activation silently fails) — after deploying, activate with `sf agent activate` (see Agent Activation → Method 1).
166
+
167
+ ---
168
+
169
+ ## Activation Verification
170
+
171
+ After creation (any method), verify the agent is active:
172
+
173
+ ```bash
174
+ # Check agent status (standard SOQL — NOT --use-tooling-api)
175
+ sf data query -q "SELECT Id, DeveloperName FROM BotDefinition WHERE DeveloperName = 'SalesAgent'" --target-org $ORG --json 2>/dev/null
176
+
177
+ # If found: agent exists (BotDefinition does not expose Status via SOQL)
178
+ # If 0 records: agent not created (may be normal — see Detection section)
179
+ ```
180
+
181
+ ---
182
+
183
+ ## Agent Activation (if the auto-provisioned BotVersion is Inactive)
184
+
185
+ ### Method 1: `sf agent activate` (PRIMARY — the working method)
186
+
187
+ Publishing the authoring bundle creates the `BotDefinition` and an auto-provisioned
188
+ `BotVersion` that lands **Inactive**. Activate that version directly:
189
+
190
+ ```bash
191
+ sf agent activate --api-name SalesAgent --version 1 --target-org $ORG --json 2>/dev/null
192
+ ```
193
+
194
+ `create-agent.sh` / `setup-all.sh` run this after publishing the bundle. Verify with the
195
+ `BotVersion ... Status = 'Active'` query in the Activation Verification section.
196
+
197
+ > **Do NOT rely on a `Bot:SalesAgent` metadata deploy with `<status>Active</status>`** — it
198
+ > reports success but **silently fails to activate** the BotVersion (org-verified). Use
199
+ > `sf agent activate`.
200
+ >
201
+ > `sf agent activate` (bare) is correct here. `sf agent activate authoring-bundle` is a
202
+ > *different* command that targets Agent Script agents (AiAuthoringBundle) — do NOT use that
203
+ > subcommand for Pipeline Management's BotDefinition agent.
204
+
205
+ ### Method 2: Setup UI (fallback)
206
+
207
+ If `sf agent activate` is unavailable, use Setup:
208
+
209
+ 1. Setup → Agents → Find "Sales Management Agent"
210
+ 2. Click Activate
211
+
212
+ ---
213
+
214
+ ## Agent User Configuration
215
+
216
+ The agent runs as a system user (`salesmanagementagentuser@<uuid>.ext`) that needs:
217
+ 1. **Permission Set Group**: `SalesManagementAgentUserPsg` (auto-assigned on creation)
218
+ 2. **Opportunity Team Member Access**: Agent must be able to join opportunity teams to read/write opportunity fields
219
+
220
+ ### Verify Agent User Permissions
221
+
222
+ ```bash
223
+ # Get agent user ID
224
+ AGENT_USER_ID=$(sf data query -q "SELECT Id FROM User WHERE Username LIKE '%salesmanagementagentuser%'" --target-org $ORG --json 2>/dev/null | jq -r '.result.records[0].Id')
225
+
226
+ # Check PSG assignment
227
+ sf data query -q "SELECT PermissionSetGroup.DeveloperName FROM PermissionSetAssignment WHERE AssigneeId = '${AGENT_USER_ID}' AND PermissionSetGroup.DeveloperName = 'SalesManagementAgentUserPsg'" --target-org $ORG --json 2>/dev/null
228
+
229
+ # Check if agent can query opportunities
230
+ sf data query -q "SELECT COUNT() FROM Opportunity" --target-org $ORG --json 2>/dev/null
231
+ # If this fails, agent doesn't have Read access to opportunities
232
+ ```
233
+
234
+ ### Manual PSG Assignment (if missing)
235
+
236
+ ```bash
237
+ PSG_ID=$(sf data query -q "SELECT Id FROM PermissionSetGroup WHERE DeveloperName = 'SalesManagementAgentUserPsg'" --target-org $ORG --json 2>/dev/null | jq -r '.result.records[0].Id')
238
+
239
+ sf data create record --sobject PermissionSetAssignment --values "AssigneeId='${AGENT_USER_ID}' PermissionSetGroupId='${PSG_ID}'" --target-org $ORG --json 2>/dev/null
240
+ ```
241
+
242
+ ---
243
+
244
+ ## Agent Access — Letting Users Launch the Agent (W-23242378)
245
+
246
+ Creating and activating the agent is **not sufficient** for end users to use it. The agent must also be added to the **Agent Access** section of a permission set that those users hold. Without this, a user assigned `SalesManagementUserPsg` sees the agent as unavailable even though it is active.
247
+
248
+ ### Why a custom permission set is required
249
+
250
+ Agent Access is stored as a `SetupEntityAccess` record with `SetupEntityType='BotDefinition'`. Its `ParentId` must be a **PermissionSet** — and only a **custom** permission set can hold it. `SalesManagementUserPsg` is a **managed** permission set group; its Agent Access cannot be edited directly. So the pattern is:
251
+
252
+ 1. Create a **custom** permission set (`Sales_Agent_Access`, `License = None`).
253
+ 2. Grant Agent Access on it (add the Pipeline Management BotDefinition).
254
+ 3. Add that custom permset as a **component** of `SalesManagementUserPsg`.
255
+ 4. Recalculate the PSG so users inherit the access.
256
+
257
+ ### Automated (recommended)
258
+
259
+ ```bash
260
+ # Idempotent — safe to re-run. Must run AFTER the agent (BotDefinition) exists.
261
+ bash scripts/define-agent-access.sh <org-alias>
262
+ ```
263
+
264
+ `setup-all.sh` runs this automatically (Phase 4c), and `create-agent.sh` calls it at the end.
265
+
266
+ **Bot-timing behavior (exit 0, not exit 1)**: Agent Access can only be defined once the agent exists and has an **Active** `BotVersion`. If the script runs before the agent is created (or before its version is activated), it prints a warning and **exits 0** — a deliberate non-error so that an orchestrating run (`setup-all.sh`) is not aborted just because the agent isn't ready yet. This is why running it early is harmless: re-run it after the agent is active and it will complete the grant. It exits non-zero only for genuine failures (bad org alias, missing `jq`/`sf`, PSG recalculation `Failed`, or an un-tolerated create error).
267
+
268
+ ### Manual / API details
269
+
270
+ ```bash
271
+ ORG="pipeline-mgmt-org"
272
+
273
+ # 1. BotDefinition Id — detect by AgentTemplate (the field the scheduled flow uses),
274
+ # NOT a hardcoded DeveloperName. Only bots with an Active BotVersion qualify.
275
+ # Use a TWO-STEP query, not a correlated subquery: the single-query form
276
+ # `AND Id IN (SELECT BotDefinitionId FROM BotVersion WHERE Status = 'Active')`
277
+ # hangs 60+ seconds on some orgs and was removed in de77d520. First find the
278
+ # bot by AgentTemplate, then confirm it has an Active BotVersion separately.
279
+ BOT_DEF_ID=$(sf data query -q "SELECT Id FROM BotDefinition WHERE AgentTemplate IN ('SalesMgmt__NGASalesAgent','SalesMgmt__SalesAgent') ORDER BY LastModifiedDate DESC LIMIT 1" --target-org $ORG --json 2>/dev/null | jq -r '.result.records[0].Id')
280
+ sf data query -q "SELECT COUNT() FROM BotVersion WHERE BotDefinitionId = '${BOT_DEF_ID}' AND Status = 'Active'" --target-org $ORG --json 2>/dev/null # expect totalSize >= 1
281
+
282
+ # 2. Create the custom permission set (standard Data API — omit License => None; required fields Name + Label)
283
+ PS_ID=$(sf data create record --sobject PermissionSet --values "Name='Sales_Agent_Access' Label='Sales Agent Access'" --target-org $ORG --json 2>/dev/null | jq -r '.result.id')
284
+
285
+ # 3. Grant Agent Access (SetupEntityAccess: Create/Delete/Query only — no Update).
286
+ # Do NOT set SetupEntityType — it is derived from SetupEntityId. Requires API v64.0+.
287
+ sf data create record --sobject SetupEntityAccess --values "ParentId='${PS_ID}' SetupEntityId='${BOT_DEF_ID}'" --target-org $ORG --json 2>/dev/null
288
+
289
+ # 4. Link the custom permset into the managed PSG (PermissionSetGroupComponent is a TOOLING API object)
290
+ PSG_ID=$(sf data query -q "SELECT Id FROM PermissionSetGroup WHERE DeveloperName = 'SalesManagementUserPsg'" --target-org $ORG --use-tooling-api --json 2>/dev/null | jq -r '.result.records[0].Id')
291
+ sf data create record --sobject PermissionSetGroupComponent --values "PermissionSetGroupId='${PSG_ID}' PermissionSetId='${PS_ID}'" --target-org $ORG --use-tooling-api --json 2>/dev/null
292
+
293
+ # 5. Recalculate the PSG (no dedicated CLI verb — the component insert in step 4
294
+ # is what triggers the async recalc; poll PermissionSetGroup.Status via Tooling
295
+ # API until 'Updated'). Status is system-computed, NOT client-writable — writing
296
+ # it (e.g. a PATCH) is rejected with a non-2xx (typically HTTP 400) and does
297
+ # nothing, so the script does not attempt it: polling is the only mechanism.
298
+ ```
299
+
300
+ **Key constraints**:
301
+ - `SetupEntityAccess` requires a **custom** permission set as `ParentId` — a managed/standard permission set is rejected.
302
+ - `SetupEntityType` is read-only/derived — setting it on insert errors.
303
+ - `PermissionSetGroupComponent` is Tooling-API-only (`--use-tooling-api`). A **custom** permset CAN be linked into the **managed** `SalesManagementUserPsg`.
304
+ - Adding a component triggers **automatic async recalculation**; `PermissionSetGroup.Status` is system-computed (Updated/Updating/Outdated/Failed) — poll it, do not try to write it.
305
+ - The BotDefinition is detected by `AgentTemplate` (`SalesMgmt__NGASalesAgent` / `SalesMgmt__SalesAgent`), so the grant matches whatever local name the agent was published with.
306
+ - Two templates exist for historical reasons: `SalesMgmt__SalesAgent` is the **legacy** template, and `SalesMgmt__NGASalesAgent` is the newer **NGA** ("Next-Gen Agent") template that the current authoring bundle publishes. Detection matches either so the script works on both older and newer orgs; when both are present, **NGA is preferred** (it is the forward direction).
307
+ - The autonomous **agent user** does NOT need Agent Access — this is for **human interactive users** only.
308
+
309
+ ---
310
+
311
+ ## Troubleshooting
312
+
313
+ ### Auto-provisioning didn't create agent
314
+
315
+ **Symptom**: Enabled Pipeline Management but `BotDefinition` query returns 0 records
316
+
317
+ **Cause**: Missing prerequisites or edition limitation
318
+
319
+ **Fix**:
320
+ 1. Verify all prerequisites enabled (see `references/setup-order.md`)
321
+ 2. Wait up to 5 minutes (agent user + PSG provisioning is async)
322
+ 3. If the **BotDefinition** is missing → publish the authoring bundle (Method 1) — this is the only path
323
+ 4. If the **agent user or PSGs** are missing → use SOAP toggle (Method 2) to re-provision those, then publish the bundle
324
+ 5. If bundle publish itself fails, fall back to Metadata API deploy (Method 3)
325
+
326
+ ### Agent creation succeeds but agent is not active
327
+
328
+ **Symptom**: `BotDefinition` exists but its `BotVersion` is Inactive
329
+
330
+ **Cause**: Agent was created but the auto-provisioned BotVersion was never activated
331
+
332
+ **Fix**: `sf agent activate --api-name SalesAgent --version 1` (see Agent Activation → Method 1). A `Bot:SalesAgent` metadata deploy with `<status>Active</status>` silently fails to activate — do not rely on it.
333
+
334
+ ### Toggle didn't create the BotDefinition
335
+
336
+ **Symptom**: After toggling `enableDealAgent` off and back on, the agent user and PSGs came back but `BotDefinition:SalesAgent` still returns 0 records.
337
+
338
+ **Cause**: This is expected — the SOAP toggle does not create the BotDefinition. The toggle only re-provisions the agent user and PSGs.
339
+
340
+ **Fix**: Publish the authoring bundle:
341
+ ```bash
342
+ sf agent publish authoring-bundle --api-name SalesAgent --target-org $ORG --json
343
+ ```
344
+ Or run `bash scripts/create-agent.sh <org-alias>`, which wraps `publish_and_activate_agent()` and only publishes when the BotDefinition is missing.
345
+
346
+ If the bundle publish itself fails, verify prerequisites (see `references/setup-order.md`) and check the edition/license in Setup → Company Information.
347
+
348
+ ### Agent exists but doesn't generate suggestions
349
+
350
+ **Symptom**: Agent is active but no `AiGenActionItem` records (`Type = 'FIELD_UPDATE'`) are created
351
+
352
+ **Cause**:
353
+ - Flow is not active (see `references/flow-clone-from-template.md`)
354
+ - Stage descriptions missing (see `references/opportunity-stages.md`)
355
+ - No data sources (no recent notes, emails, or calls)
356
+ - Agent user doesn't have opportunity access
357
+
358
+ **Fix**: See `references/repair-diagnostics.md` for full checklist
359
+
360
+ ---
361
+
362
+ ## Decision Matrix: Which Creation Method to Use
363
+
364
+ | Scenario | Use Method |
365
+ |----------|------------|
366
+ | First enablement (greenfield org) | Method 1 — auto-provisioning creates agent user + PSGs; publish bundle to create BotDefinition |
367
+ | `BotDefinition:SalesAgent` missing (any org) | Method 1 (publish authoring bundle) — the SOAP toggle will NOT create it |
368
+ | Agent user or PSGs missing (BotDefinition may also be missing) | Method 2 (SOAP toggle) to re-provision the user + PSGs, then Method 1 to create the BotDefinition |
369
+ | Production org with active users | Method 1 only when possible (toggle causes brief downtime and can drop custom PSG components) |
370
+ | Bundle publish fails | Method 3 (Metadata API deploy) as a last resort |
371
+
372
+ ---
373
+
374
+ ## Notes
375
+
376
+ - Pipeline Management uses a classic `BotDefinition` agent, NOT an `AiAuthoringBundle` (Agent Script) agent
377
+ - `sf agent generate/validate/publish authoring-bundle` commands create Agent Script agents — do NOT use these for Pipeline Management
378
+ - The SOAP `enableDealAgent` toggle re-provisions only the agent user and PSGs — it does NOT create or re-create `BotDefinition:SalesAgent`. Publishing the authoring bundle is the only path that creates the BotDefinition.
379
+ - SOAP toggle causes temporary Pipeline Management downtime (suggestions stop generating during toggle)
380
+ - Agent creation is asynchronous — may take up to 5 minutes after enablement
381
+ - Agent user is auto-created with agent and auto-assigned `SalesManagementAgentUserPsg`
382
+ - Agent must be active AND have opportunity access to generate suggestions
383
+ - Always use `2>/dev/null` on `sf ... --json` piped to jq
@@ -0,0 +1,146 @@
1
+ # Authentication and CLI Compatibility
2
+
3
+ ## Authentication Methods
4
+
5
+ ### Web Login (Recommended for Initial Setup)
6
+
7
+ ```bash
8
+ ORG="pipeline-mgmt-org"
9
+ BROWSER=/usr/bin/open sf org login web --instance-url https://login.salesforce.com --alias $ORG
10
+ ```
11
+
12
+ ### SFDX Auth URL (CI/CD and Automation)
13
+
14
+ ```bash
15
+ # Export from authenticated org
16
+ sf org display --target-org $ORG --verbose --json 2>/dev/null | jq -r '.result.sfdxAuthUrl' > authurl.txt
17
+
18
+ # Import in another environment
19
+ sf org login sfdx-url --sfdx-url-file authurl.txt --alias $ORG
20
+ ```
21
+
22
+ ### JWT Bearer (Service Accounts)
23
+
24
+ ```bash
25
+ sf org login jwt --client-id <connected-app-client-id> \
26
+ --jwt-key-file server.key \
27
+ --username admin@example.com \
28
+ --instance-url https://login.salesforce.com \
29
+ --alias $ORG
30
+ ```
31
+
32
+ ---
33
+
34
+ ## Extracting Credentials
35
+
36
+ ```bash
37
+ # Get instance URL (always works)
38
+ INSTANCE_URL=$(sf org display --target-org $ORG --json 2>/dev/null | jq -r '.result.instanceUrl')
39
+
40
+ # Get access token — newer CLI versions (2.108+) REDACT it in sf org display --json
41
+ ACCESS_TOKEN=$(sf org display --target-org $ORG --json 2>/dev/null | jq -r '.result.accessToken')
42
+
43
+ # Fallback for redacted token (CLI 2.108+)
44
+ if [[ -z "$ACCESS_TOKEN" || "$ACCESS_TOKEN" == "null" || "$ACCESS_TOKEN" == *"REDACTED"* ]]; then
45
+ ACCESS_TOKEN=$(echo "y" | sf org auth show-access-token --target-org $ORG --no-prompt --json 2>/dev/null | jq -r '.result.accessToken // empty')
46
+ fi
47
+ ```
48
+
49
+ **Why the fallback**: Starting with SF CLI ~2.108, `sf org display --json` returns `"[REDACTED] Use 'sf org auth show-access-token' to view"` instead of the actual token. The `sf org auth show-access-token --json` command always returns the real token. The `echo "y"` handles the interactive confirmation prompt in non-TTY environments.
50
+
51
+ **Why `2>/dev/null`**: The Salesforce CLI emits non-JSON warnings to stderr (plugin updates, deprecation notices). When piping to `jq`, these warnings get mixed with stdout on some CLI versions, causing parse failures. The `2>/dev/null` ensures only clean JSON reaches `jq`.
52
+
53
+ ---
54
+
55
+ ## CLI Compatibility Notes
56
+
57
+ ### Version Requirements
58
+
59
+ | Feature | Minimum CLI Version | Notes |
60
+ |---------|-------------------|-------|
61
+ | `sf data query` | Any | Core command |
62
+ | `sf data create record` | Any | Core command |
63
+ | `sf org assign permset` | v2.20+ | Use Data API fallback for older versions |
64
+ | `sf org assign permsetgroup` | v2.130+ | Use Data API fallback for older versions |
65
+ | `sf project retrieve start` | v2.0+ | Core command |
66
+ | `sf project deploy start` | v2.0+ | Core command |
67
+ | `sf agent` commands | v2.50+ | Requires `@salesforce/plugin-agent`; creates Agent Script (AiAuthoringBundle) agents, NOT classic Bots |
68
+
69
+ ### Permission Assignment Compatibility
70
+
71
+ ```bash
72
+ # Modern CLI (v2.130+):
73
+ sf org assign permsetgroup --name SalesManagementUserPsg --on-behalf-of user@example.com --target-org $ORG --json 2>/dev/null
74
+
75
+ # Universal fallback (all CLI versions) — Data API approach:
76
+ PSG_ID=$(sf data query -q "SELECT Id FROM PermissionSetGroup WHERE DeveloperName = 'SalesManagementUserPsg'" --target-org $ORG --json 2>/dev/null | jq -r '.result.records[0].Id')
77
+ USER_ID=$(sf data query -q "SELECT Id FROM User WHERE Username = 'user@example.com'" --target-org $ORG --json 2>/dev/null | jq -r '.result.records[0].Id')
78
+ sf data create record --sobject PermissionSetAssignment --values "AssigneeId='${USER_ID}' PermissionSetGroupId='${PSG_ID}'" --target-org $ORG --json 2>/dev/null
79
+ # DUPLICATE_VALUE error = already assigned = success
80
+ ```
81
+
82
+ ### SOAP API vs CLI for Settings (Verified)
83
+
84
+ **Settings that REQUIRE SOAP API** (CLI cannot even retrieve them):
85
+ - `SalesDealAgentSettings` — CLI returns "Settings type is unknown"
86
+
87
+ **Settings that work with CLI** (verified — retrieve AND deploy both succeed):
88
+ - `EinsteinGptSettings` — CLI deploy works, no silent failure observed
89
+ - `EinsteinCopilotSettings` — CLI deploy works
90
+ - `OpportunitySettings` — CLI deploy works (may fail on specific fields that require additional config)
91
+ - `EnhancedNotesSettings` — CLI retrieve works
92
+ - `EmailAdministrationSettings` — CLI retrieve works
93
+
94
+ **Recommendation**: Use SOAP API for `SalesDealAgentSettings` (only option). For other settings, CLI is acceptable but SOAP provides a uniform approach. Always verify after deployment regardless of method.
95
+
96
+ ### CLI Retrieve Returns Empty for Settings (Known Issue)
97
+
98
+ **Symptom**: `sf project retrieve start --metadata "Settings:EinsteinGptSettings"` succeeds but creates empty directories with no XML files, even when the setting is enabled in the org.
99
+
100
+ **Root cause**: The CLI retrieve for Settings metadata types has a known limitation where:
101
+ 1. The type must be known to the CLI's internal metadata registry
102
+ 2. Even known types may return empty if the org has no explicit customization (only default values)
103
+ 3. Some settings types (like `SalesDealAgentSettings`) are not in the registry at all
104
+
105
+ **Workaround — Use SOAP `readMetadata` for verification**:
106
+ ```bash
107
+ # Instead of retrieving via CLI, use SOAP readMetadata to CHECK settings state
108
+ curl -s "${INSTANCE_URL}/services/Soap/m/64.0" \
109
+ -H "Content-Type: text/xml; charset=UTF-8" \
110
+ -H "SOAPAction: readMetadata" \
111
+ -d "<?xml version='1.0' encoding='utf-8'?>
112
+ <soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:met='http://soap.sforce.com/2006/04/metadata'>
113
+ <soapenv:Header><met:SessionHeader><met:sessionId>${ACCESS_TOKEN}</met:sessionId></met:SessionHeader></soapenv:Header>
114
+ <soapenv:Body><met:readMetadata><met:type>EinsteinGptSettings</met:type><met:fullNames>EinsteinGpt</met:fullNames></met:readMetadata></soapenv:Body>
115
+ </soapenv:Envelope>" | grep -o "<enableEinsteinGptPlatform>[^<]*"
116
+ ```
117
+
118
+ **Workaround — Use SOAP `updateMetadata` for deployment**:
119
+ ```bash
120
+ # For settings that CLI can't deploy, use SOAP updateMetadata
121
+ # (see scripts/setup-all.sh for full patterns)
122
+ ```
123
+
124
+ **Rule**: Never trust `sf project retrieve start` for Settings verification. Always verify enablement via SOAP `readMetadata` or direct API queries after any deploy operation.
125
+
126
+ See `references/soap-api-enablement.md` for all SOAP API patterns.
127
+
128
+ ---
129
+
130
+ ## CLI Hardening Rules
131
+
132
+ 1. **Always** use `2>/dev/null` on `sf ... --json` piped to jq
133
+ 2. **Always** verify enablement after deploy (don't trust success response alone)
134
+ 3. **Never** use `sf project deploy start` for `SalesDealAgentSettings` (not recognized by CLI)
135
+ 4. **Never** use `--use-tooling-api` for `BotDefinition` queries (not supported — use standard SOQL)
136
+ 5. **Prefer** Data API approach for permission assignments (universal compatibility)
137
+ 6. **Check** `jq` output for `null` before using variables (prevents empty-string commands)
138
+
139
+ ```bash
140
+ # Safe variable extraction pattern
141
+ VALUE=$(sf data query -q "..." --target-org $ORG --json 2>/dev/null | jq -r '.result.records[0].Id // empty')
142
+ if [[ -z "$VALUE" ]]; then
143
+ echo "ERROR: Query returned no results"
144
+ exit 1
145
+ fi
146
+ ```
@@ -0,0 +1,23 @@
1
+ # Automation Matrix — what Pipeline Management setup can/can't do via CLI
2
+
3
+ Which configuration steps are CLI-automatable (and how) versus UI-only. `scripts/setup-all.sh`
4
+ performs every CLI-automatable row in the correct dependency order; the UI-only rows are the
5
+ handful of steps a human must finish in Setup.
6
+
7
+ | Category | CLI-Automatable | UI-Only |
8
+ |----------|----------------|---------|
9
+ | Prerequisites check | ✅ SOQL queries | — |
10
+ | Prerequisites enablement | ✅ SOAP Metadata API `updateMetadata` | — |
11
+ | Pipeline Management enablement | ✅ SOAP Metadata API v64.0 `updateMetadata` (NOT CLI deploy) | — |
12
+ | Enhanced Email enablement | ✅ SOAP Metadata API `EmailAdministrationSettings` | — |
13
+ | Pipeline Inspection enablement | ✅ SOAP Metadata API `OpportunitySettings.enablePipelineInspection` | — |
14
+ | Permission assignment | ✅ `sf org assign permset/permsetgroup` or Data API | — |
15
+ | Flow detection | ✅ `FlowDefinitionView` query by ApiName (`SourceTemplateId` is empty after a Metadata-API deploy) | — |
16
+ | Flow clone from template | ✅ Deploy pre-retrieved template (`assets/pipeline_management_flow.flow-meta.xml`) | Fallback: Setup UI 'Save As' if deploy fails |
17
+ | Flow activation | ✅ Tooling API `PATCH /tooling/sobjects/Flow/<id>` with `status: Active` | — |
18
+ | Agent creation | ✅ Auto-provisioning creates agent user + PSGs on enablement; `sf agent publish authoring-bundle --api-name SalesAgent` creates the `BotDefinition:SalesAgent` (SOAP toggle does NOT create the BotDefinition) | — |
19
+ | Agent activation | ✅ `sf agent activate --api-name SalesAgent --version <n>` activates the auto-provisioned (Inactive) BotVersion. A `Bot:SalesAgent` metadata deploy with `<status>Active</status>` **silently fails to activate** — use `sf agent activate`. | — |
20
+ | Agent Access (user launch) | ✅ Custom permset + `SetupEntityAccess` + `PermissionSetGroupComponent` (`scripts/define-agent-access.sh`) | — |
21
+ | Custom field suggestion (template + flow wiring) | ✅ `scripts/add-field-suggestion.sh` (deploy → retrieve `<versionIdentifier>` → set `<activeVersionIdentifier>` → redeploy → wire flow) | — |
22
+ | Stage descriptions | ✅ Tooling API CRUD on `OpptStageDescription` | — |
23
+ | Agent Analytics | — | ✅ Setup UI only |