ag-cortex 0.1.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/.agent/commands/test-browser.md +339 -0
- package/.agent/rules/00-constitution.md +46 -0
- package/.agent/rules/project-rules.md +49 -0
- package/.agent/skills/agent-browser/SKILL.md +223 -0
- package/.agent/skills/agent-native-architecture/SKILL.md +435 -0
- package/.agent/skills/agent-native-architecture/references/action-parity-discipline.md +409 -0
- package/.agent/skills/agent-native-architecture/references/agent-execution-patterns.md +467 -0
- package/.agent/skills/agent-native-architecture/references/agent-native-testing.md +582 -0
- package/.agent/skills/agent-native-architecture/references/architecture-patterns.md +478 -0
- package/.agent/skills/agent-native-architecture/references/dynamic-context-injection.md +338 -0
- package/.agent/skills/agent-native-architecture/references/files-universal-interface.md +301 -0
- package/.agent/skills/agent-native-architecture/references/from-primitives-to-domain-tools.md +359 -0
- package/.agent/skills/agent-native-architecture/references/mcp-tool-design.md +506 -0
- package/.agent/skills/agent-native-architecture/references/mobile-patterns.md +871 -0
- package/.agent/skills/agent-native-architecture/references/product-implications.md +443 -0
- package/.agent/skills/agent-native-architecture/references/refactoring-to-prompt-native.md +317 -0
- package/.agent/skills/agent-native-architecture/references/self-modification.md +269 -0
- package/.agent/skills/agent-native-architecture/references/shared-workspace-architecture.md +680 -0
- package/.agent/skills/agent-native-architecture/references/system-prompt-design.md +250 -0
- package/.agent/skills/agent-native-reviewer/SKILL.md +246 -0
- package/.agent/skills/andrew-kane-gem-writer/SKILL.md +184 -0
- package/.agent/skills/andrew-kane-gem-writer/references/database-adapters.md +231 -0
- package/.agent/skills/andrew-kane-gem-writer/references/module-organization.md +121 -0
- package/.agent/skills/andrew-kane-gem-writer/references/rails-integration.md +183 -0
- package/.agent/skills/andrew-kane-gem-writer/references/resources.md +119 -0
- package/.agent/skills/andrew-kane-gem-writer/references/testing-patterns.md +261 -0
- package/.agent/skills/ankane-readme-writer/SKILL.md +50 -0
- package/.agent/skills/architecture-strategist/SKILL.md +52 -0
- package/.agent/skills/best-practices-researcher/SKILL.md +100 -0
- package/.agent/skills/bug-reproduction-validator/SKILL.md +67 -0
- package/.agent/skills/code-simplicity-reviewer/SKILL.md +85 -0
- package/.agent/skills/coding-tutor/.claude-plugin/plugin.json +9 -0
- package/.agent/skills/coding-tutor/README.md +37 -0
- package/.agent/skills/coding-tutor/commands/quiz-me.md +1 -0
- package/.agent/skills/coding-tutor/commands/sync-tutorials.md +25 -0
- package/.agent/skills/coding-tutor/commands/teach-me.md +1 -0
- package/.agent/skills/coding-tutor/skills/coding-tutor/SKILL.md +214 -0
- package/.agent/skills/coding-tutor/skills/coding-tutor/scripts/create_tutorial.py +202 -0
- package/.agent/skills/coding-tutor/skills/coding-tutor/scripts/index_tutorials.py +203 -0
- package/.agent/skills/coding-tutor/skills/coding-tutor/scripts/quiz_priority.py +190 -0
- package/.agent/skills/coding-tutor/skills/coding-tutor/scripts/setup_tutorials.py +132 -0
- package/.agent/skills/compound-docs/SKILL.md +510 -0
- package/.agent/skills/compound-docs/assets/critical-pattern-template.md +34 -0
- package/.agent/skills/compound-docs/assets/resolution-template.md +93 -0
- package/.agent/skills/compound-docs/references/yaml-schema.md +65 -0
- package/.agent/skills/compound-docs/schema.yaml +176 -0
- package/.agent/skills/create-agent-skills/SKILL.md +299 -0
- package/.agent/skills/create-agent-skills/references/api-security.md +226 -0
- package/.agent/skills/create-agent-skills/references/be-clear-and-direct.md +531 -0
- package/.agent/skills/create-agent-skills/references/best-practices.md +404 -0
- package/.agent/skills/create-agent-skills/references/common-patterns.md +595 -0
- package/.agent/skills/create-agent-skills/references/core-principles.md +437 -0
- package/.agent/skills/create-agent-skills/references/executable-code.md +175 -0
- package/.agent/skills/create-agent-skills/references/iteration-and-testing.md +474 -0
- package/.agent/skills/create-agent-skills/references/official-spec.md +185 -0
- package/.agent/skills/create-agent-skills/references/recommended-structure.md +168 -0
- package/.agent/skills/create-agent-skills/references/skill-structure.md +372 -0
- package/.agent/skills/create-agent-skills/references/using-scripts.md +113 -0
- package/.agent/skills/create-agent-skills/references/using-templates.md +112 -0
- package/.agent/skills/create-agent-skills/references/workflows-and-validation.md +510 -0
- package/.agent/skills/create-agent-skills/templates/router-skill.md +73 -0
- package/.agent/skills/create-agent-skills/templates/simple-skill.md +33 -0
- package/.agent/skills/create-agent-skills/workflows/add-reference.md +96 -0
- package/.agent/skills/create-agent-skills/workflows/add-script.md +93 -0
- package/.agent/skills/create-agent-skills/workflows/add-template.md +74 -0
- package/.agent/skills/create-agent-skills/workflows/add-workflow.md +120 -0
- package/.agent/skills/create-agent-skills/workflows/audit-skill.md +138 -0
- package/.agent/skills/create-agent-skills/workflows/create-domain-expertise-skill.md +605 -0
- package/.agent/skills/create-agent-skills/workflows/create-new-skill.md +191 -0
- package/.agent/skills/create-agent-skills/workflows/get-guidance.md +121 -0
- package/.agent/skills/create-agent-skills/workflows/upgrade-to-router.md +161 -0
- package/.agent/skills/create-agent-skills/workflows/verify-skill.md +204 -0
- package/.agent/skills/data-integrity-guardian/SKILL.md +70 -0
- package/.agent/skills/data-migration-expert/SKILL.md +97 -0
- package/.agent/skills/deployment-verification-agent/SKILL.md +159 -0
- package/.agent/skills/design-implementation-reviewer/SKILL.md +85 -0
- package/.agent/skills/design-iterator/SKILL.md +197 -0
- package/.agent/skills/dhh-rails-reviewer/SKILL.md +45 -0
- package/.agent/skills/dhh-rails-style/SKILL.md +184 -0
- package/.agent/skills/dhh-rails-style/references/architecture.md +653 -0
- package/.agent/skills/dhh-rails-style/references/controllers.md +303 -0
- package/.agent/skills/dhh-rails-style/references/frontend.md +510 -0
- package/.agent/skills/dhh-rails-style/references/gems.md +266 -0
- package/.agent/skills/dhh-rails-style/references/models.md +359 -0
- package/.agent/skills/dhh-rails-style/references/testing.md +338 -0
- package/.agent/skills/dspy-ruby/SKILL.md +594 -0
- package/.agent/skills/dspy-ruby/assets/config-template.rb +359 -0
- package/.agent/skills/dspy-ruby/assets/module-template.rb +326 -0
- package/.agent/skills/dspy-ruby/assets/signature-template.rb +143 -0
- package/.agent/skills/dspy-ruby/references/core-concepts.md +265 -0
- package/.agent/skills/dspy-ruby/references/optimization.md +623 -0
- package/.agent/skills/dspy-ruby/references/providers.md +305 -0
- package/.agent/skills/every-style-editor/SKILL.md +134 -0
- package/.agent/skills/every-style-editor/references/EVERY_WRITE_STYLE.md +529 -0
- package/.agent/skills/figma-design-sync/SKILL.md +166 -0
- package/.agent/skills/file-todos/SKILL.md +251 -0
- package/.agent/skills/file-todos/assets/todo-template.md +155 -0
- package/.agent/skills/framework-docs-researcher/SKILL.md +83 -0
- package/.agent/skills/frontend-design/SKILL.md +42 -0
- package/.agent/skills/gemini-imagegen/SKILL.md +237 -0
- package/.agent/skills/gemini-imagegen/requirements.txt +2 -0
- package/.agent/skills/gemini-imagegen/scripts/compose_images.py +168 -0
- package/.agent/skills/gemini-imagegen/scripts/edit_image.py +157 -0
- package/.agent/skills/gemini-imagegen/scripts/gemini_images.py +265 -0
- package/.agent/skills/gemini-imagegen/scripts/generate_image.py +147 -0
- package/.agent/skills/gemini-imagegen/scripts/multi_turn_chat.py +215 -0
- package/.agent/skills/git-history-analyzer/SKILL.md +42 -0
- package/.agent/skills/git-worktree/SKILL.md +302 -0
- package/.agent/skills/git-worktree/scripts/worktree-manager.sh +345 -0
- package/.agent/skills/julik-frontend-races-reviewer/SKILL.md +222 -0
- package/.agent/skills/kieran-python-reviewer/SKILL.md +104 -0
- package/.agent/skills/kieran-rails-reviewer/SKILL.md +86 -0
- package/.agent/skills/kieran-typescript-reviewer/SKILL.md +95 -0
- package/.agent/skills/lint/SKILL.md +16 -0
- package/.agent/skills/pattern-recognition-specialist/SKILL.md +57 -0
- package/.agent/skills/performance-oracle/SKILL.md +110 -0
- package/.agent/skills/pr-comment-resolver/SKILL.md +69 -0
- package/.agent/skills/rclone/SKILL.md +150 -0
- package/.agent/skills/rclone/scripts/check_setup.sh +60 -0
- package/.agent/skills/repo-research-analyst/SKILL.md +113 -0
- package/.agent/skills/security-sentinel/SKILL.md +93 -0
- package/.agent/skills/skill-creator/SKILL.md +209 -0
- package/.agent/skills/skill-creator/scripts/init_skill.py +304 -0
- package/.agent/skills/skill-creator/scripts/package_skill.py +112 -0
- package/.agent/skills/skill-creator/scripts/quick_validate.py +72 -0
- package/.agent/skills/spec-flow-analyzer/SKILL.md +113 -0
- package/.agent/skills/test-agent/SKILL.md +4 -0
- package/.agent/workflows/agent-native-audit.md +277 -0
- package/.agent/workflows/ask-user-question.md +21 -0
- package/.agent/workflows/changelog.md +137 -0
- package/.agent/workflows/compound.md +202 -0
- package/.agent/workflows/create-agent-skill.md +8 -0
- package/.agent/workflows/deepen-plan-research.md +334 -0
- package/.agent/workflows/deepen-plan-synthesis.md +182 -0
- package/.agent/workflows/deepen-plan.md +79 -0
- package/.agent/workflows/feature-video.md +342 -0
- package/.agent/workflows/generate-command.md +162 -0
- package/.agent/workflows/heal-skill.md +142 -0
- package/.agent/workflows/lfg.md +20 -0
- package/.agent/workflows/plan-analysis.md +67 -0
- package/.agent/workflows/plan-next-steps.md +63 -0
- package/.agent/workflows/plan-review.md +33 -0
- package/.agent/workflows/plan-synthesis.md +106 -0
- package/.agent/workflows/plan.md +49 -0
- package/.agent/workflows/report-bug.md +150 -0
- package/.agent/workflows/reproduce-bug.md +99 -0
- package/.agent/workflows/resolve-parallel.md +34 -0
- package/.agent/workflows/resolve-pr-parallel.md +49 -0
- package/.agent/workflows/resolve-todo-parallel.md +35 -0
- package/.agent/workflows/review-analysis.md +145 -0
- package/.agent/workflows/review-synthesis.md +262 -0
- package/.agent/workflows/review.md +64 -0
- package/.agent/workflows/ship.md +90 -0
- package/.agent/workflows/test-command.md +3 -0
- package/.agent/workflows/triage.md +310 -0
- package/.agent/workflows/work.md +157 -0
- package/.agent/workflows/xcode-test.md +332 -0
- package/LICENSE +22 -0
- package/README.md +49 -0
- package/bin/ag-cortex.js +54 -0
- package/lib/core.js +165 -0
- package/package.json +31 -0
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
<overview>
|
|
2
|
+
How to inject dynamic runtime context into agent system prompts. The agent needs to know what exists in the app to know what it can work with. Static prompts aren't enough—the agent needs to see the same context the user sees.
|
|
3
|
+
|
|
4
|
+
**Core principle:** The user's context IS the agent's context.
|
|
5
|
+
</overview>
|
|
6
|
+
|
|
7
|
+
<why_context_matters>
|
|
8
|
+
## Why Dynamic Context Injection?
|
|
9
|
+
|
|
10
|
+
A static system prompt tells the agent what it CAN do. Dynamic context tells it what it can do RIGHT NOW with the user's actual data.
|
|
11
|
+
|
|
12
|
+
**The failure case:**
|
|
13
|
+
```
|
|
14
|
+
User: "Write a little thing about Catherine the Great in my reading feed"
|
|
15
|
+
Agent: "What system are you referring to? I'm not sure what reading feed means."
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The agent failed because it didn't know:
|
|
19
|
+
- What books exist in the user's library
|
|
20
|
+
- What the "reading feed" is
|
|
21
|
+
- What tools it has to publish there
|
|
22
|
+
|
|
23
|
+
**The fix:** Inject runtime context about app state into the system prompt.
|
|
24
|
+
</why_context_matters>
|
|
25
|
+
|
|
26
|
+
<pattern name="context-injection">
|
|
27
|
+
## The Context Injection Pattern
|
|
28
|
+
|
|
29
|
+
Build your system prompt dynamically, including current app state:
|
|
30
|
+
|
|
31
|
+
```swift
|
|
32
|
+
func buildSystemPrompt() -> String {
|
|
33
|
+
// Gather current state
|
|
34
|
+
let availableBooks = libraryService.books
|
|
35
|
+
let recentActivity = analysisService.recentRecords(limit: 10)
|
|
36
|
+
let userProfile = profileService.currentProfile
|
|
37
|
+
|
|
38
|
+
return """
|
|
39
|
+
# Your Identity
|
|
40
|
+
|
|
41
|
+
You are a reading assistant for \(userProfile.name)'s library.
|
|
42
|
+
|
|
43
|
+
## Available Books in User's Library
|
|
44
|
+
|
|
45
|
+
\(availableBooks.map { "- \"\($0.title)\" by \($0.author) (id: \($0.id))" }.joined(separator: "\n"))
|
|
46
|
+
|
|
47
|
+
## Recent Reading Activity
|
|
48
|
+
|
|
49
|
+
\(recentActivity.map { "- Analyzed \"\($0.bookTitle)\": \($0.excerptPreview)" }.joined(separator: "\n"))
|
|
50
|
+
|
|
51
|
+
## Your Capabilities
|
|
52
|
+
|
|
53
|
+
- **publish_to_feed**: Create insights that appear in the Feed tab
|
|
54
|
+
- **read_library**: View books, highlights, and analyses
|
|
55
|
+
- **web_search**: Search the internet for research
|
|
56
|
+
- **write_file**: Save research to Documents/Research/{bookId}/
|
|
57
|
+
|
|
58
|
+
When the user mentions "the feed" or "reading feed", they mean the Feed tab
|
|
59
|
+
where insights appear. Use `publish_to_feed` to create content there.
|
|
60
|
+
"""
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
</pattern>
|
|
64
|
+
|
|
65
|
+
<what_to_inject>
|
|
66
|
+
## What Context to Inject
|
|
67
|
+
|
|
68
|
+
### 1. Available Resources
|
|
69
|
+
What data/files exist that the agent can access?
|
|
70
|
+
|
|
71
|
+
```swift
|
|
72
|
+
## Available in User's Library
|
|
73
|
+
|
|
74
|
+
Books:
|
|
75
|
+
- "Moby Dick" by Herman Melville (id: book_123)
|
|
76
|
+
- "1984" by George Orwell (id: book_456)
|
|
77
|
+
|
|
78
|
+
Research folders:
|
|
79
|
+
- Documents/Research/book_123/ (3 files)
|
|
80
|
+
- Documents/Research/book_456/ (1 file)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### 2. Current State
|
|
84
|
+
What has the user done recently? What's the current context?
|
|
85
|
+
|
|
86
|
+
```swift
|
|
87
|
+
## Recent Activity
|
|
88
|
+
|
|
89
|
+
- 2 hours ago: Highlighted passage in "1984" about surveillance
|
|
90
|
+
- Yesterday: Completed research on "Moby Dick" whale symbolism
|
|
91
|
+
- This week: Added 3 new books to library
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### 3. Capabilities Mapping
|
|
95
|
+
What tool maps to what UI feature? Use the user's language.
|
|
96
|
+
|
|
97
|
+
```swift
|
|
98
|
+
## What You Can Do
|
|
99
|
+
|
|
100
|
+
| User Says | You Should Use | Result |
|
|
101
|
+
|-----------|----------------|--------|
|
|
102
|
+
| "my feed" / "reading feed" | `publish_to_feed` | Creates insight in Feed tab |
|
|
103
|
+
| "my library" / "my books" | `read_library` | Shows their book collection |
|
|
104
|
+
| "research this" | `web_search` + `write_file` | Saves to Research folder |
|
|
105
|
+
| "my profile" | `read_file("profile.md")` | Shows reading profile |
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### 4. Domain Vocabulary
|
|
109
|
+
Explain app-specific terms the user might use.
|
|
110
|
+
|
|
111
|
+
```swift
|
|
112
|
+
## Vocabulary
|
|
113
|
+
|
|
114
|
+
- **Feed**: The Feed tab showing reading insights and analyses
|
|
115
|
+
- **Research folder**: Documents/Research/{bookId}/ where research is stored
|
|
116
|
+
- **Reading profile**: A markdown file describing user's reading preferences
|
|
117
|
+
- **Highlight**: A passage the user marked in a book
|
|
118
|
+
```
|
|
119
|
+
</what_to_inject>
|
|
120
|
+
|
|
121
|
+
<implementation_patterns>
|
|
122
|
+
## Implementation Patterns
|
|
123
|
+
|
|
124
|
+
### Pattern 1: Service-Based Injection (Swift/iOS)
|
|
125
|
+
|
|
126
|
+
```swift
|
|
127
|
+
class AgentContextBuilder {
|
|
128
|
+
let libraryService: BookLibraryService
|
|
129
|
+
let profileService: ReadingProfileService
|
|
130
|
+
let activityService: ActivityService
|
|
131
|
+
|
|
132
|
+
func buildContext() -> String {
|
|
133
|
+
let books = libraryService.books
|
|
134
|
+
let profile = profileService.currentProfile
|
|
135
|
+
let activity = activityService.recent(limit: 10)
|
|
136
|
+
|
|
137
|
+
return """
|
|
138
|
+
## Library (\(books.count) books)
|
|
139
|
+
\(formatBooks(books))
|
|
140
|
+
|
|
141
|
+
## Profile
|
|
142
|
+
\(profile.summary)
|
|
143
|
+
|
|
144
|
+
## Recent Activity
|
|
145
|
+
\(formatActivity(activity))
|
|
146
|
+
"""
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
private func formatBooks(_ books: [Book]) -> String {
|
|
150
|
+
books.map { "- \"\($0.title)\" (id: \($0.id))" }.joined(separator: "\n")
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Usage in agent initialization
|
|
155
|
+
let context = AgentContextBuilder(
|
|
156
|
+
libraryService: .shared,
|
|
157
|
+
profileService: .shared,
|
|
158
|
+
activityService: .shared
|
|
159
|
+
).buildContext()
|
|
160
|
+
|
|
161
|
+
let systemPrompt = basePrompt + "\n\n" + context
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Pattern 2: Hook-Based Injection (TypeScript)
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
interface ContextProvider {
|
|
168
|
+
getContext(): Promise<string>;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
class LibraryContextProvider implements ContextProvider {
|
|
172
|
+
async getContext(): Promise<string> {
|
|
173
|
+
const books = await db.books.list();
|
|
174
|
+
const recent = await db.activity.recent(10);
|
|
175
|
+
|
|
176
|
+
return `
|
|
177
|
+
## Library
|
|
178
|
+
${books.map(b => `- "${b.title}" (${b.id})`).join('\n')}
|
|
179
|
+
|
|
180
|
+
## Recent
|
|
181
|
+
${recent.map(r => `- ${r.description}`).join('\n')}
|
|
182
|
+
`.trim();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Compose multiple providers
|
|
187
|
+
async function buildSystemPrompt(providers: ContextProvider[]): Promise<string> {
|
|
188
|
+
const contexts = await Promise.all(providers.map(p => p.getContext()));
|
|
189
|
+
return [BASE_PROMPT, ...contexts].join('\n\n');
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Pattern 3: Template-Based Injection
|
|
194
|
+
|
|
195
|
+
```markdown
|
|
196
|
+
# System Prompt Template (system-prompt.template.md)
|
|
197
|
+
|
|
198
|
+
You are a reading assistant.
|
|
199
|
+
|
|
200
|
+
## Available Books
|
|
201
|
+
|
|
202
|
+
{{#each books}}
|
|
203
|
+
- "{{title}}" by {{author}} (id: {{id}})
|
|
204
|
+
{{/each}}
|
|
205
|
+
|
|
206
|
+
## Capabilities
|
|
207
|
+
|
|
208
|
+
{{#each capabilities}}
|
|
209
|
+
- **{{name}}**: {{description}}
|
|
210
|
+
{{/each}}
|
|
211
|
+
|
|
212
|
+
## Recent Activity
|
|
213
|
+
|
|
214
|
+
{{#each recentActivity}}
|
|
215
|
+
- {{timestamp}}: {{description}}
|
|
216
|
+
{{/each}}
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
```typescript
|
|
220
|
+
// Render at runtime
|
|
221
|
+
const prompt = Handlebars.compile(template)({
|
|
222
|
+
books: await libraryService.getBooks(),
|
|
223
|
+
capabilities: getCapabilities(),
|
|
224
|
+
recentActivity: await activityService.getRecent(10),
|
|
225
|
+
});
|
|
226
|
+
```
|
|
227
|
+
</implementation_patterns>
|
|
228
|
+
|
|
229
|
+
<context_freshness>
|
|
230
|
+
## Context Freshness
|
|
231
|
+
|
|
232
|
+
Context should be injected at agent initialization, and optionally refreshed during long sessions.
|
|
233
|
+
|
|
234
|
+
**At initialization:**
|
|
235
|
+
```swift
|
|
236
|
+
// Always inject fresh context when starting an agent
|
|
237
|
+
func startChatAgent() async -> AgentSession {
|
|
238
|
+
let context = await buildCurrentContext() // Fresh context
|
|
239
|
+
return await AgentOrchestrator.shared.startAgent(
|
|
240
|
+
config: ChatAgent.config,
|
|
241
|
+
systemPrompt: basePrompt + context
|
|
242
|
+
)
|
|
243
|
+
}
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
**During long sessions (optional):**
|
|
247
|
+
```swift
|
|
248
|
+
// For long-running agents, provide a refresh tool
|
|
249
|
+
tool("refresh_context", "Get current app state") { _ in
|
|
250
|
+
let books = libraryService.books
|
|
251
|
+
let recent = activityService.recent(10)
|
|
252
|
+
return """
|
|
253
|
+
Current library: \(books.count) books
|
|
254
|
+
Recent: \(recent.map { $0.summary }.joined(separator: ", "))
|
|
255
|
+
"""
|
|
256
|
+
}
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
**What NOT to do:**
|
|
260
|
+
```swift
|
|
261
|
+
// DON'T: Use stale context from app launch
|
|
262
|
+
let cachedContext = appLaunchContext // Stale!
|
|
263
|
+
// Books may have been added, activity may have changed
|
|
264
|
+
```
|
|
265
|
+
</context_freshness>
|
|
266
|
+
|
|
267
|
+
<examples>
|
|
268
|
+
## Real-World Example: Every Reader
|
|
269
|
+
|
|
270
|
+
The Every Reader app injects context for its chat agent:
|
|
271
|
+
|
|
272
|
+
```swift
|
|
273
|
+
func getChatAgentSystemPrompt() -> String {
|
|
274
|
+
// Get current library state
|
|
275
|
+
let books = BookLibraryService.shared.books
|
|
276
|
+
let analyses = BookLibraryService.shared.analysisRecords.prefix(10)
|
|
277
|
+
let profile = ReadingProfileService.shared.getProfileForSystemPrompt()
|
|
278
|
+
|
|
279
|
+
let bookList = books.map { book in
|
|
280
|
+
"- \"\(book.title)\" by \(book.author) (id: \(book.id))"
|
|
281
|
+
}.joined(separator: "\n")
|
|
282
|
+
|
|
283
|
+
let recentList = analyses.map { record in
|
|
284
|
+
let title = books.first { $0.id == record.bookId }?.title ?? "Unknown"
|
|
285
|
+
return "- From \"\(title)\": \"\(record.excerptPreview)\""
|
|
286
|
+
}.joined(separator: "\n")
|
|
287
|
+
|
|
288
|
+
return """
|
|
289
|
+
# Reading Assistant
|
|
290
|
+
|
|
291
|
+
You help the user with their reading and book research.
|
|
292
|
+
|
|
293
|
+
## Available Books in User's Library
|
|
294
|
+
|
|
295
|
+
\(bookList.isEmpty ? "No books yet." : bookList)
|
|
296
|
+
|
|
297
|
+
## Recent Reading Journal (Latest Analyses)
|
|
298
|
+
|
|
299
|
+
\(recentList.isEmpty ? "No analyses yet." : recentList)
|
|
300
|
+
|
|
301
|
+
## Reading Profile
|
|
302
|
+
|
|
303
|
+
\(profile)
|
|
304
|
+
|
|
305
|
+
## Your Capabilities
|
|
306
|
+
|
|
307
|
+
- **Publish to Feed**: Create insights using `publish_to_feed` that appear in the Feed tab
|
|
308
|
+
- **Library Access**: View books and highlights using `read_library`
|
|
309
|
+
- **Research**: Search web and save to Documents/Research/{bookId}/
|
|
310
|
+
- **Profile**: Read/update the user's reading profile
|
|
311
|
+
|
|
312
|
+
When the user asks you to "write something for their feed" or "add to my reading feed",
|
|
313
|
+
use the `publish_to_feed` tool with the relevant book_id.
|
|
314
|
+
"""
|
|
315
|
+
}
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
**Result:** When user says "write a little thing about Catherine the Great in my reading feed", the agent:
|
|
319
|
+
1. Sees "reading feed" → knows to use `publish_to_feed`
|
|
320
|
+
2. Sees available books → finds the relevant book ID
|
|
321
|
+
3. Creates appropriate content for the Feed tab
|
|
322
|
+
</examples>
|
|
323
|
+
|
|
324
|
+
<checklist>
|
|
325
|
+
## Context Injection Checklist
|
|
326
|
+
|
|
327
|
+
Before launching an agent:
|
|
328
|
+
- [ ] System prompt includes current resources (books, files, data)
|
|
329
|
+
- [ ] Recent activity is visible to the agent
|
|
330
|
+
- [ ] Capabilities are mapped to user vocabulary
|
|
331
|
+
- [ ] Domain-specific terms are explained
|
|
332
|
+
- [ ] Context is fresh (gathered at agent start, not cached)
|
|
333
|
+
|
|
334
|
+
When adding new features:
|
|
335
|
+
- [ ] New resources are included in context injection
|
|
336
|
+
- [ ] New capabilities are documented in system prompt
|
|
337
|
+
- [ ] User vocabulary for the feature is mapped
|
|
338
|
+
</checklist>
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
<overview>
|
|
2
|
+
Files are the universal interface for agent-native applications. Agents are naturally fluent with file operations—they already know how to read, write, and organize files. This document covers why files work so well, how to organize them, and the context.md pattern for accumulated knowledge.
|
|
3
|
+
</overview>
|
|
4
|
+
|
|
5
|
+
<why_files>
|
|
6
|
+
## Why Files
|
|
7
|
+
|
|
8
|
+
Agents are naturally good at files. Antigravity works because bash + filesystem is the most battle-tested agent interface. When building agent-native apps, lean into this.
|
|
9
|
+
|
|
10
|
+
### Agents Already Know How
|
|
11
|
+
|
|
12
|
+
You don't need to teach the agent your API—it already knows `cat`, `grep`, `mv`, `mkdir`. File operations are the primitives it's most fluent with.
|
|
13
|
+
|
|
14
|
+
### Files Are Inspectable
|
|
15
|
+
|
|
16
|
+
Users can see what the agent created, edit it, move it, delete it. No black box. Complete transparency into agent behavior.
|
|
17
|
+
|
|
18
|
+
### Files Are Portable
|
|
19
|
+
|
|
20
|
+
Export is trivial. Backup is trivial. Users own their data. No vendor lock-in, no complex migration paths.
|
|
21
|
+
|
|
22
|
+
### App State Stays in Sync
|
|
23
|
+
|
|
24
|
+
On mobile, if you use the file system with iCloud, all devices share the same file system. The agent's work on one device appears on all devices—without you having to build a server.
|
|
25
|
+
|
|
26
|
+
### Directory Structure Is Information Architecture
|
|
27
|
+
|
|
28
|
+
The filesystem gives you hierarchy for free. `/projects/acme/notes/` is self-documenting in a way that `SELECT * FROM notes WHERE project_id = 123` isn't.
|
|
29
|
+
</why_files>
|
|
30
|
+
|
|
31
|
+
<file_organization>
|
|
32
|
+
## File Organization Patterns
|
|
33
|
+
|
|
34
|
+
> **Needs validation:** These conventions are one approach that's worked so far, not a prescription. Better solutions should be considered.
|
|
35
|
+
|
|
36
|
+
A general principle of agent-native design: **Design for what agents can reason about.** The best proxy for that is what would make sense to a human. If a human can look at your file structure and understand what's going on, an agent probably can too.
|
|
37
|
+
|
|
38
|
+
### Entity-Scoped Directories
|
|
39
|
+
|
|
40
|
+
Organize files around entities, not actors or file types:
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
{entity_type}/{entity_id}/
|
|
44
|
+
├── primary content
|
|
45
|
+
├── metadata
|
|
46
|
+
└── related materials
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
**Example:** `Research/books/{bookId}/` contains everything about one book—full text, notes, sources, agent logs.
|
|
50
|
+
|
|
51
|
+
### Naming Conventions
|
|
52
|
+
|
|
53
|
+
| File Type | Naming Pattern | Example |
|
|
54
|
+
|-----------|---------------|---------|
|
|
55
|
+
| Entity data | `{entity}.json` | `library.json`, `status.json` |
|
|
56
|
+
| Human-readable content | `{content_type}.md` | `introduction.md`, `profile.md` |
|
|
57
|
+
| Agent reasoning | `agent_log.md` | Per-entity agent history |
|
|
58
|
+
| Primary content | `full_text.txt` | Downloaded/extracted text |
|
|
59
|
+
| Multi-volume | `volume{N}.txt` | `volume1.txt`, `volume2.txt` |
|
|
60
|
+
| External sources | `{source_name}.md` | `wikipedia.md`, `sparknotes.md` |
|
|
61
|
+
| Checkpoints | `{sessionId}.checkpoint` | UUID-based |
|
|
62
|
+
| Configuration | `config.json` | Feature settings |
|
|
63
|
+
|
|
64
|
+
### Directory Naming
|
|
65
|
+
|
|
66
|
+
- **Entity-scoped:** `{entityType}/{entityId}/` (e.g., `Research/books/{bookId}/`)
|
|
67
|
+
- **Type-scoped:** `{type}/` (e.g., `AgentCheckpoints/`, `AgentLogs/`)
|
|
68
|
+
- **Convention:** Lowercase with underscores, not camelCase
|
|
69
|
+
|
|
70
|
+
### Ephemeral vs. Durable Separation
|
|
71
|
+
|
|
72
|
+
Separate agent working files from user's permanent data:
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
Documents/
|
|
76
|
+
├── AgentCheckpoints/ # Ephemeral (can delete)
|
|
77
|
+
│ └── {sessionId}.checkpoint
|
|
78
|
+
├── AgentLogs/ # Ephemeral (debugging)
|
|
79
|
+
│ └── {type}/{sessionId}.md
|
|
80
|
+
└── Research/ # Durable (user's work)
|
|
81
|
+
└── books/{bookId}/
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### The Split: Markdown vs JSON
|
|
85
|
+
|
|
86
|
+
- **Markdown:** For content users might read or edit
|
|
87
|
+
- **JSON:** For structured data the app queries
|
|
88
|
+
</file_organization>
|
|
89
|
+
|
|
90
|
+
<context_md_pattern>
|
|
91
|
+
## The context.md Pattern
|
|
92
|
+
|
|
93
|
+
A file the agent reads at the start of each session and updates as it learns:
|
|
94
|
+
|
|
95
|
+
```markdown
|
|
96
|
+
# Context
|
|
97
|
+
|
|
98
|
+
## Who I Am
|
|
99
|
+
Reading assistant for the Every app.
|
|
100
|
+
|
|
101
|
+
## What I Know About This User
|
|
102
|
+
- Interested in military history and Russian literature
|
|
103
|
+
- Prefers concise analysis
|
|
104
|
+
- Currently reading War and Peace
|
|
105
|
+
|
|
106
|
+
## What Exists
|
|
107
|
+
- 12 notes in /notes
|
|
108
|
+
- 3 active projects
|
|
109
|
+
- User preferences at /preferences.md
|
|
110
|
+
|
|
111
|
+
## Recent Activity
|
|
112
|
+
- User created "Project kickoff" (2 hours ago)
|
|
113
|
+
- Analyzed passage about Austerlitz (yesterday)
|
|
114
|
+
|
|
115
|
+
## My Guidelines
|
|
116
|
+
- Don't spoil books they're reading
|
|
117
|
+
- Use their interests to personalize insights
|
|
118
|
+
|
|
119
|
+
## Current State
|
|
120
|
+
- No pending tasks
|
|
121
|
+
- Last sync: 10 minutes ago
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Benefits
|
|
125
|
+
|
|
126
|
+
- **Agent behavior evolves without code changes** - Update the context, behavior changes
|
|
127
|
+
- **Users can inspect and modify** - Complete transparency
|
|
128
|
+
- **Natural place for accumulated context** - Learnings persist across sessions
|
|
129
|
+
- **Portable across sessions** - Restart agent, knowledge preserved
|
|
130
|
+
|
|
131
|
+
### How It Works
|
|
132
|
+
|
|
133
|
+
1. Agent reads `context.md` at session start
|
|
134
|
+
2. Agent updates it when learning something important
|
|
135
|
+
3. System can also update it (recent activity, new resources)
|
|
136
|
+
4. Context persists across sessions
|
|
137
|
+
|
|
138
|
+
### What to Include
|
|
139
|
+
|
|
140
|
+
| Section | Purpose |
|
|
141
|
+
|---------|---------|
|
|
142
|
+
| Who I Am | Agent identity and role |
|
|
143
|
+
| What I Know About This User | Learned preferences, interests |
|
|
144
|
+
| What Exists | Available resources, data |
|
|
145
|
+
| Recent Activity | Context for continuity |
|
|
146
|
+
| My Guidelines | Learned rules and constraints |
|
|
147
|
+
| Current State | Session status, pending items |
|
|
148
|
+
</context_md_pattern>
|
|
149
|
+
|
|
150
|
+
<files_vs_database>
|
|
151
|
+
## Files vs. Database
|
|
152
|
+
|
|
153
|
+
> **Needs validation:** This framing is informed by mobile development. For web apps, the tradeoffs are different.
|
|
154
|
+
|
|
155
|
+
| Use files for... | Use database for... |
|
|
156
|
+
|------------------|---------------------|
|
|
157
|
+
| Content users should read/edit | High-volume structured data |
|
|
158
|
+
| Configuration that benefits from version control | Data that needs complex queries |
|
|
159
|
+
| Agent-generated content | Ephemeral state (sessions, caches) |
|
|
160
|
+
| Anything that benefits from transparency | Data with relationships |
|
|
161
|
+
| Large text content | Data that needs indexing |
|
|
162
|
+
|
|
163
|
+
**The principle:** Files for legibility, databases for structure. When in doubt, files—they're more transparent and users can always inspect them.
|
|
164
|
+
|
|
165
|
+
### When Files Work Best
|
|
166
|
+
|
|
167
|
+
- Scale is small (one user's library, not millions of records)
|
|
168
|
+
- Transparency is valued over query speed
|
|
169
|
+
- Cloud sync (iCloud, Dropbox) works well with files
|
|
170
|
+
|
|
171
|
+
### Hybrid Approach
|
|
172
|
+
|
|
173
|
+
Even if you need a database for performance, consider maintaining a file-based "source of truth" that the agent works with, synced to the database for the UI:
|
|
174
|
+
|
|
175
|
+
```
|
|
176
|
+
Files (agent workspace):
|
|
177
|
+
Research/book_123/introduction.md
|
|
178
|
+
|
|
179
|
+
Database (UI queries):
|
|
180
|
+
research_index: { bookId, path, title, createdAt }
|
|
181
|
+
```
|
|
182
|
+
</files_vs_database>
|
|
183
|
+
|
|
184
|
+
<conflict_model>
|
|
185
|
+
## Conflict Model
|
|
186
|
+
|
|
187
|
+
If agents and users write to the same files, you need a conflict model.
|
|
188
|
+
|
|
189
|
+
### Current Reality
|
|
190
|
+
|
|
191
|
+
Most implementations use **last-write-wins** via atomic writes:
|
|
192
|
+
|
|
193
|
+
```swift
|
|
194
|
+
try data.write(to: url, options: [.atomic])
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
This is simple but can lose changes.
|
|
198
|
+
|
|
199
|
+
### Options
|
|
200
|
+
|
|
201
|
+
| Strategy | Pros | Cons |
|
|
202
|
+
|----------|------|------|
|
|
203
|
+
| **Last write wins** | Simple | Changes can be lost |
|
|
204
|
+
| **Agent checks before writing** | Preserves user edits | More complexity |
|
|
205
|
+
| **Separate spaces** | No conflicts | Less collaboration |
|
|
206
|
+
| **Append-only logs** | Never overwrites | Files grow forever |
|
|
207
|
+
| **File locking** | Safe concurrent access | Complexity, can block |
|
|
208
|
+
|
|
209
|
+
### Recommended Approaches
|
|
210
|
+
|
|
211
|
+
**For files agents write frequently (logs, status):** Last-write-wins is fine. Conflicts are rare.
|
|
212
|
+
|
|
213
|
+
**For files users edit (profiles, notes):** Consider explicit handling:
|
|
214
|
+
- Agent checks modification time before overwriting
|
|
215
|
+
- Or keep agent output separate from user-editable content
|
|
216
|
+
- Or use append-only pattern
|
|
217
|
+
|
|
218
|
+
### iCloud Considerations
|
|
219
|
+
|
|
220
|
+
iCloud sync adds complexity. It creates `{filename} (conflict).md` files when sync conflicts occur. Monitor for these:
|
|
221
|
+
|
|
222
|
+
```swift
|
|
223
|
+
NotificationCenter.default.addObserver(
|
|
224
|
+
forName: .NSMetadataQueryDidUpdate,
|
|
225
|
+
...
|
|
226
|
+
)
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### System Prompt Guidance
|
|
230
|
+
|
|
231
|
+
Tell the agent about the conflict model:
|
|
232
|
+
|
|
233
|
+
```markdown
|
|
234
|
+
## Working with User Content
|
|
235
|
+
|
|
236
|
+
When you create content, the user may edit it afterward. Always read
|
|
237
|
+
existing files before modifying them—the user may have made improvements
|
|
238
|
+
you should preserve.
|
|
239
|
+
|
|
240
|
+
If a file has been modified since you last wrote it, ask before overwriting.
|
|
241
|
+
```
|
|
242
|
+
</conflict_model>
|
|
243
|
+
|
|
244
|
+
<examples>
|
|
245
|
+
## Example: Reading App File Structure
|
|
246
|
+
|
|
247
|
+
```
|
|
248
|
+
Documents/
|
|
249
|
+
├── Library/
|
|
250
|
+
│ └── library.json # Book metadata
|
|
251
|
+
├── Research/
|
|
252
|
+
│ └── books/
|
|
253
|
+
│ └── {bookId}/
|
|
254
|
+
│ ├── full_text.txt # Downloaded content
|
|
255
|
+
│ ├── introduction.md # Agent-generated, user-editable
|
|
256
|
+
│ ├── notes.md # User notes
|
|
257
|
+
│ └── sources/
|
|
258
|
+
│ ├── wikipedia.md # Research gathered by agent
|
|
259
|
+
│ └── reviews.md
|
|
260
|
+
├── Chats/
|
|
261
|
+
│ └── {conversationId}.json # Chat history
|
|
262
|
+
├── Profile/
|
|
263
|
+
│ └── profile.md # User reading profile
|
|
264
|
+
└── context.md # Agent's accumulated knowledge
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
**How it works:**
|
|
268
|
+
|
|
269
|
+
1. User adds book → creates entry in `library.json`
|
|
270
|
+
2. Agent downloads text → saves to `Research/books/{id}/full_text.txt`
|
|
271
|
+
3. Agent researches → saves to `sources/`
|
|
272
|
+
4. Agent generates intro → saves to `introduction.md`
|
|
273
|
+
5. User edits intro → agent sees changes on next read
|
|
274
|
+
6. Agent updates `context.md` with learnings
|
|
275
|
+
</examples>
|
|
276
|
+
|
|
277
|
+
<checklist>
|
|
278
|
+
## Files as Universal Interface Checklist
|
|
279
|
+
|
|
280
|
+
### Organization
|
|
281
|
+
- [ ] Entity-scoped directories (`{type}/{id}/`)
|
|
282
|
+
- [ ] Consistent naming conventions
|
|
283
|
+
- [ ] Ephemeral vs durable separation
|
|
284
|
+
- [ ] Markdown for human content, JSON for structured data
|
|
285
|
+
|
|
286
|
+
### context.md
|
|
287
|
+
- [ ] Agent reads context at session start
|
|
288
|
+
- [ ] Agent updates context when learning
|
|
289
|
+
- [ ] Includes: identity, user knowledge, what exists, guidelines
|
|
290
|
+
- [ ] Persists across sessions
|
|
291
|
+
|
|
292
|
+
### Conflict Handling
|
|
293
|
+
- [ ] Conflict model defined (last-write-wins, check-before-write, etc.)
|
|
294
|
+
- [ ] Agent guidance in system prompt
|
|
295
|
+
- [ ] iCloud conflict monitoring (if applicable)
|
|
296
|
+
|
|
297
|
+
### Integration
|
|
298
|
+
- [ ] UI observes file changes (or shared service)
|
|
299
|
+
- [ ] Agent can read user edits
|
|
300
|
+
- [ ] User can inspect agent output
|
|
301
|
+
</checklist>
|