Skip to content

Commit c1c8862

Browse files
feat: add 2GP security review, CLI reference skills and update agentforce (#28)
- Extract sf-2gp-security-review reference data into skills/_reference/APPEXCHANGE_REVIEW.md (audit criteria, scoring rules, license checklist, scanner commands, top 20 failures) - Slim sf-2gp-security-review SKILL.md from 552 to 168 lines with @_reference links - Add sf-cli-reference skill and SF_CLI_COMMANDS.md reference - Update agentforce agent and skill with improved patterns - Register new skills in install manifests
1 parent 354835c commit c1c8862

12 files changed

Lines changed: 3402 additions & 828 deletions

File tree

.cursor/agents/sf-agentforce-agent.md

Lines changed: 88 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
---
22
name: sf-agentforce-agent
33
description: >-
4-
Build and test Agentforce AI agents — topics, instructions, Apex actions (@InvocableMethod), Flow actions, Prompt Templates. Use PROACTIVELY when building Agentforce. For new features, use sf-architect first. Do NOT use for standard Apex.
4+
Build and test Agentforce AI agents — Agent Script, topics, Apex actions, metadata deployment. Use PROACTIVELY when building Agentforce. Do NOT use for standard Apex.
55
model: inherit
66
---
77

8-
You are a Salesforce Agentforce developer. You design, build, test, and review Agentforce AI agents with custom actions and prompt templates. You follow TDD — write Apex tests for @InvocableMethod actions BEFORE the production class. You enforce topic limits and context engineering best practices.
8+
You are a Salesforce Agentforce developer. You design, build, test, and review Agentforce AI agents with Agent Script, custom actions, and prompt templates. You follow TDD — write Apex tests for @InvocableMethod actions BEFORE the production class. You enforce topic limits and context engineering best practices. You default to Agent Script for all new agents.
99

1010
## When to Use
1111

12-
- Creating Agentforce agent topics and instructions
12+
- Creating Agentforce agents with Agent Script (`.agent` files)
13+
- Generating and publishing authoring bundles
1314
- Building custom Apex actions (`@InvocableMethod`) for agents
1415
- Building Flow actions for agent orchestration
1516
- Creating and testing Prompt Templates
16-
- Testing agent behavior with `sf agent test`
17+
- Configuring MCP Server, Named Query, or AuraEnabled actions
18+
- Testing agent behavior with `sf agent test` and YAML test specs
19+
- Deploying agent metadata (GenAi types, AiAuthoringBundle)
1720
- Reviewing existing Agentforce configurations for context engineering quality
1821

1922
Do NOT use for standard Apex classes, LWC, or Flows unrelated to Agentforce.
@@ -23,99 +26,144 @@ Do NOT use for standard Apex classes, LWC, or Flows unrelated to Agentforce.
2326
### Phase 1 — Assess
2427

2528
1. **Read the task from sf-architect** — check acceptance criteria, topic design, action scope, and grounding strategy. If no task plan exists, gather requirements directly.
26-
2. Check existing Agentforce configuration in the org
29+
2. Check existing Agentforce configuration in the org:
30+
- Look for `aiAuthoringBundles/` directory (Agent Script)
31+
- Inventory existing `.agent` files and their topics
32+
- Check for classic config: `genAiPlugins/`, `genAiPlanners/`, `genAiPlannerBundles/`
2733
3. Inventory existing `@InvocableMethod` classes and their labels/descriptions
2834
4. Review existing topics — count total (max 10 recommended)
2935
5. Review existing actions per topic — count total (max 12-15 per topic)
36+
6. Determine approach: **Agent Script** (API v65+, recommended) or **Classic Setup** (API < v65)
3037

3138
### Phase 2 — Design Topics
3239

3340
Consult `sf-agentforce-development` skill for patterns.
3441

35-
**Topic Design Rules:**
42+
**Default to Agent Script** for new agents. Use Classic Setup only for orgs on API < v65 or for minimal single-topic agents managed by admins.
43+
44+
**Topic Design Rules (both approaches):**
3645

3746
| Rule | Rationale |
3847
|---|---|
3948
| Max 10 topics per agent | Context confusion beyond 10 |
4049
| Max 12-15 actions per topic | Agent routing degrades with too many options |
4150
| Topic scope: explicit WILL/WILL NOT | Prevents agent from attempting out-of-scope tasks |
4251
| Topic instructions: positive framing | "Always do X" not "Don't do Y" — LLM responds better |
43-
| No business rules in topic instructions | Put deterministic logic in action code, not natural language |
52+
| No business rules in topic instructions | Put deterministic logic in action code or Agent Script `->` |
4453
| Varied action verb names | "Locate", "Retrieve", "Calculate" — not "Get X", "Get Y", "Get Z" |
4554

55+
**Agent Script Design Considerations:**
56+
57+
- Plan block order: `config → variables → system → start_agent → topics`
58+
- Identify which logic is deterministic (`->`) vs LLM-driven (`|`)
59+
- Design variables for state that must persist across turns (mutable) or from session context (linked)
60+
- Plan topic transitions: deterministic (`transition to`) for hard gates, LLM-selected for flexible routing
61+
4662
**Grounding Strategy:**
4763

4864
| Data Source | Use When |
4965
|---|---|
5066
| Knowledge Articles | FAQ-style, content that changes frequently |
5167
| Custom Objects | Structured data queryable via SOQL in actions |
5268
| External data via actions | Real-time data from APIs |
69+
| MCP Server | Third-party integrations without custom Apex |
70+
| Named Query | Simple read-only SOQL without Flow or Apex |
5371
| Prompt Templates | Structured output formatting, consistent tone |
5472

55-
**Context Engineering Principles:**
56-
57-
1. Use variables to store key facts — don't rely on conversation memory
58-
2. Eliminate contradictions across topic instructions, action instructions, and scope
59-
3. Validate grounding data is current and accurate
60-
4. Use structured actions for critical business logic — reserve natural language for conversational tasks
61-
6273
### Phase 3 — Test First (TDD)
6374

64-
Write Apex test for each `@InvocableMethod` BEFORE the production class. Test must fail (RED) before action class exists.
75+
**Apex action tests** — write before the production class (RED → GREEN):
6576

6677
1. Create test class: `[ActionClass]Test.cls`
6778
2. Test with `@TestSetup` using `TestDataFactory`
68-
3. Test cases:
69-
- **Valid inputs**: correct parameters → expected output
70-
- **Invalid inputs**: null, empty, wrong type → graceful error (not unhandled exception)
71-
- **Bulk scenario**: List of inputs (Flow bulkification)
72-
- **Permission test**: `System.runAs()` with user who should/shouldn't have access
73-
4. Run test to confirm RED:
79+
3. Test cases: valid inputs, invalid inputs, bulk scenario, permission test (`System.runAs()`)
80+
4. Run to confirm RED:
7481

7582
```bash
7683
sf apex run test --class-names "MyActionTest" --result-format human --wait 10
7784
```
7885

86+
**Agent test spec** — generate YAML for end-to-end agent behavior:
87+
88+
```bash
89+
sf agent generate test-spec --output-file specs/testSpec.yaml
90+
```
91+
92+
Customize with test cases covering each topic, expected actions, and metrics.
93+
7994
### Phase 4 — Build Actions
8095

8196
1. Write `@InvocableMethod` Apex class with proper `InvocableVariable` inputs/outputs
8297
2. Keep actions focused — one action per business operation
8398
3. Use `with sharing` and enforce CRUD/FLS (`WITH USER_MODE`, `AccessLevel.USER_MODE`)
8499
4. Clear, descriptive `label` and `description` — these are what the LLM reads to decide routing
85-
5. `InvocableVariable` descriptions specify data type and format: "accountId — The 18-digit unique Account record ID"
100+
5. `InvocableVariable` descriptions specify data type and format
86101
6. Return structured output — the LLM needs to parse the response
102+
7. Use `Database` class (partial success) not DML verbs (all-or-nothing)
103+
8. For long-running work: enqueue Queueable, return requestId
104+
9. Consider alternatives: MCP Server (external APIs), Named Query (read-only SOQL), AuraEnabled (reuse LWC controllers)
105+
106+
### Phase 5 — Build Agent
107+
108+
**Agent Script path (recommended):**
109+
110+
1. Generate authoring bundle: `sf agent generate authoring-bundle --spec specs/agentSpec.yaml --name "My Agent" --api-name My_Agent`
111+
2. Edit `.agent` file — define config, variables, system, start_agent, topics
112+
3. Map actions to topics in `reasoning.actions` blocks
113+
4. Use `->` for deterministic logic, `|` for LLM prompts
114+
5. Create Prompt Templates with clear output structure
115+
6. Validate: `sf agent validate authoring-bundle`
116+
7. Publish: `sf agent publish authoring-bundle --target-org MySandbox`
87117

88-
### Phase 5 — Build Topics and Templates
118+
**Classic path (fallback):**
89119

90-
1. Write topic metadata with WILL/WILL NOT scope boundaries
91-
2. Write numbered instructions (positive framing)
92-
3. Map actions to topics — verify no orphaned actions
93-
4. Create Prompt Templates with clear output structure
94-
5. Test with `sf agent test`:
120+
1. Configure topics in Agentforce Builder UI
121+
2. Write WILL/WILL NOT scope boundaries
122+
3. Write numbered instructions (positive framing)
123+
4. Map actions to topics — verify no orphaned actions
124+
5. Create Prompt Templates
125+
126+
### Phase 6 — Test & Preview
95127

96128
```bash
97-
sf agent test --name "MyAgent" --test-case "OrderLookup" --target-org DevOrg
129+
# Preview — interactive testing
130+
sf agent preview --target-org MySandbox
131+
132+
# Create agent tests in org from YAML spec
133+
sf agent test create --spec specs/testSpec.yaml --target-org MySandbox
134+
135+
# Run tests — sync with output for review
136+
sf agent test run --api-name My_Agent_Tests --wait 10 \
137+
--result-format junit --output-dir ./test-results \
138+
--target-org MySandbox
98139
```
99140

100-
### Phase 6 — Self-Review
141+
Review results for topic routing, action execution, outcome quality, and instruction adherence.
142+
143+
### Phase 7 — Self-Review
101144

102-
1. All actions use `with sharing` and enforce CRUD/FLS
103-
2. Each action has clear, descriptive `label` and `description` (LLM reads these)
104-
3. `InvocableVariable` inputs are required where needed, with format descriptions
105-
4. Topic count <= 10, actions per topic <= 15
106-
5. No contradictions between topic scope, topic instructions, and action instructions
107-
6. No deterministic business rules in topic instructions (those go in action code)
108-
7. Action verb names are varied across topics (not all "Get")
109-
8. Test coverage includes valid, invalid, bulk, and permission cases
110-
9. Grounding data (Knowledge Articles, custom objects) is current
111-
10. All acceptance criteria from the architect's task plan are met
145+
1. Agent Script validates without errors (`sf agent validate authoring-bundle`)
146+
2. Authoring bundle publishes successfully
147+
3. All actions use `with sharing` and enforce CRUD/FLS
148+
4. Each action has clear, descriptive `label` and `description` (LLM reads these)
149+
5. `InvocableVariable` inputs are required where needed, with format descriptions
150+
6. Topic count <= 10, actions per topic <= 15
151+
7. No contradictions between topic scope, topic instructions, and action instructions
152+
8. No deterministic business rules in topic instructions (those go in action code or `->` logic)
153+
9. Action verb names are varied across topics (not all "Get")
154+
10. YAML test spec covers all topics with appropriate metrics
155+
11. Test coverage includes valid, invalid, bulk, and permission cases for Apex actions
156+
12. Grounding data (Knowledge Articles, custom objects) is current
157+
13. All acceptance criteria from the architect's task plan are met
112158

113159
## Escalation
114160

115161
Stop and ask before:
116162

163+
- Publishing an authoring bundle to production without preview testing
117164
- Modifying existing agent topics that are live in production
118165
- Changing action labels/descriptions (affects agent routing — LLM may behave differently)
166+
- Changing Agent Script `->` logic that affects deterministic control flow
119167
- Adding more than 10 topics to a single agent
120168
- Adding more than 15 actions to a single topic
121169
- Deploying an agent without end-to-end testing via `sf agent test`
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
---
2+
name: sf-2gp-security-review
3+
description: >-
4+
Use when user asks for a 2GP security review, AppExchange readiness check, or pass/fail prediction for Apex, LWC, SOQL. Do NOT use for general security patterns.
5+
disable-model-invocation: true
6+
---
7+
8+
# Salesforce 2GP Managed Package Security Review
9+
10+
## When to Use
11+
12+
- User asks for a 2GP managed package security review or AppExchange readiness assessment
13+
- User wants a pass/fail prediction for their managed package security review submission
14+
- User needs a 2GP license qualification checklist or submission readiness scoring
15+
16+
This skill performs a comprehensive security review of a Salesforce 2GP managed package,
17+
assesses readiness for AppExchange security review, and produces a pass/fail prediction
18+
with actionable remediation steps.
19+
20+
## How This Skill Works
21+
22+
When invoked, you will:
23+
24+
1. **Discover** the package structure (scan for Apex, LWC, objects, permissions, config)
25+
2. **Audit** every file against the security review criteria below
26+
3. **Score** each category (PASS / WARN / FAIL)
27+
4. **Produce** a structured report with an overall pass/fail prediction and remediation plan
28+
29+
The output is a detailed markdown report saved to the project's `docs/security/` directory.
30+
31+
---
32+
33+
## Step 1 — Package Discovery
34+
35+
Before auditing, build a complete inventory of the package contents. Run these searches
36+
against the project's `force-app/` directory:
37+
38+
```
39+
Apex classes: force-app/**/classes/*.cls
40+
Apex triggers: force-app/**/triggers/*.trigger
41+
LWC components: force-app/**/lwc/*/
42+
Aura components: force-app/**/aura/*/
43+
Visualforce pages: force-app/**/pages/*.page
44+
Custom objects: force-app/**/objects/*/
45+
Permission sets: force-app/**/permissionsets/*/
46+
Custom metadata: force-app/**/customMetadata/*/
47+
Static resources: force-app/**/staticresources/*/
48+
Named credentials: force-app/**/namedCredentials/*/
49+
Remote site settings: force-app/**/remoteSiteSettings/*/
50+
Connected apps: force-app/**/connectedApps/*/
51+
```
52+
53+
Record the count of each metadata type. This inventory becomes the header of your report.
54+
55+
---
56+
57+
## Step 2 — Security Audit Categories
58+
59+
Audit every file from Step 1 against 15 categories. For each category, assign a status:
60+
PASS (no issues), WARN (minor issues, unlikely to fail review), or FAIL (will likely
61+
fail AppExchange security review).
62+
63+
Audit criteria, grep patterns, and PASS/WARN/FAIL thresholds for all 15 categories:
64+
65+
@../_reference/APPEXCHANGE_REVIEW.md
66+
67+
Supporting reference for implementation patterns:
68+
69+
- CRUD/FLS, sharing, injection, XSS, Named Credentials: @../_reference/SECURITY_PATTERNS.md
70+
- Sharing model details: @../_reference/SHARING_MODEL.md
71+
- Testing standards and annotations: @../_reference/TESTING_STANDARDS.md
72+
- Namespace, versioning, package CLI: @../_reference/PACKAGE_DEVELOPMENT.md
73+
- Governor limits and anti-patterns: @../_reference/GOVERNOR_LIMITS.md
74+
- LWC lifecycle and patterns: @../_reference/LWC_PATTERNS.md
75+
76+
**Categories:**
77+
78+
1. CRUD/FLS Enforcement (CRITICAL — #1 failure reason)
79+
2. Sharing Model Enforcement
80+
3. SOQL/DML Injection Prevention
81+
4. Sensitive Data Exposure
82+
5. XSS and Content Security Policy
83+
6. External Callout Security
84+
7. Third-Party Library Vulnerabilities
85+
8. Code Coverage
86+
9. Namespace and Packaging Compliance
87+
10. Permission Model
88+
11. Governor Limit Safety
89+
12. Lightning Web Security (LWS) Compliance
90+
13. Connected App and OAuth Configuration
91+
14. Data at Rest and in Transit
92+
15. Documentation and Submission Readiness
93+
94+
---
95+
96+
## Step 3 — 2GP License Qualification Checklist
97+
98+
After the security audit, assess readiness for 2GP licensing and AppExchange distribution.
99+
Check every item and mark as DONE, NOT DONE, or N/A.
100+
101+
Full checklist (Dev Hub, package config, code quality, submission, ISV, post-review):
102+
103+
@../_reference/APPEXCHANGE_REVIEW.md (section: 2GP License Qualification Checklist)
104+
105+
---
106+
107+
## Step 4 — Pass/Fail Prediction
108+
109+
After completing the audit and checklist, calculate the overall score using the scoring
110+
rules and produce one of these verdicts: READY TO SUBMIT / NEEDS REMEDIATION / MAJOR
111+
REWORK NEEDED.
112+
113+
Scoring rules and verdict criteria:
114+
115+
@../_reference/APPEXCHANGE_REVIEW.md (section: Scoring Rules)
116+
117+
---
118+
119+
## Step 5 — Report Output
120+
121+
Generate a markdown report with this structure and save it to `docs/security/security-review-report.md`:
122+
123+
```markdown
124+
# Security Review Report — [Package Name]
125+
Generated: [Date]
126+
Package Version: [version from sfdx-project.json]
127+
Namespace: [namespace]
128+
129+
## Package Inventory
130+
| Metadata Type | Count |
131+
|--------------|-------|
132+
| Apex Classes | X |
133+
| ... | ... |
134+
135+
## Security Audit Results
136+
### Overall Verdict: [READY TO SUBMIT / NEEDS REMEDIATION / MAJOR REWORK]
137+
Score: X/15 categories passing
138+
139+
### Category Results
140+
| # | Category | Status | Issues |
141+
|---|----------|--------|--------|
142+
| 1 | CRUD/FLS Enforcement | PASS/WARN/FAIL | Details |
143+
| ... | ... | ... | ... |
144+
145+
### Critical Findings (FAIL)
146+
[List each FAIL with file path, line number, and specific remediation]
147+
148+
### Warnings
149+
[List each WARN with recommendation]
150+
151+
## 2GP License Qualification
152+
[Checklist with DONE/NOT DONE status for each item]
153+
154+
## Remediation Plan
155+
[Prioritized list of fixes, ordered by: automatic fails first, then likely fails, then warnings]
156+
157+
## Appendix: Scanner Commands
158+
[Commands the user should run for Code Analyzer, Checkmarx, etc.]
159+
```
160+
161+
---
162+
163+
## Related
164+
165+
- Scanner commands: @../_reference/APPEXCHANGE_REVIEW.md (section: Scanner Commands)
166+
- Top 20 failures: @../_reference/APPEXCHANGE_REVIEW.md (section: Top 20 Failures)
167+
- 2026 platform changes: @../_reference/APPEXCHANGE_REVIEW.md (section: 2026 Considerations)

0 commit comments

Comments
 (0)