Build tracker identification prompt categories dynamically
Generate the category list from coredata.ThirdPartyCategories() at runtime instead of hardcoding it in the prompt text. Type the TrackerIdentification.Category field as coredata.ThirdPartyCategory so JSON unmarshaling validates values automatically. Also documents the .txt.tmpl template file naming convention. Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
@@ -72,6 +72,27 @@ shutdown broadcast onto a per-run `cancelRun(agent.ErrSuspendForCheckpoint)`,
|
||||
so the same contract drives both the public Go API and the worker
|
||||
infrastructure path.
|
||||
|
||||
## Prompt templates
|
||||
|
||||
Prompt files with placeholders use `.txt.tmpl` (see general template naming
|
||||
convention in `.cursor/rules/template-files.mdc`).
|
||||
|
||||
Use `agent.WithInstructionsFunc` to build prompts dynamically at runtime:
|
||||
|
||||
```go
|
||||
//go:embed prompts/tracker_identification.txt.tmpl
|
||||
var trackerIdentificationPrompt string
|
||||
|
||||
func trackerMappingInstructions(_ context.Context, _ *agent.Agent) string {
|
||||
categories := coredata.ThirdPartyCategories()
|
||||
parts := make([]string, len(categories))
|
||||
for i, c := range categories {
|
||||
parts[i] = string(c)
|
||||
}
|
||||
return strings.Replace(trackerIdentificationPrompt, "{{.Categories}}", strings.Join(parts, ", "), 1)
|
||||
}
|
||||
```
|
||||
|
||||
## Limits
|
||||
|
||||
- Max turns: 10 (default)
|
||||
|
||||
29
contrib/claude/file-naming.md
Normal file
29
contrib/claude/file-naming.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# File naming conventions
|
||||
|
||||
## Template files
|
||||
|
||||
Template files use the extension pattern `<name>.<output-ext>.tmpl`:
|
||||
|
||||
```
|
||||
pkg/trust/sitemap.xml.tmpl
|
||||
pkg/server/mailactions/templates/page.html.tmpl
|
||||
pkg/cookiebanner/prompts/tracker_identification.txt.tmpl
|
||||
pkg/probo/templates/risk_list.json.tmpl
|
||||
compose/keycloak/probo-realm.json.tmpl
|
||||
pkg/esign/certificate.html.tmpl
|
||||
```
|
||||
|
||||
The `<output-ext>` indicates the format produced after rendering (`.xml`, `.html`, `.txt`, `.json`). The final `.tmpl` suffix marks the file as a template requiring substitution before use.
|
||||
|
||||
### Dynamic values over hardcoded lists
|
||||
|
||||
Never hardcode enum values or source-of-truth lists in template text. Use a
|
||||
placeholder and substitute at runtime so the template stays in sync with the
|
||||
code:
|
||||
|
||||
```
|
||||
Use one of: {{.Categories}}.
|
||||
```
|
||||
|
||||
For single-placeholder templates, `strings.Replace` is sufficient. For multiple
|
||||
placeholders, use `text/template`.
|
||||
Reference in New Issue
Block a user