sf-forcekit 1.0.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.
- package/License +21 -0
- package/README.md +106 -0
- package/bin/cli.js +85 -0
- package/package.json +44 -0
- package/templates/ai-dir/README.md +155 -0
- package/templates/ai-dir/agentforce.md +213 -0
- package/templates/ai-dir/architecture.md +123 -0
- package/templates/ai-dir/commands.md +276 -0
- package/templates/ai-dir/context-snapshots/TEMPLATE.md +64 -0
- package/templates/ai-dir/conventions.md +242 -0
- package/templates/ai-dir/current-state.md +113 -0
- package/templates/ai-dir/debugging-notes.md +165 -0
- package/templates/ai-dir/deployment.md +161 -0
- package/templates/ai-dir/integrations.md +199 -0
- package/templates/ai-dir/inventory.md +209 -0
- package/templates/ai-dir/known-issues.md +124 -0
- package/templates/ai-dir/org-context.md +110 -0
- package/templates/ai-dir/performance.md +312 -0
- package/templates/ai-dir/prompts/agentforce.md +163 -0
- package/templates/ai-dir/prompts/apex.md +165 -0
- package/templates/ai-dir/prompts/flows.md +125 -0
- package/templates/ai-dir/prompts/lwc.md +230 -0
- package/templates/ai-dir/prompts/security.md +181 -0
- package/templates/ai-dir/prompts/testing.md +269 -0
- package/templates/ai-dir/rules.md +238 -0
- package/templates/ai-dir/scripts/update_state.py +1406 -0
- package/templates/ai-dir/source-of-truth.md +180 -0
- package/templates/ai-dir/templates/Selector.cls +113 -0
- package/templates/ai-dir/templates/Service.cls +132 -0
- package/templates/ai-dir/templates/TestClass.cls +143 -0
- package/templates/ai-dir/templates/TriggerHandler.cls +67 -0
- package/templates/ai-dir/testing-strategy.md +342 -0
package/License
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Rohit Vaghela
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# ForceKit β‘
|
|
2
|
+
|
|
3
|
+
> **Salesforce enterprise-grade AI context layer and agent skill for Salesforce DX projects.**
|
|
4
|
+
|
|
5
|
+
ForceKit provides a structured, token-efficient `.ai/` context system that shields AI agents from hallucinations, enforces strict layered architecture patterns, and manages session state. It also bundles a complete **agent skill** configuration that you can drop directly into your agent's config folder.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## π Key Features
|
|
10
|
+
|
|
11
|
+
* **Anti-Hallucination Protocol (Non-Negotiable)**: Strictly enforces verification rules so agents don't guess API names, custom fields, or Apex methods.
|
|
12
|
+
* **Tiered Reading Architecture**: Organizes context files into tiers (T0 to T3) to save token budget while maintaining situational awareness.
|
|
13
|
+
* **Enterprise-Grade Apex Standards**: Automates rules for bulkification, user mode queries (`WITH USER_MODE`), and trigger bypass patterns.
|
|
14
|
+
* **Automated State Scannner**: Includes an inventory script that scans and indexes objects, classes, LWCs, and flows.
|
|
15
|
+
* **Next-Session Handoff**: Keeps a rolling session log so agents can hand off work to each other across sessions without loss of context.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## π¦ Directory Structure
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
forcekit/
|
|
23
|
+
βββ SKILL.md # Agent-facing skill description & triggers
|
|
24
|
+
βββ README.md # This user guide
|
|
25
|
+
βββ scripts/
|
|
26
|
+
β βββ scaffold.sh # Installer script to generate .ai/ in target projects
|
|
27
|
+
βββ references/ # Context guides read by the active agent skill
|
|
28
|
+
β βββ conventions.md
|
|
29
|
+
β βββ testing-strategy.md
|
|
30
|
+
β βββ ...
|
|
31
|
+
βββ templates/
|
|
32
|
+
βββ ai-dir/ # Source files for bootstrapping new projects
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## βοΈ How to Use / Install
|
|
38
|
+
|
|
39
|
+
### Option A: Zero Install (npx, bunx, pnpm dlx)
|
|
40
|
+
You don't need to install anything! Run this command directly inside your Salesforce DX project root to scaffold the `.ai/` directory:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
# Using npm
|
|
44
|
+
npx sf-forcekit
|
|
45
|
+
|
|
46
|
+
# Using bun
|
|
47
|
+
bunx sf-forcekit
|
|
48
|
+
|
|
49
|
+
# Using pnpm
|
|
50
|
+
pnpm dlx sf-forcekit
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
### Option B: Local AI Agent Skill
|
|
56
|
+
If you want to use ForceKit as a registered local skill inside your AI agent (like Google Antigravity, Claude Code, Windsurf, Codex, etc.) so it can auto-trigger on command:
|
|
57
|
+
|
|
58
|
+
1. Clone this repository into your agent's skills directory:
|
|
59
|
+
```bash
|
|
60
|
+
git clone https://github.com/<your-username>/forcekit.git ~/.gemini/config/skills/forcekit
|
|
61
|
+
```
|
|
62
|
+
2. Restart your agent or start a new session. The agent will automatically register the `forcekit` skill!
|
|
63
|
+
|
|
64
|
+
Once the skill is active, you can tell the agent:
|
|
65
|
+
> *"scaffold a salesforce context layer"*
|
|
66
|
+
> OR
|
|
67
|
+
> *"initialize forcekit in this project"*
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## π οΈ Scaffolding Output
|
|
72
|
+
|
|
73
|
+
The scaffold process generates the following structure in your project root:
|
|
74
|
+
```
|
|
75
|
+
my-sfdx-project/
|
|
76
|
+
βββ .ai/
|
|
77
|
+
βββ README.md
|
|
78
|
+
βββ rules.md # Rules for agent behavior
|
|
79
|
+
βββ org-context.md # Target org details
|
|
80
|
+
βββ current-state.md # Active session log & tech debt
|
|
81
|
+
βββ inventory.md # Auto-scanned metadata index
|
|
82
|
+
βββ scripts/
|
|
83
|
+
β βββ update_state.py # Automation tool
|
|
84
|
+
βββ ...
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## π€ AI Agent Compatibility
|
|
90
|
+
|
|
91
|
+
ForceKit is designed to work with all major AI developer agents and IDE extensions:
|
|
92
|
+
* **Google Antigravity & Gemini**: Full custom skill registration and guideline enforcement.
|
|
93
|
+
* **Claude Code**: Supports standard `agentskills` trigger formatting.
|
|
94
|
+
* **Codex & Windsurf**: Integrates with local workspace context rules and custom commands.
|
|
95
|
+
* **GitHub Copilot**: Automatically reads project state from the `.ai/` folder.
|
|
96
|
+
* **Cursor**: Seamlessly references `.ai/` files via `@` context inclusion.
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## π€ Contributing
|
|
101
|
+
|
|
102
|
+
Contributions to improve Salesforce AI development patterns are welcome! Feel free to open issues or submit pull requests.
|
|
103
|
+
|
|
104
|
+
## π License
|
|
105
|
+
|
|
106
|
+
MIT
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const readline = require('readline');
|
|
6
|
+
|
|
7
|
+
// Colors helper
|
|
8
|
+
const GREEN = '\x1b[32m';
|
|
9
|
+
const BLUE = '\x1b[34m';
|
|
10
|
+
const YELLOW = '\x1b[33m';
|
|
11
|
+
const RED = '\x1b[31m';
|
|
12
|
+
const NC = '\x1b[0m';
|
|
13
|
+
|
|
14
|
+
console.log(`${BLUE}=== ForceKit: Salesforce AI Context Scaffolder ===${NC}`);
|
|
15
|
+
|
|
16
|
+
// Verify sfdx-project.json exists
|
|
17
|
+
if (!fs.existsSync(path.join(process.cwd(), 'sfdx-project.json'))) {
|
|
18
|
+
console.log(`${YELLOW}Warning: sfdx-project.json not found in current directory.${NC}`);
|
|
19
|
+
console.log('Are you running this from the root of your Salesforce DX project?\n');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const targetDir = path.join(process.cwd(), '.ai');
|
|
23
|
+
const templateDir = path.join(__dirname, '..', 'templates', 'ai-dir');
|
|
24
|
+
|
|
25
|
+
function copyRecursiveSync(src, dest) {
|
|
26
|
+
const exists = fs.existsSync(src);
|
|
27
|
+
const stats = exists && fs.statSync(src);
|
|
28
|
+
const isDirectory = exists && stats.isDirectory();
|
|
29
|
+
if (isDirectory) {
|
|
30
|
+
if (!fs.existsSync(dest)) {
|
|
31
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
32
|
+
}
|
|
33
|
+
fs.readdirSync(src).forEach((childItemName) => {
|
|
34
|
+
copyRecursiveSync(path.join(src, childItemName), path.join(dest, childItemName));
|
|
35
|
+
});
|
|
36
|
+
} else {
|
|
37
|
+
fs.copyFileSync(src, dest);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function doScaffold() {
|
|
42
|
+
if (fs.existsSync(targetDir)) {
|
|
43
|
+
console.log(`${YELLOW}Warning: Target directory .ai/ already exists.${NC}`);
|
|
44
|
+
const rl = readline.createInterface({
|
|
45
|
+
input: process.stdin,
|
|
46
|
+
output: process.stdout
|
|
47
|
+
});
|
|
48
|
+
rl.question('Do you want to overwrite it? (y/n) ', (answer) => {
|
|
49
|
+
rl.close();
|
|
50
|
+
if (answer.toLowerCase() === 'y') {
|
|
51
|
+
console.log('Cleaning up existing .ai/ directory...');
|
|
52
|
+
fs.rmSync(targetDir, { recursive: true, force: true });
|
|
53
|
+
runCopy();
|
|
54
|
+
} else {
|
|
55
|
+
console.log(`${RED}Scaffold aborted.${NC}`);
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
} else {
|
|
60
|
+
runCopy();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function runCopy() {
|
|
65
|
+
console.log('Bootstrapping .ai/ directory structure...');
|
|
66
|
+
try {
|
|
67
|
+
copyRecursiveSync(templateDir, targetDir);
|
|
68
|
+
// Make python script executable if on Unix
|
|
69
|
+
const pythonScript = path.join(targetDir, 'scripts', 'update_state.py');
|
|
70
|
+
if (fs.existsSync(pythonScript) && process.platform !== 'win32') {
|
|
71
|
+
fs.chmodSync(pythonScript, '755');
|
|
72
|
+
}
|
|
73
|
+
console.log(`${GREEN}β Success! ForceKit context layer generated at ./.ai/${NC}\n`);
|
|
74
|
+
console.log('Next steps:');
|
|
75
|
+
console.log(` 1. Edit ${BLUE}.ai/org-context.md${NC} with your Salesforce org details.`);
|
|
76
|
+
console.log(` 2. Run ${BLUE}python3 .ai/scripts/update_state.py scan${NC} to initialize project inventory.`);
|
|
77
|
+
console.log(` 3. Start code generation using the tiered reading instructions in ${BLUE}.ai/README.md${NC}.\n`);
|
|
78
|
+
console.log('Happy Coding! β‘');
|
|
79
|
+
} catch (err) {
|
|
80
|
+
console.error(`${RED}Error scaffolding project: ${err.message}${NC}`);
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
doScaffold();
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "sf-forcekit",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Scaffold a structured .ai/ context layer for Salesforce DX projects β anti-hallucination, layered architecture, session memory, and governor limit awareness for AI agents.",
|
|
5
|
+
"main": "bin/cli.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"sf-forcekit": "./bin/cli.js",
|
|
8
|
+
"forcekit": "./bin/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"bin",
|
|
12
|
+
"templates/ai-dir",
|
|
13
|
+
"License"
|
|
14
|
+
],
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=16.0.0"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"salesforce",
|
|
20
|
+
"sfdx",
|
|
21
|
+
"ai",
|
|
22
|
+
"context",
|
|
23
|
+
"agents",
|
|
24
|
+
"claude-code",
|
|
25
|
+
"antigravity",
|
|
26
|
+
"copilot",
|
|
27
|
+
"cursor",
|
|
28
|
+
"apex",
|
|
29
|
+
"lwc",
|
|
30
|
+
"devops",
|
|
31
|
+
"dx",
|
|
32
|
+
"forcekit"
|
|
33
|
+
],
|
|
34
|
+
"author": "Rohit Vaghela",
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "git+https://github.com/rvaghela20/forcekit.git"
|
|
39
|
+
},
|
|
40
|
+
"homepage": "https://github.com/rvaghela20/forcekit#readme",
|
|
41
|
+
"bugs": {
|
|
42
|
+
"url": "https://github.com/rvaghela20/forcekit/issues"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# .ai/ β Salesforce Project AI Context
|
|
2
|
+
|
|
3
|
+
> A structured context layer for AI-assisted Salesforce development.
|
|
4
|
+
> Drop this `.ai/` directory into the root of any SFDX project to give agents full situational awareness.
|
|
5
|
+
|
|
6
|
+
## Quick Start for Agents
|
|
7
|
+
|
|
8
|
+
> [!IMPORTANT]
|
|
9
|
+
> **Agents: Read `rules.md` FIRST.** It defines your read order, auto-update obligations, and code generation rules.
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
1. Read rules.md β Your behavior rules
|
|
13
|
+
2. Read org-context.md β Org details and CLI config
|
|
14
|
+
3. Read current-state.md β What's happening NOW + session history
|
|
15
|
+
4. Read conventions.md β Coding standards
|
|
16
|
+
5. Start working β and UPDATE current-state.md as you go
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Directory Structure
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
.ai/
|
|
23
|
+
βββ rules.md β π€ AGENT START HERE β behavior rules, auto-update protocol
|
|
24
|
+
βββ README.md β You are here
|
|
25
|
+
β
|
|
26
|
+
βββ ββ CORE (Always Read) ββββββββββββββββββββββββββββββββββ
|
|
27
|
+
βββ source-of-truth.md β π« ANTI-HALLUCINATION β verification commands, standard library
|
|
28
|
+
βββ inventory.md β π€ AUTO-UPDATED β registry of everything in the project
|
|
29
|
+
βββ org-context.md β Org type, edition, limits, installed packages
|
|
30
|
+
βββ current-state.md β π€ AUTO-UPDATED β live status, session log, tech debt, next steps
|
|
31
|
+
β
|
|
32
|
+
βββ ββ STANDARDS (Read Per Task) βββββββββββββββββββββββββββ
|
|
33
|
+
βββ conventions.md β Coding standards (Apex, LWC, Flows, naming)
|
|
34
|
+
βββ architecture.md β System design, data model, integration map
|
|
35
|
+
βββ testing-strategy.md β Test philosophy, patterns, TestDataFactory, coverage rules
|
|
36
|
+
βββ performance.md β Governor limits, SOQL optimization, heap, async patterns
|
|
37
|
+
β
|
|
38
|
+
βββ ββ REFERENCE (Read As Needed) ββββββββββββββββββββββββββ
|
|
39
|
+
βββ commands.md β sf CLI cookbook β every command organized by workflow
|
|
40
|
+
βββ deployment.md β Deploy/retrieve workflows, CI/CD config
|
|
41
|
+
βββ integrations.md β External systems, Named Credentials, callout patterns
|
|
42
|
+
βββ agentforce.md β Agentforce Topics, Actions, Prompt Templates
|
|
43
|
+
βββ debugging-notes.md β Debug techniques, log categories, common errors
|
|
44
|
+
βββ known-issues.md β Platform bugs, workarounds, tech debt
|
|
45
|
+
β
|
|
46
|
+
βββ ββ GENERATION RULES ββββββββββββββββββββββββββββββββββββ
|
|
47
|
+
βββ prompts/ β Agent-specific instruction sets
|
|
48
|
+
β βββ apex.md β Apex generation rules
|
|
49
|
+
β βββ lwc.md β LWC generation rules
|
|
50
|
+
β βββ testing.md β Test class generation rules
|
|
51
|
+
β βββ flows.md β Flow building guidance
|
|
52
|
+
β βββ security.md β Security review & CRUD/FLS rules
|
|
53
|
+
β βββ agentforce.md β Agentforce/Einstein development rules
|
|
54
|
+
β
|
|
55
|
+
βββ ββ TEMPLATES & TOOLS βββββββββββββββββββββββββββββββββββ
|
|
56
|
+
βββ templates/ β Copy-paste boilerplate starters
|
|
57
|
+
β βββ TriggerHandler.cls β Base class with routing + bypass control
|
|
58
|
+
β βββ Service.cls β Service layer template
|
|
59
|
+
β βββ Selector.cls β Selector/repository template
|
|
60
|
+
β βββ TestClass.cls β Test class template
|
|
61
|
+
βββ scripts/ β Automation scripts
|
|
62
|
+
β βββ update_state.py β Scan, sync, verify, lint, session management
|
|
63
|
+
βββ context-snapshots/ β Point-in-time project snapshots
|
|
64
|
+
βββ TEMPLATE.md β Copy per session for deep context preservation
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## File Priority Tiers
|
|
68
|
+
|
|
69
|
+
Agents should optimize context window usage by reading files in priority order:
|
|
70
|
+
|
|
71
|
+
| Tier | Files | When to Read | ~Size |
|
|
72
|
+
|------|-------|-------------|-------|
|
|
73
|
+
| **T0 β Always** | `rules.md`, `org-context.md`, `current-state.md`, `inventory.md` | Every session start | ~20 KB |
|
|
74
|
+
| **T1 β Per Task** | `conventions.md`, `source-of-truth.md`, + relevant `prompts/*.md` | Before writing code | ~20 KB |
|
|
75
|
+
| **T2 β Situational** | `architecture.md`, `testing-strategy.md`, `performance.md` | When task involves design, tests, or optimization | ~15 KB |
|
|
76
|
+
| **T3 β Reference** | `commands.md`, `deployment.md`, `integrations.md`, `debugging-notes.md`, `known-issues.md`, `agentforce.md` | When specifically needed | ~35 KB |
|
|
77
|
+
|
|
78
|
+
> [!TIP]
|
|
79
|
+
> **Total .ai/ context β 90 KB.** For tight context windows, read only T0 + T1. For full sessions, read T0βT2.
|
|
80
|
+
|
|
81
|
+
## How It Works
|
|
82
|
+
|
|
83
|
+
### For Humans
|
|
84
|
+
|
|
85
|
+
1. **Copy** this `.ai/` folder into any new SFDX project root.
|
|
86
|
+
2. **Fill in** `org-context.md` with your target org details (or run `python3 .ai/scripts/update_state.py sync-org`).
|
|
87
|
+
3. **Review** `current-state.md` to see what the AI has been doing β session logs, decisions, files changed.
|
|
88
|
+
4. **Correct** anything in `current-state.md` if the agent got it wrong.
|
|
89
|
+
|
|
90
|
+
### For AI Agents
|
|
91
|
+
|
|
92
|
+
1. **Read** `rules.md` first β it's your operating manual.
|
|
93
|
+
2. **Auto-update** `current-state.md` as you work:
|
|
94
|
+
- Log your session (date, goal, what you did)
|
|
95
|
+
- Track active work (in progress / completed)
|
|
96
|
+
- Record blockers and decisions
|
|
97
|
+
- List every file you create or change
|
|
98
|
+
3. **Snapshot** context into `context-snapshots/YYYY-MM-DD.md` at end of long sessions.
|
|
99
|
+
|
|
100
|
+
### Auto-Update Flow
|
|
101
|
+
|
|
102
|
+
```
|
|
103
|
+
Agent starts session
|
|
104
|
+
β
|
|
105
|
+
ββββ Reads rules.md + current-state.md
|
|
106
|
+
β
|
|
107
|
+
ββββ Adds session entry to Session Log
|
|
108
|
+
β
|
|
109
|
+
ββββ Works on task
|
|
110
|
+
β βββ Updates "In Progress" items
|
|
111
|
+
β βββ Appends to "Files Changed"
|
|
112
|
+
β βββ Logs blockers/decisions as they arise
|
|
113
|
+
β
|
|
114
|
+
ββββ Session ends
|
|
115
|
+
βββ Marks items completed
|
|
116
|
+
βββ Writes session summary
|
|
117
|
+
βββ Creates context snapshot (if major session)
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Multi-Agent Compatibility
|
|
121
|
+
|
|
122
|
+
This structure is designed to work with:
|
|
123
|
+
- **Claude Code / Antigravity** β reads `rules.md` as project rules
|
|
124
|
+
- **GitHub Copilot** β reads `.ai/` as project context
|
|
125
|
+
- **Cursor** β `.ai/` files surface in context window
|
|
126
|
+
- **Agentforce for Developers** β mirror `prompts/` into `.sfdx/a4d/rules/`
|
|
127
|
+
- **Any LLM agent** β markdown is universally parseable
|
|
128
|
+
|
|
129
|
+
## Maintenance
|
|
130
|
+
|
|
131
|
+
| File | Updated By | Frequency |
|
|
132
|
+
|------|-----------|-----------|
|
|
133
|
+
| `rules.md` | Human | Rarely (on process change) |
|
|
134
|
+
| `org-context.md` | Human / Script | Once per org (or `sync-org`) |
|
|
135
|
+
| `conventions.md` | Human | Rarely (on standards update) |
|
|
136
|
+
| `architecture.md` | Human + Agent | Per major feature / data model change |
|
|
137
|
+
| `testing-strategy.md` | Human | Rarely (on test philosophy change) |
|
|
138
|
+
| `performance.md` | Human | Per API version / new patterns |
|
|
139
|
+
| `commands.md` | Human | On CLI updates |
|
|
140
|
+
| `current-state.md` | **π€ Agent (auto)** | **Every session, continuously** |
|
|
141
|
+
| `inventory.md` | **π€ Agent (auto)** | **After creating/deleting metadata** |
|
|
142
|
+
| `deployment.md` | Human | On CI/CD pipeline changes |
|
|
143
|
+
| `known-issues.md` | Human + Agent | As discovered |
|
|
144
|
+
| `context-snapshots/` | **π€ Agent (auto)** | Per session or milestone |
|
|
145
|
+
|
|
146
|
+
## Helper Script Reference
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
python3 .ai/scripts/update_state.py scan # Scan project β update inventory.md
|
|
150
|
+
python3 .ai/scripts/update_state.py sync-org # Fetch org details β update org-context.local.md
|
|
151
|
+
python3 .ai/scripts/update_state.py cache-schema # Cache objects/fields for offline verification
|
|
152
|
+
python3 .ai/scripts/update_state.py check # Static analysis / code style lint
|
|
153
|
+
python3 .ai/scripts/update_state.py verify --type class --name AccountService # Verify metadata exists
|
|
154
|
+
python3 .ai/scripts/update_state.py clean # Strip local data for open-source distribution
|
|
155
|
+
```
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# Agentforce
|
|
2
|
+
|
|
3
|
+
> Einstein Bots, Copilot Actions, Prompt Templates, and autonomous agent development.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
Agentforce is Salesforce's autonomous AI agent platform (successor to Einstein Copilot). Agents can interact with users, trigger autonomously on events, and take actions grounded in live CRM data.
|
|
10
|
+
|
|
11
|
+
### Core Concepts
|
|
12
|
+
|
|
13
|
+
| Concept | Description |
|
|
14
|
+
|---------|-------------|
|
|
15
|
+
| **Agent** | AI entity (Service Agent, Sales Agent, Custom Agent) |
|
|
16
|
+
| **Topic** | Category of tasks/intents the agent handles (e.g., "Order Management") |
|
|
17
|
+
| **Action** | Tool the agent invokes β Standard, Flow, Apex, or Prompt Template |
|
|
18
|
+
| **Atlas Reasoning Engine** | The AI planner that decides which actions to invoke based on natural language |
|
|
19
|
+
| **Einstein Trust Layer** | Masks sensitive PII before sending data to LLM, audits all interactions |
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Architecture
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
User / Event Trigger
|
|
27
|
+
β
|
|
28
|
+
βΌ
|
|
29
|
+
ββββββββββββββββββββββββ
|
|
30
|
+
β Agentforce Agent β
|
|
31
|
+
β (Supervisor / Child)β
|
|
32
|
+
ββββββββββββββββββββββββ€
|
|
33
|
+
β Atlas Reasoning β β Uses Topic descriptions + Action descriptions
|
|
34
|
+
β Engine β to decide what to do
|
|
35
|
+
ββββββββββββββββββββββββ€
|
|
36
|
+
β Trust Layer β β PII masking, audit logging, guardrails
|
|
37
|
+
ββββββββββββββββββββββββ€
|
|
38
|
+
β Actions β
|
|
39
|
+
β ββββββββββββββββββ β
|
|
40
|
+
β β Standard Actionβ β β Out-of-the-box (e.g., Query Records)
|
|
41
|
+
β β Flow Action β β β Triggered Flows / Screen Flows
|
|
42
|
+
β β Apex Action β β β @InvocableMethod classes
|
|
43
|
+
β β Prompt Templateβ β β Prompt Builder templates
|
|
44
|
+
β ββββββββββββββββββ β
|
|
45
|
+
ββββββββββββββββββββββββ€
|
|
46
|
+
β Data Cloud β β Grounding data, context
|
|
47
|
+
ββββββββββββββββββββββββ
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Development Rules
|
|
53
|
+
|
|
54
|
+
### 1. Declarative First
|
|
55
|
+
|
|
56
|
+
Always check if a standard action or Flow can solve the problem before writing custom Apex.
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
Decision Tree:
|
|
60
|
+
Can a Standard Action do it? β Use Standard Action
|
|
61
|
+
Can a Flow do it? β Use Flow Action
|
|
62
|
+
Need complex logic? β Use @InvocableMethod Apex Action
|
|
63
|
+
Need AI-generated text? β Use Prompt Template Action
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 2. Action Descriptions Are Critical
|
|
67
|
+
|
|
68
|
+
The Atlas Reasoning Engine uses **natural language descriptions** to decide when to invoke actions. Poor descriptions = wrong action selection.
|
|
69
|
+
|
|
70
|
+
```apex
|
|
71
|
+
// β
GOOD β Clear, specific description
|
|
72
|
+
@InvocableMethod(
|
|
73
|
+
label='Get Account Health Score'
|
|
74
|
+
description='Calculates a health score (0-100) for an Account based on recent activity, open cases, and engagement metrics. Use when the user asks about account health, risk, or engagement.'
|
|
75
|
+
)
|
|
76
|
+
public static List<Integer> getHealthScore(List<Id> accountIds) { ... }
|
|
77
|
+
|
|
78
|
+
// β BAD β Vague description
|
|
79
|
+
@InvocableMethod(
|
|
80
|
+
label='Process Account'
|
|
81
|
+
description='Does account stuff'
|
|
82
|
+
)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### 3. Apex Actions for Agentforce
|
|
86
|
+
|
|
87
|
+
```apex
|
|
88
|
+
/**
|
|
89
|
+
* @description Apex action for Agentforce to retrieve order status.
|
|
90
|
+
* Action: Invocable from Agentforce Topics.
|
|
91
|
+
*/
|
|
92
|
+
public with sharing class OrderStatusAction {
|
|
93
|
+
|
|
94
|
+
public class OrderStatusRequest {
|
|
95
|
+
@InvocableVariable(label='Order Number' description='The order number to look up' required=true)
|
|
96
|
+
public String orderNumber;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
public class OrderStatusResponse {
|
|
100
|
+
@InvocableVariable(label='Status' description='Current order status')
|
|
101
|
+
public String status;
|
|
102
|
+
|
|
103
|
+
@InvocableVariable(label='Expected Delivery' description='Expected delivery date')
|
|
104
|
+
public Date expectedDelivery;
|
|
105
|
+
|
|
106
|
+
@InvocableVariable(label='Message' description='Human-readable status summary')
|
|
107
|
+
public String message;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
@InvocableMethod(
|
|
111
|
+
label='Get Order Status'
|
|
112
|
+
description='Retrieves the current status and expected delivery date for a given order number. Use when customers ask about their order, shipment, or delivery.'
|
|
113
|
+
)
|
|
114
|
+
public static List<OrderStatusResponse> getOrderStatus(List<OrderStatusRequest> requests) {
|
|
115
|
+
// Bulkified implementation
|
|
116
|
+
List<OrderStatusResponse> responses = new List<OrderStatusResponse>();
|
|
117
|
+
Set<String> orderNumbers = new Set<String>();
|
|
118
|
+
|
|
119
|
+
for (OrderStatusRequest req : requests) {
|
|
120
|
+
orderNumbers.add(req.orderNumber);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
Map<String, Order> orderMap = new Map<String, Order>();
|
|
124
|
+
for (Order o : [
|
|
125
|
+
SELECT Id, OrderNumber, Status, ExpectedDeliveryDate__c
|
|
126
|
+
FROM Order
|
|
127
|
+
WHERE OrderNumber IN :orderNumbers
|
|
128
|
+
WITH USER_MODE
|
|
129
|
+
]) {
|
|
130
|
+
orderMap.put(o.OrderNumber, o);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
for (OrderStatusRequest req : requests) {
|
|
134
|
+
OrderStatusResponse resp = new OrderStatusResponse();
|
|
135
|
+
Order o = orderMap.get(req.orderNumber);
|
|
136
|
+
if (o != null) {
|
|
137
|
+
resp.status = o.Status;
|
|
138
|
+
resp.expectedDelivery = o.ExpectedDeliveryDate__c;
|
|
139
|
+
resp.message = 'Order ' + o.OrderNumber + ' is ' + o.Status;
|
|
140
|
+
} else {
|
|
141
|
+
resp.message = 'Order not found: ' + req.orderNumber;
|
|
142
|
+
}
|
|
143
|
+
responses.add(resp);
|
|
144
|
+
}
|
|
145
|
+
return responses;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### 4. Prompt Templates
|
|
151
|
+
|
|
152
|
+
- Use **Prompt Builder** in Setup to create reusable prompt templates
|
|
153
|
+
- Ground templates with **Data Cloud** merge fields for accurate, hallucination-resistant output
|
|
154
|
+
- Test templates with different personas and edge cases
|
|
155
|
+
|
|
156
|
+
### 5. Guardrails
|
|
157
|
+
|
|
158
|
+
- Use **Agent Script** for mission-critical tasks (enforces if/then deterministic workflows)
|
|
159
|
+
- Configure **Content Safety Policies** for output filtering
|
|
160
|
+
- Enable **Audit Trails** in Command Center for monitoring
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## Multi-Agent Orchestration
|
|
165
|
+
|
|
166
|
+
```
|
|
167
|
+
βββββββββββββββββββββββββββ
|
|
168
|
+
β Supervisor Agent β β Single front door
|
|
169
|
+
β (routes to children) β
|
|
170
|
+
βββββββββββββββββββββββββββ€
|
|
171
|
+
β β
|
|
172
|
+
β βββββββββ βββββββββββββ
|
|
173
|
+
β β Sales β β Service ββ
|
|
174
|
+
β β Agent β β Agent ββ
|
|
175
|
+
β βββββββββ βββββββββββββ
|
|
176
|
+
β βββββββββ βββββββββββββ
|
|
177
|
+
β β Customβ β Analyticsββ
|
|
178
|
+
β β Agent β β Agent ββ
|
|
179
|
+
β βββββββββ βββββββββββββ
|
|
180
|
+
βββββββββββββββββββββββββββ
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
- Use a **Supervisor Agent** as the entry point
|
|
184
|
+
- Route to **specialist agents** based on Topic matching
|
|
185
|
+
- Each child agent has its own Topics and Actions
|
|
186
|
+
- Monitor via **Command Center**
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
## Testing Agentforce
|
|
191
|
+
|
|
192
|
+
1. **Unit test** all `@InvocableMethod` classes like standard Apex
|
|
193
|
+
2. **Test in Agent Builder** preview panel with sample conversations
|
|
194
|
+
3. **Validate** action descriptions by checking if Atlas picks the correct action
|
|
195
|
+
4. **Edge cases**: What happens when the action returns no data? Empty input? Error?
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
## Agentforce for Developers (A4D) Rules
|
|
200
|
+
|
|
201
|
+
Salesforce recognizes `.sfdx/a4d/rules/*.md` files for AI coding assistant rules:
|
|
202
|
+
|
|
203
|
+
```
|
|
204
|
+
.sfdx/
|
|
205
|
+
a4d/
|
|
206
|
+
rules/
|
|
207
|
+
apex.md β Apex generation rules
|
|
208
|
+
html.md β LWC HTML template rules
|
|
209
|
+
css.md β Component CSS rules
|
|
210
|
+
js.md β LWC JavaScript rules
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
These are auto-detected by Agentforce for Developers during code generation. Consider mirroring your `.ai/prompts/` content here for A4D compatibility.
|