@agent-native/core 0.39.1 → 0.40.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 (208) hide show
  1. package/README.md +1 -1
  2. package/dist/action.js +12 -0
  3. package/dist/action.js.map +1 -1
  4. package/dist/cli/create.d.ts.map +1 -1
  5. package/dist/cli/create.js +5 -1
  6. package/dist/cli/create.js.map +1 -1
  7. package/dist/cli/index.js +1 -1
  8. package/dist/cli/index.js.map +1 -1
  9. package/dist/cli/skills.d.ts +6 -6
  10. package/dist/cli/skills.d.ts.map +1 -1
  11. package/dist/cli/skills.js +936 -1167
  12. package/dist/cli/skills.js.map +1 -1
  13. package/dist/client/MultiTabAssistantChat.d.ts.map +1 -1
  14. package/dist/client/MultiTabAssistantChat.js +2 -5
  15. package/dist/client/MultiTabAssistantChat.js.map +1 -1
  16. package/dist/client/NewWorkspaceAppFlow.js +1 -1
  17. package/dist/client/NewWorkspaceAppFlow.js.map +1 -1
  18. package/dist/client/blocks/AiEditableField.d.ts +8 -0
  19. package/dist/client/blocks/AiEditableField.d.ts.map +1 -0
  20. package/dist/client/blocks/AiEditableField.js +10 -0
  21. package/dist/client/blocks/AiEditableField.js.map +1 -0
  22. package/dist/client/blocks/BlockView.d.ts +3 -3
  23. package/dist/client/blocks/BlockView.d.ts.map +1 -1
  24. package/dist/client/blocks/BlockView.js +15 -3
  25. package/dist/client/blocks/BlockView.js.map +1 -1
  26. package/dist/client/blocks/SchemaBlockEditor.js +2 -2
  27. package/dist/client/blocks/SchemaBlockEditor.js.map +1 -1
  28. package/dist/client/blocks/index.d.ts +5 -2
  29. package/dist/client/blocks/index.d.ts.map +1 -1
  30. package/dist/client/blocks/index.js +6 -3
  31. package/dist/client/blocks/index.js.map +1 -1
  32. package/dist/client/blocks/library/ApiEndpointBlock.d.ts.map +1 -1
  33. package/dist/client/blocks/library/ApiEndpointBlock.js +20 -6
  34. package/dist/client/blocks/library/ApiEndpointBlock.js.map +1 -1
  35. package/dist/client/blocks/library/DiffBlock.d.ts +29 -0
  36. package/dist/client/blocks/library/DiffBlock.d.ts.map +1 -1
  37. package/dist/client/blocks/library/DiffBlock.js +190 -30
  38. package/dist/client/blocks/library/DiffBlock.js.map +1 -1
  39. package/dist/client/blocks/library/FileTreeBlock.d.ts.map +1 -1
  40. package/dist/client/blocks/library/FileTreeBlock.js +46 -7
  41. package/dist/client/blocks/library/FileTreeBlock.js.map +1 -1
  42. package/dist/client/blocks/library/HighlightedCode.d.ts +10 -0
  43. package/dist/client/blocks/library/HighlightedCode.d.ts.map +1 -0
  44. package/dist/client/blocks/library/HighlightedCode.js +92 -0
  45. package/dist/client/blocks/library/HighlightedCode.js.map +1 -0
  46. package/dist/client/blocks/library/JsonExplorerBlock.d.ts +9 -4
  47. package/dist/client/blocks/library/JsonExplorerBlock.d.ts.map +1 -1
  48. package/dist/client/blocks/library/JsonExplorerBlock.js +66 -30
  49. package/dist/client/blocks/library/JsonExplorerBlock.js.map +1 -1
  50. package/dist/client/blocks/library/MermaidBlock.d.ts.map +1 -1
  51. package/dist/client/blocks/library/MermaidBlock.js +73 -44
  52. package/dist/client/blocks/library/MermaidBlock.js.map +1 -1
  53. package/dist/client/blocks/library/OpenApiSpecBlock.d.ts.map +1 -1
  54. package/dist/client/blocks/library/OpenApiSpecBlock.js +3 -2
  55. package/dist/client/blocks/library/OpenApiSpecBlock.js.map +1 -1
  56. package/dist/client/blocks/library/checklist.d.ts.map +1 -1
  57. package/dist/client/blocks/library/checklist.js +1 -0
  58. package/dist/client/blocks/library/checklist.js.map +1 -1
  59. package/dist/client/blocks/library/code-tabs.d.ts.map +1 -1
  60. package/dist/client/blocks/library/code-tabs.js +183 -102
  61. package/dist/client/blocks/library/code-tabs.js.map +1 -1
  62. package/dist/client/blocks/library/columns.config.d.ts +60 -0
  63. package/dist/client/blocks/library/columns.config.d.ts.map +1 -0
  64. package/dist/client/blocks/library/columns.config.js +37 -0
  65. package/dist/client/blocks/library/columns.config.js.map +1 -0
  66. package/dist/client/blocks/library/columns.d.ts +25 -0
  67. package/dist/client/blocks/library/columns.d.ts.map +1 -0
  68. package/dist/client/blocks/library/columns.js +199 -0
  69. package/dist/client/blocks/library/columns.js.map +1 -0
  70. package/dist/client/blocks/library/dev-doc-ui.d.ts +2 -1
  71. package/dist/client/blocks/library/dev-doc-ui.d.ts.map +1 -1
  72. package/dist/client/blocks/library/dev-doc-ui.js +2 -1
  73. package/dist/client/blocks/library/dev-doc-ui.js.map +1 -1
  74. package/dist/client/blocks/library/html.d.ts +1 -1
  75. package/dist/client/blocks/library/html.d.ts.map +1 -1
  76. package/dist/client/blocks/library/html.js +34 -4
  77. package/dist/client/blocks/library/html.js.map +1 -1
  78. package/dist/client/blocks/library/json-explorer.config.d.ts +3 -1
  79. package/dist/client/blocks/library/json-explorer.config.d.ts.map +1 -1
  80. package/dist/client/blocks/library/json-explorer.config.js +30 -1
  81. package/dist/client/blocks/library/json-explorer.config.js.map +1 -1
  82. package/dist/client/blocks/library/server-specs.d.ts.map +1 -1
  83. package/dist/client/blocks/library/server-specs.js +13 -3
  84. package/dist/client/blocks/library/server-specs.js.map +1 -1
  85. package/dist/client/blocks/library/specs.d.ts +4 -4
  86. package/dist/client/blocks/library/specs.d.ts.map +1 -1
  87. package/dist/client/blocks/library/specs.js +21 -16
  88. package/dist/client/blocks/library/specs.js.map +1 -1
  89. package/dist/client/blocks/library/table.config.d.ts +3 -0
  90. package/dist/client/blocks/library/table.config.d.ts.map +1 -1
  91. package/dist/client/blocks/library/table.config.js +13 -1
  92. package/dist/client/blocks/library/table.config.js.map +1 -1
  93. package/dist/client/blocks/library/table.d.ts.map +1 -1
  94. package/dist/client/blocks/library/table.js +90 -9
  95. package/dist/client/blocks/library/table.js.map +1 -1
  96. package/dist/client/blocks/library/tabs.config.d.ts +16 -8
  97. package/dist/client/blocks/library/tabs.config.d.ts.map +1 -1
  98. package/dist/client/blocks/library/tabs.config.js +10 -4
  99. package/dist/client/blocks/library/tabs.config.js.map +1 -1
  100. package/dist/client/blocks/library/tabs.d.ts.map +1 -1
  101. package/dist/client/blocks/library/tabs.js +146 -21
  102. package/dist/client/blocks/library/tabs.js.map +1 -1
  103. package/dist/client/blocks/server.d.ts +2 -1
  104. package/dist/client/blocks/server.d.ts.map +1 -1
  105. package/dist/client/blocks/server.js +1 -0
  106. package/dist/client/blocks/server.js.map +1 -1
  107. package/dist/client/blocks/types.d.ts +99 -9
  108. package/dist/client/blocks/types.d.ts.map +1 -1
  109. package/dist/client/blocks/types.js.map +1 -1
  110. package/dist/client/index.d.ts +1 -1
  111. package/dist/client/index.d.ts.map +1 -1
  112. package/dist/client/index.js +2 -2
  113. package/dist/client/index.js.map +1 -1
  114. package/dist/client/rich-markdown-editor/BubbleToolbar.d.ts.map +1 -1
  115. package/dist/client/rich-markdown-editor/BubbleToolbar.js +13 -3
  116. package/dist/client/rich-markdown-editor/BubbleToolbar.js.map +1 -1
  117. package/dist/client/rich-markdown-editor/DragHandle.d.ts +49 -4
  118. package/dist/client/rich-markdown-editor/DragHandle.d.ts.map +1 -1
  119. package/dist/client/rich-markdown-editor/DragHandle.js +656 -88
  120. package/dist/client/rich-markdown-editor/DragHandle.js.map +1 -1
  121. package/dist/client/rich-markdown-editor/RegistryBlockNode.d.ts +10 -1
  122. package/dist/client/rich-markdown-editor/RegistryBlockNode.d.ts.map +1 -1
  123. package/dist/client/rich-markdown-editor/RegistryBlockNode.js +180 -15
  124. package/dist/client/rich-markdown-editor/RegistryBlockNode.js.map +1 -1
  125. package/dist/client/rich-markdown-editor/SharedRichEditor.d.ts +2 -1
  126. package/dist/client/rich-markdown-editor/SharedRichEditor.d.ts.map +1 -1
  127. package/dist/client/rich-markdown-editor/SharedRichEditor.js +3 -1
  128. package/dist/client/rich-markdown-editor/SharedRichEditor.js.map +1 -1
  129. package/dist/client/rich-markdown-editor/SlashCommandMenu.d.ts +5 -0
  130. package/dist/client/rich-markdown-editor/SlashCommandMenu.d.ts.map +1 -1
  131. package/dist/client/rich-markdown-editor/SlashCommandMenu.js +33 -5
  132. package/dist/client/rich-markdown-editor/SlashCommandMenu.js.map +1 -1
  133. package/dist/client/rich-markdown-editor/index.d.ts +3 -3
  134. package/dist/client/rich-markdown-editor/index.d.ts.map +1 -1
  135. package/dist/client/rich-markdown-editor/index.js +2 -2
  136. package/dist/client/rich-markdown-editor/index.js.map +1 -1
  137. package/dist/client/rich-markdown-editor/registrySlashCommands.d.ts +14 -0
  138. package/dist/client/rich-markdown-editor/registrySlashCommands.d.ts.map +1 -1
  139. package/dist/client/rich-markdown-editor/registrySlashCommands.js +38 -0
  140. package/dist/client/rich-markdown-editor/registrySlashCommands.js.map +1 -1
  141. package/dist/client/rich-markdown-editor/useCollabReconcile.d.ts +1 -0
  142. package/dist/client/rich-markdown-editor/useCollabReconcile.d.ts.map +1 -1
  143. package/dist/client/rich-markdown-editor/useCollabReconcile.js +4 -0
  144. package/dist/client/rich-markdown-editor/useCollabReconcile.js.map +1 -1
  145. package/dist/client/settings/SettingsPanel.d.ts.map +1 -1
  146. package/dist/client/settings/SettingsPanel.js +11 -19
  147. package/dist/client/settings/SettingsPanel.js.map +1 -1
  148. package/dist/client/use-chat-models.d.ts.map +1 -1
  149. package/dist/client/use-chat-models.js +2 -5
  150. package/dist/client/use-chat-models.js.map +1 -1
  151. package/dist/db/client.d.ts.map +1 -1
  152. package/dist/db/client.js +17 -1
  153. package/dist/db/client.js.map +1 -1
  154. package/dist/deploy/build.d.ts.map +1 -1
  155. package/dist/deploy/build.js +2 -1
  156. package/dist/deploy/build.js.map +1 -1
  157. package/dist/deploy/route-discovery.d.ts +29 -0
  158. package/dist/deploy/route-discovery.d.ts.map +1 -1
  159. package/dist/deploy/route-discovery.js +158 -11
  160. package/dist/deploy/route-discovery.js.map +1 -1
  161. package/dist/server/auth.d.ts +2 -0
  162. package/dist/server/auth.d.ts.map +1 -1
  163. package/dist/server/auth.js +9 -0
  164. package/dist/server/auth.js.map +1 -1
  165. package/dist/sharing/access.d.ts +4 -2
  166. package/dist/sharing/access.d.ts.map +1 -1
  167. package/dist/sharing/access.js +8 -3
  168. package/dist/sharing/access.js.map +1 -1
  169. package/dist/sharing/actions/set-resource-visibility.d.ts.map +1 -1
  170. package/dist/sharing/actions/set-resource-visibility.js +2 -3
  171. package/dist/sharing/actions/set-resource-visibility.js.map +1 -1
  172. package/dist/sharing/registry.d.ts +13 -0
  173. package/dist/sharing/registry.d.ts.map +1 -1
  174. package/dist/sharing/registry.js.map +1 -1
  175. package/dist/styles/rich-markdown-editor.css +15 -0
  176. package/dist/templates/default/.agents/skills/actions/SKILL.md +96 -11
  177. package/dist/templates/default/.agents/skills/adding-a-feature/SKILL.md +126 -26
  178. package/dist/templates/default/.agents/skills/capture-learnings/SKILL.md +56 -30
  179. package/dist/templates/default/.agents/skills/create-skill/SKILL.md +28 -0
  180. package/dist/templates/default/.agents/skills/delegate-to-agent/SKILL.md +75 -5
  181. package/dist/templates/default/.agents/skills/frontend-design/SKILL.md +17 -0
  182. package/dist/templates/default/.agents/skills/real-time-collab/SKILL.md +99 -124
  183. package/dist/templates/default/.agents/skills/real-time-sync/SKILL.md +43 -10
  184. package/dist/templates/default/.agents/skills/security/SKILL.md +162 -144
  185. package/dist/templates/default/.agents/skills/self-modifying-code/SKILL.md +5 -3
  186. package/dist/templates/default/.agents/skills/shadcn-ui/SKILL.md +15 -0
  187. package/dist/templates/default/.agents/skills/storing-data/SKILL.md +116 -83
  188. package/dist/templates/default/DEVELOPING.md +10 -13
  189. package/dist/templates/workspace-core/.agents/skills/client-methods/references/legacy-client-fetch-audit-2026-06-03.md +9 -0
  190. package/dist/templates/workspace-core/.agents/skills/writing-agent-instructions/SKILL.md +27 -0
  191. package/docs/content/template-plan.md +5 -3
  192. package/docs/content/visual-plans.md +5 -2
  193. package/package.json +16 -1
  194. package/src/templates/default/.agents/skills/actions/SKILL.md +96 -11
  195. package/src/templates/default/.agents/skills/adding-a-feature/SKILL.md +126 -26
  196. package/src/templates/default/.agents/skills/capture-learnings/SKILL.md +56 -30
  197. package/src/templates/default/.agents/skills/create-skill/SKILL.md +28 -0
  198. package/src/templates/default/.agents/skills/delegate-to-agent/SKILL.md +75 -5
  199. package/src/templates/default/.agents/skills/frontend-design/SKILL.md +17 -0
  200. package/src/templates/default/.agents/skills/real-time-collab/SKILL.md +99 -124
  201. package/src/templates/default/.agents/skills/real-time-sync/SKILL.md +43 -10
  202. package/src/templates/default/.agents/skills/security/SKILL.md +162 -144
  203. package/src/templates/default/.agents/skills/self-modifying-code/SKILL.md +5 -3
  204. package/src/templates/default/.agents/skills/shadcn-ui/SKILL.md +15 -0
  205. package/src/templates/default/.agents/skills/storing-data/SKILL.md +116 -83
  206. package/src/templates/default/DEVELOPING.md +10 -13
  207. package/src/templates/workspace-core/.agents/skills/client-methods/references/legacy-client-fetch-audit-2026-06-03.md +9 -0
  208. package/src/templates/workspace-core/.agents/skills/writing-agent-instructions/SKILL.md +27 -0
@@ -1,128 +1,161 @@
1
1
  ---
2
2
  name: storing-data
3
3
  description: >-
4
- How and where to store application data. Use when adding new data models,
5
- deciding between settings vs Drizzle tables, reading/writing app config,
6
- or working with application state.
4
+ How to store application data in agent-native apps. All data lives in SQL.
5
+ Use when adding data models, deciding where to store data, or reading/writing
6
+ application data.
7
+ metadata:
8
+ internal: true
7
9
  ---
8
10
 
9
- # Storing Data
11
+ # Storing Data — SQL is the Source of Truth
10
12
 
11
- ## Where Data Goes
13
+ ## Rule
12
14
 
13
- All data lives in one SQLite database (`data/app.db`). In production, set `DATABASE_URL` to point to Turso, Neon, Supabase, or D1 same code, no changes needed.
15
+ All application data lives in **SQL** (SQLite locally, persistent database in production). The agent and UI share the same database. Do not store durable app data in the filesystem.
14
16
 
15
- There are three storage layers, each for a different kind of data:
17
+ ## How It Works
16
18
 
17
- ### 1. Settings app configuration
19
+ Agent-native apps use Drizzle ORM over the configured SQL backend. Local development works out of the box with a SQLite file at `data/app.db`; production and shared preview deploys need a persistent `DATABASE_URL` because container/serverless filesystems can reset. The code should behave the same across backends, but the local SQLite file is not durable once deployed.
18
20
 
19
- Key-value store for persistent non-secret config that the user or agent can change. Theme, preferences, integration settings, availability schedules.
21
+ For app code, use Drizzle's schema/query DSL by default. Raw SQL is an escape hatch for additive migrations, health checks, or one-off maintenance, not the normal way to build features.
20
22
 
21
- ```ts
22
- import { getSetting, putSetting } from "@agent-native/core/settings";
23
+ ### Core SQL Stores (auto-created, available in all templates)
23
24
 
24
- // Read (returns null if not set)
25
- const prefs = await getSetting("user-preferences");
25
+ | Store | Purpose | Access |
26
+ | ------------------- | ---------------------------------------------------- | ------------------------------------------ |
27
+ | `application_state` | Ephemeral UI state (compose windows, navigation) | `readAppState()` / `writeAppState()` |
28
+ | `settings` | Persistent KV config (preferences, app settings) | `getSetting()` / `putSetting()` |
29
+ | `oauth_tokens` | OAuth credentials | `@agent-native/core/oauth-tokens` |
30
+ | `sessions` | Auth sessions | `@agent-native/core/server` |
26
31
 
27
- // Write (creates or replaces)
28
- await putSetting("user-preferences", { theme: "dark", density: "comfortable" });
29
- ```
32
+ ### Domain Data (per-template)
33
+
34
+ Define schema with the framework Drizzle helpers in `server/db/schema.ts`. Get a database instance with `const db = getDb()` from `server/db/index.ts`. All queries are async.
30
35
 
31
- From scripts:
32
36
  ```ts
33
- import { readSetting, writeSetting } from "@agent-native/core/settings";
34
- const prefs = await readSetting("user-preferences");
35
- ```
37
+ import { eq } from "drizzle-orm";
38
+ import { table, text, integer, now } from "@agent-native/core/db/schema";
39
+
40
+ export const tasks = table("tasks", {
41
+ id: text("id").primaryKey(),
42
+ title: text("title").notNull(),
43
+ completed: integer("completed", { mode: "boolean" })
44
+ .notNull()
45
+ .default(false),
46
+ createdAt: text("created_at").notNull().default(now()),
47
+ });
36
48
 
37
- SSE: writes automatically notify the UI via `{ source: "settings", type: "change", key }`.
49
+ const rows = await db.select().from(tasks).where(eq(tasks.id, taskId));
50
+ ```
38
51
 
39
- ### 2. Application State ephemeral UI state
52
+ Never import `sqliteTable` / `pgTable` or column helpers from `drizzle-orm/sqlite-core` or `drizzle-orm/pg-core` in app templates. Use `@agent-native/core/db/schema` so the same schema can run against SQLite, Postgres, libSQL/Turso, D1, and other supported backends.
40
53
 
41
- For state the agent and UI share in real-time: what the user is looking at, compose drafts, navigation commands. Scoped by session — cleared between sessions.
54
+ | Template | Tables |
55
+ | ------------ | --------------------------------------------- |
56
+ | **Mail** | emails, labels (+ Gmail API when connected) |
57
+ | **Calendar** | events, bookings |
58
+ | **Forms** | forms, responses |
59
+ | **Content** | documents |
60
+ | **Slides** | decks (JSON stored in SQL) |
61
+ | **Videos** | compositions in registry + localStorage |
42
62
 
43
- ```ts
44
- import { readAppState, writeAppState, deleteAppState, listAppState } from "@agent-native/core/application-state";
63
+ ### Agent Access
45
64
 
46
- // Write state (UI updates instantly via SSE)
47
- await writeAppState("navigate", { view: "inbox", threadId: "t-123" });
65
+ The agent uses app-specific actions to read/write the database. Core DB scripts are for inspection and maintenance, not for implementing normal product behavior:
48
66
 
49
- // Read state
50
- const nav = await readAppState("navigation");
67
+ - `pnpm action db-schema` — Show all tables, columns, types
68
+ - `pnpm action db-query --sql "SELECT * FROM forms"` — Run SELECT queries
69
+ - `pnpm action db-exec --sql "UPDATE ..."` — Last-resort ad-hoc maintenance for short columns, multi-column writes, or computed updates when no domain action exists. For several related writes, prefer `--statements '[{"sql":"...","args":[...]}]'` so they run sequentially in one transaction. Schema changes are blocked; use reviewed additive migrations/startup code instead.
70
+ - `pnpm action db-patch --table <t> --column <c> --where "<clause>" --find "<old>" --replace "<new>"` — **Surgical search/replace on a large text column.** Sends the diff instead of re-transmitting the whole value, so it's dramatically more token-efficient than `db-exec UPDATE` when editing multi-kilobyte documents, slide HTML, dashboard/form JSON, etc. Targets exactly one row per call — narrow `--where` by primary key. Supports `--edits '[{find,replace},...]'` for batch edits and `--all` to replace every occurrence.
71
+ - App-specific actions for domain operations — **always prefer these over raw SQL when one exists.** They encode business rules, power the client action hooks, and for editor-backed tables (documents, slides) also push live Yjs updates to open collaborative editors. `db-patch` is the generic fallback for tables without a dedicated edit action.
51
72
 
52
- // List by prefix (e.g., all compose drafts)
53
- const drafts = await listAppState("compose-");
73
+ **For one-off maintenance, how to choose between `db-exec UPDATE` and `db-patch`:**
54
74
 
55
- // Delete (one-shot commands: UI reads, then agent or UI deletes)
56
- await deleteAppState("navigate");
57
- ```
75
+ | Scenario | Use |
76
+ | -------------------------------------------------------------- | ------------ |
77
+ | `SET status = 'published'` on one row | `db-exec` |
78
+ | `SET calories = calories + 50` | `db-exec` |
79
+ | Updating several columns at once | `db-exec` |
80
+ | Inserting/updating several rows as one logical operation | `db-exec --statements` |
81
+ | Fixing a typo in a 50KB markdown document's `content` column | `db-patch` |
82
+ | Changing a single key in a dashboard's JSON blob | `db-patch` |
83
+ | Tweaking one paragraph of slide HTML stored in `decks.data` | `db-patch` |
84
+ | Any edit where you'd otherwise re-send thousands of characters | `db-patch` |
58
85
 
59
- SSE: writes automatically notify the UI via `{ source: "app-state", type: "change", key }`.
86
+ All of these honor the per-user / per-org data scoping you can't read or write rows outside the current user's data, regardless of which tool you choose.
60
87
 
61
- ### 3. Drizzle Tables — structured domain data
88
+ ### Frontend Access
62
89
 
63
- For data with schemas, relationships, and queries: forms, bookings, emails, compositions. Define tables in `server/db/schema.ts` using Drizzle ORM.
90
+ The frontend calls actions using React Query hooks from the client API. The framework owns the HTTP transport behind these hooks, so components should not call action routes with raw `fetch`.
64
91
 
65
92
  ```ts
66
- import { table, text, integer } from "@agent-native/core/db/schema";
93
+ import { useActionQuery, useActionMutation } from "@agent-native/core/client";
67
94
 
68
- export const bookings = table("bookings", {
69
- id: text("id").primaryKey(),
70
- name: text("name").notNull(),
71
- email: text("email").notNull(),
72
- startTime: integer("start_time").notNull(),
73
- endTime: integer("end_time").notNull(),
74
- });
95
+ // Read data
96
+ const { data } = useActionQuery("list-meals", { date: "2025-01-01" });
97
+
98
+ // Write data
99
+ const { mutate } = useActionMutation("log-meal");
75
100
  ```
76
101
 
77
- Query via `getDb()` singleton from `server/db/index.ts`.
102
+ Actions are the **preferred way** for the frontend to access data. You rarely need custom `/api/` routes — only for file uploads, streaming, webhooks, or OAuth callbacks.
78
103
 
79
- ### 4. OAuth Tokens — credentials
104
+ ### Production / Cloud Deployment
80
105
 
81
- For OAuth tokens acquired at runtime (Google, etc.). Never store these in settings use the dedicated store.
106
+ Local SQLite works out of the box for development. To deploy to production or any environment where data must survive restarts:
82
107
 
83
- ```ts
84
- import { saveOAuthTokens, getOAuthTokens, listOAuthAccounts } from "@agent-native/core/oauth-tokens";
108
+ 1. Set `DATABASE_URL` to a persistent SQL database.
109
+ 2. Set `DATABASE_AUTH_TOKEN` only when the provider requires a separate token, such as Turso/libSQL.
110
+ 3. No code changes should be needed when the schema and queries stay portable.
85
111
 
86
- await saveOAuthTokens("google", "user@gmail.com", { access_token: "...", refresh_token: "..." });
87
- const tokens = await getOAuthTokens("google", "user@gmail.com");
88
- const accounts = await listOAuthAccounts("google");
89
- ```
112
+ Turso is one valid option, not the required option. Common choices include Neon or Supabase Postgres, Turso/libSQL, plain Postgres, durable SQLite, Cloudflare D1 bindings, and managed platform SQL environments when available.
113
+
114
+ ### Real-time Sync
115
+
116
+ Polling streams database changes to the UI. When the agent writes to the database via scripts, the UI updates automatically via `useDbSync()` which invalidates React Query caches.
117
+
118
+ ## Do
119
+
120
+ - Use Drizzle ORM for structured domain data (forms, bookings, documents)
121
+ - Use Drizzle query builder methods (`select`, `insert`, `update`, `delete`) and portable operators from `drizzle-orm` (`eq`, `and`, `or`, `inArray`, `desc`, etc.) for app reads/writes
122
+ - Use framework schema helpers from `@agent-native/core/db/schema`, not dialect-specific Drizzle imports
123
+ - Use the `settings` store for app configuration and user preferences
124
+ - Use `application-state` for ephemeral UI state that the agent and UI share
125
+ - Use `oauth-tokens` for OAuth credentials
126
+ - Use core DB scripts (`db-schema`, `db-query`, `db-exec`, `db-patch`) for ad-hoc database operations
127
+ - Use `db-exec --statements` instead of several separate `db-exec` calls for related writes; it is faster and rolls back the whole batch if one statement fails
128
+ - Reach for `db-patch` instead of `db-exec UPDATE` whenever you're making a small change to a large text/JSON column — it's much cheaper on tokens
90
129
 
91
- ### 5. Secrets / Credentials — encrypted values
130
+ ## Don't
92
131
 
93
- For API keys, service tokens, webhook secrets, and user/org/workspace
94
- credentials. Register user-facing secrets with the secrets registry and read
95
- them server-side with `readAppSecret`, or use `saveCredential` /
96
- `resolveCredential` for scoped credential lookup. Never store these values in
97
- settings, application state, source code, docs, examples, logs, or action
98
- responses.
132
+ - Don't store structured app data as JSON files
133
+ - Don't store app state in localStorage, sessionStorage, or cookies (except for UI-only preferences like sidebar width)
134
+ - Don't keep state only in memory (server variables, global stores)
135
+ - Don't use Redis or any external state store for app data
136
+ - Don't implement product features with raw SQL or `getDbExec()` when Drizzle can express the query
137
+ - Don't write SQLite-only or Postgres-only SQL in app code
138
+ - Don't interpolate user input directly into SQL queries — use Drizzle ORM's query builder
99
139
 
100
- ## Which Layer to Use
140
+ ## Security
101
141
 
102
- | Data | Layer | Why |
103
- |------|-------|-----|
104
- | User preferences, theme, config | Settings | Persistent KV, SSE notifications, simple read/write |
105
- | What the user sees on screen | Application State | Ephemeral, real-time sync, agent ↔ UI bridge |
106
- | Compose drafts, wizard steps | Application State | Temporary, deleted when done |
107
- | Domain records (forms, bookings) | Drizzle table | Needs schema, queries, relationships |
108
- | API keys, service tokens, webhook secrets | Secrets / credentials | Encrypted and scoped; never client-readable |
109
- | OAuth refresh tokens | OAuth Tokens | Secure, per-provider, per-account |
142
+ - **SQL injection** Use Drizzle ORM's query builder, never raw string interpolation for SQL queries
143
+ - **Validate before writing** — Check data shape before writing, especially for user-submitted data
110
144
 
111
- ## Environment Variables
145
+ ## Application State and Context Awareness
112
146
 
113
- Infrastructure config stays in `.env`these differ per deployment:
147
+ When storing app-state, include **navigation state** the agent needs to know what the user is looking at. The `application_state` table holds ephemeral UI state that both the agent and UI share. Key patterns:
114
148
 
115
- - `DATABASE_URL`database connection (default: `file:./data/app.db`)
116
- - `DATABASE_AUTH_TOKEN`for remote databases
117
- - `GOOGLE_CLIENT_ID`, `GOOGLE_CLIENT_SECRET` — OAuth app credentials
118
- - `ACCESS_TOKEN` — production auth token
149
+ - **`navigation` key** the UI writes current view and selection on every route change. The agent reads this before acting.
150
+ - **`navigate` key** the agent writes one-shot commands to navigate the UI. The UI processes and deletes them.
151
+ - **Domain-specific keys** (e.g., `compose-{id}`)bidirectional state for features like email drafts.
119
152
 
120
- Everything else (user settings, app state, domain data) goes in SQL through the
121
- appropriate store. User/org/workspace credential values go in the encrypted
122
- secrets/credential stores, not plain settings rows.
153
+ When adding a new data model or feature, also consider what navigation and selection state needs to be exposed via application-state. See the **context-awareness** skill for the full pattern.
123
154
 
124
- ## Security Rules
155
+ ## Related Skills
125
156
 
126
- - **Never store API keys or secrets in Settings or Application State** — use the secrets registry / vault or `saveCredential` / `resolveCredential` for API keys and service tokens, deploy env vars only for deploy-level secrets, and `oauth_tokens` for OAuth credentials. Settings and application state are readable by the client.
127
- - **Every Drizzle table with user data must have `owner_email`** the framework auto-scopes queries in production so users only see their own data. Run `pnpm action db-check-scoping` to verify. See the `security` skill for the full model.
128
- - **Never return secrets in action responses** — action responses may be visible in the agent chat or sent to the client. Keep credentials server-side only.
157
+ - **context-awareness** — How to expose navigation and selection state via application-state
158
+ - **real-time-sync**Set up polling so the UI updates when the database changes
159
+ - **actions** — Create actions with `defineAction` to query the database
160
+ - **client-methods** — Keep route details behind named client helpers/hooks
161
+ - **self-modifying-code** — The agent can also modify the app's source code
@@ -6,7 +6,7 @@ This guide is for development-mode agents editing this app's source code. For ap
6
6
 
7
7
  **Client-side-first rendering:** This app uses React Router v7 framework mode with `ssr: true`, but all app content renders **client-side only**. The server renders only the HTML shell (meta tags, styles, scripts) plus a loading spinner. This is enforced by the `ClientOnly` wrapper in `root.tsx` — never remove it. Browser APIs (`window`, `localStorage`, `new Date()`) are safe to use anywhere in app code because components never run on the server.
8
8
 
9
- **Do NOT fetch data server-side** in route loaders. The standard pattern is: server renders a spinner, client hydrates, React Query hooks fetch from `/api/*`.
9
+ **Do NOT fetch data server-side** in route loaders unless the page genuinely needs SEO/OG content. The standard pattern is: SSR renders the shell, client hydrates, and React reads/writes normal app data through actions with `useActionQuery` / `useActionMutation`.
10
10
 
11
11
  ## Adding a Page
12
12
 
@@ -30,7 +30,7 @@ In a workspace, this app can be mounted under `/<app-id>`. React Router already
30
30
  | `app/routes/review.tsx` | `/review` | `/<app-id>/review` |
31
31
  | `app/routes/$id.tsx` | `/:id` | `/<app-id>/:id` |
32
32
 
33
- Use `<Link to="/review">` and `navigate("/review")` inside this app. Do not prefix React Router paths with `/<app-id>` or the URL can double-prefix, e.g. `/<app-id>/<app-id>/review`. Use `appPath()` for raw `href`s/static assets, `appApiPath()` for `/api/*`, and `agentNativePath()` for `/_agent-native/*`.
33
+ Use `<Link to="/review">` and `navigate("/review")` inside this app. Do not prefix React Router paths with `/<app-id>` or the URL can double-prefix, e.g. `/<app-id>/<app-id>/review`. Use `appPath()` for raw `href`s/static assets, `agentNativePath()` for `/_agent-native/*`, and `appApiPath()` only for legitimate route-only `/api/*` endpoints.
34
34
 
35
35
  Each route file exports a default component and optional `meta()`:
36
36
 
@@ -46,17 +46,15 @@ export default function MyPageRoute() {
46
46
  }
47
47
  ```
48
48
 
49
- ## Adding an API Route
49
+ ## Adding App Data
50
50
 
51
- Create a file in `server/routes/api/`. The filename determines the URL path and HTTP method:
51
+ Normal app data starts as an action, not a custom route. Add `actions/<verb>-<resource>.ts` with `defineAction`, mark reads with `http: { method: "GET" }`, and call reads/writes from React with `useActionQuery` / `useActionMutation` from `@agent-native/core/client`. This keeps the UI and agent on one contract and lets mutating actions refresh action-backed queries automatically.
52
52
 
53
- ```
54
- server/routes/api/items/index.get.ts → GET /api/items
55
- server/routes/api/items/[id].get.ts → GET /api/items/:id
56
- server/routes/api/items/[id].patch.ts → PATCH /api/items/:id
57
- ```
53
+ ## Adding a Route-Only Endpoint
54
+
55
+ Use `server/routes/api/` only for protocols that cannot be modeled as JSON actions: multipart uploads, streaming/SSE/WebSocket, webhooks, OAuth callbacks/redirects, public SEO/OG endpoints, or binary/static asset serving. Do not add `/api/*` routes for normal CRUD, data queries, or pass-through wrappers around actions; the action endpoint already exists at `/_agent-native/actions/:name`.
58
56
 
59
- Each file exports a default `defineEventHandler`.
57
+ Each route-only endpoint still exports a default `defineEventHandler`, but keep shared app logic in actions or server libraries so agent and UI behavior do not fork.
60
58
 
61
59
  ## Server Plugins
62
60
 
@@ -84,10 +82,9 @@ export default defineNitroPlugin(async (nitroApp) => {
84
82
  | Agent chat context state helpers | Optional advanced helpers for two-way sync with staged context chips |
85
83
  | `agentChat` | Send messages to agent from scripts (server-side) |
86
84
 
87
- ## Adding a Script
85
+ ## Adding an Action
88
86
 
89
- Create `actions/my-script.ts` exporting `default async function(args: string[])`.
90
- Run with: `pnpm action my-script --arg value`
87
+ Create `actions/<verb>-<resource>.ts` with `defineAction`. Run with `pnpm action <name> --id value`; React callers should use `useActionQuery` for GET actions and `useActionMutation` for mutating actions, not a matching `/api/*` wrapper.
91
88
 
92
89
  ## Sending to Agent Chat
93
90
 
@@ -7,6 +7,11 @@ contracts; some need new actions or helper modules first.
7
7
 
8
8
  ## Highest Priority
9
9
 
10
+ - 2026-06-07 follow-up: the same high-priority route-first clusters are still
11
+ present. The biggest migrations remain Analytics, Calendar, Mail, Slides, and
12
+ Content. Do not copy these patterns into new work; when editing the relevant
13
+ area, add or reuse actions first, then call them with `useActionQuery`,
14
+ `useActionMutation`, or `callAction`.
10
15
  - `templates/analytics/app/pages/analyses/AnalysesList.tsx`,
11
16
  `templates/analytics/app/pages/analyses/AnalysisDetail.tsx`,
12
17
  `templates/analytics/app/components/layout/Sidebar.tsx`, and
@@ -43,6 +48,10 @@ contracts; some need new actions or helper modules first.
43
48
  - Content comments and versions are partially migrated. Add missing actions such
44
49
  as `resolve-comment`, `delete-comment`, `list-document-versions`, and
45
50
  `restore-document-version`.
51
+ - Plans version history is the model to copy for new history/rollback work:
52
+ `list-plan-versions`, `get-plan-version`, and `restore-plan-version` are
53
+ action-native, and the UI calls them through action hooks. Do not copy
54
+ Content's legacy document-version `/api/*` helpers into new version panels.
46
55
 
47
56
  ## Acceptable Exceptions
48
57
 
@@ -74,6 +74,33 @@ Keep one canonical instructions file: `AGENTS.md`. If a client expects
74
74
  hand-maintained files drift, and the agent ends up with contradictory rules.
75
75
  One source of truth, linked where needed.
76
76
 
77
+ ## Keep generated guidance in sync
78
+
79
+ Framework guidance is authored once in this repo and copied outward. Treat
80
+ `.agents/skills/` as the canonical source for shared skills. Generated
81
+ workspace skills in `packages/core/src/templates/workspace-core/.agents/skills/`
82
+ and first-party template copies of shared skills must stay byte-for-byte in
83
+ sync; run `pnpm sync:workspace-skills` after editing a shared skill, and
84
+ `pnpm guard:workspace-skills` before calling the guidance done.
85
+
86
+ Generated app and workspace instructions must teach the same action-first data
87
+ contract:
88
+
89
+ - Normal app data goes through `defineAction` files in `actions/`.
90
+ - React calls actions with `useActionQuery`, `useActionMutation`, or
91
+ `callAction`; route paths are a transport detail hidden behind helpers.
92
+ - Custom `/api/*` routes are only for route-shaped protocols such as uploads,
93
+ streaming, webhooks, OAuth callbacks, public SEO/OG endpoints, or binary
94
+ assets.
95
+ - Do not create pass-through routes whose main job is to call, repackage, or
96
+ re-export an action.
97
+
98
+ When documenting version history, restore, or audit trails, use actions for
99
+ full restorable snapshots (`list-<resource>-versions`,
100
+ `get-<resource>-version`, `restore-<resource>-version`). Do not copy legacy
101
+ raw-route version panels, such as document-version `/api/*` helpers, into new
102
+ features. The Plans version-history pattern is the preferred model.
103
+
77
104
  ## SKILL.md frontmatter must say what AND when
78
105
 
79
106
  The `description` is the only thing the agent sees when deciding whether to read