@agent-native/core 0.39.0 → 0.39.2

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 (61) hide show
  1. package/dist/cli/index.js +1 -1
  2. package/dist/cli/index.js.map +1 -1
  3. package/dist/cli/skills.d.ts +5 -5
  4. package/dist/cli/skills.d.ts.map +1 -1
  5. package/dist/cli/skills.js +458 -615
  6. package/dist/cli/skills.js.map +1 -1
  7. package/dist/client/MultiTabAssistantChat.d.ts.map +1 -1
  8. package/dist/client/MultiTabAssistantChat.js +2 -5
  9. package/dist/client/MultiTabAssistantChat.js.map +1 -1
  10. package/dist/client/NewWorkspaceAppFlow.js +1 -1
  11. package/dist/client/NewWorkspaceAppFlow.js.map +1 -1
  12. package/dist/client/settings/SettingsPanel.d.ts.map +1 -1
  13. package/dist/client/settings/SettingsPanel.js +11 -19
  14. package/dist/client/settings/SettingsPanel.js.map +1 -1
  15. package/dist/client/use-chat-models.d.ts.map +1 -1
  16. package/dist/client/use-chat-models.js +2 -5
  17. package/dist/client/use-chat-models.js.map +1 -1
  18. package/dist/deploy/build.d.ts.map +1 -1
  19. package/dist/deploy/build.js +2 -1
  20. package/dist/deploy/build.js.map +1 -1
  21. package/dist/deploy/route-discovery.d.ts +29 -0
  22. package/dist/deploy/route-discovery.d.ts.map +1 -1
  23. package/dist/deploy/route-discovery.js +158 -11
  24. package/dist/deploy/route-discovery.js.map +1 -1
  25. package/dist/server/auth.d.ts +2 -0
  26. package/dist/server/auth.d.ts.map +1 -1
  27. package/dist/server/auth.js +9 -0
  28. package/dist/server/auth.js.map +1 -1
  29. package/dist/templates/default/.agents/skills/actions/SKILL.md +96 -11
  30. package/dist/templates/default/.agents/skills/adding-a-feature/SKILL.md +126 -26
  31. package/dist/templates/default/.agents/skills/capture-learnings/SKILL.md +56 -30
  32. package/dist/templates/default/.agents/skills/create-skill/SKILL.md +28 -0
  33. package/dist/templates/default/.agents/skills/delegate-to-agent/SKILL.md +75 -5
  34. package/dist/templates/default/.agents/skills/frontend-design/SKILL.md +17 -0
  35. package/dist/templates/default/.agents/skills/real-time-collab/SKILL.md +99 -124
  36. package/dist/templates/default/.agents/skills/real-time-sync/SKILL.md +43 -10
  37. package/dist/templates/default/.agents/skills/security/SKILL.md +162 -144
  38. package/dist/templates/default/.agents/skills/self-modifying-code/SKILL.md +5 -3
  39. package/dist/templates/default/.agents/skills/shadcn-ui/SKILL.md +15 -0
  40. package/dist/templates/default/.agents/skills/storing-data/SKILL.md +116 -83
  41. package/dist/templates/default/DEVELOPING.md +10 -13
  42. package/dist/templates/workspace-core/.agents/skills/client-methods/references/legacy-client-fetch-audit-2026-06-03.md +9 -0
  43. package/dist/templates/workspace-core/.agents/skills/writing-agent-instructions/SKILL.md +27 -0
  44. package/docs/content/template-plan.md +5 -3
  45. package/docs/content/visual-plans.md +5 -2
  46. package/package.json +1 -1
  47. package/src/templates/default/.agents/skills/actions/SKILL.md +96 -11
  48. package/src/templates/default/.agents/skills/adding-a-feature/SKILL.md +126 -26
  49. package/src/templates/default/.agents/skills/capture-learnings/SKILL.md +56 -30
  50. package/src/templates/default/.agents/skills/create-skill/SKILL.md +28 -0
  51. package/src/templates/default/.agents/skills/delegate-to-agent/SKILL.md +75 -5
  52. package/src/templates/default/.agents/skills/frontend-design/SKILL.md +17 -0
  53. package/src/templates/default/.agents/skills/real-time-collab/SKILL.md +99 -124
  54. package/src/templates/default/.agents/skills/real-time-sync/SKILL.md +43 -10
  55. package/src/templates/default/.agents/skills/security/SKILL.md +162 -144
  56. package/src/templates/default/.agents/skills/self-modifying-code/SKILL.md +5 -3
  57. package/src/templates/default/.agents/skills/shadcn-ui/SKILL.md +15 -0
  58. package/src/templates/default/.agents/skills/storing-data/SKILL.md +116 -83
  59. package/src/templates/default/DEVELOPING.md +10 -13
  60. package/src/templates/workspace-core/.agents/skills/client-methods/references/legacy-client-fetch-audit-2026-06-03.md +9 -0
  61. package/src/templates/workspace-core/.agents/skills/writing-agent-instructions/SKILL.md +27 -0
@@ -2,20 +2,45 @@
2
2
  name: actions
3
3
  description: >-
4
4
  How to create and run agent actions. Actions are the single source of truth
5
- for app operations — the agent calls them as tools, the frontend calls them
6
- as HTTP endpoints. Use when creating a new action, adding an API integration,
7
- or wiring up frontend data fetching.
5
+ for app operations — the agent calls them as tools and frontend code calls
6
+ them through client hooks. Use when creating a new action, adding an API
7
+ integration, or wiring up frontend data fetching.
8
+ metadata:
9
+ internal: true
8
10
  ---
9
11
 
10
12
  # Agent Actions
11
13
 
12
14
  ## Rule
13
15
 
14
- Actions in `actions/` are the **single source of truth** for app operations. The agent calls them as tools, and the framework auto-exposes them as HTTP endpoints at `/_agent-native/actions/:name`. The frontend calls those endpoints using React Query hooks. No duplicate `/api/` routes needed.
16
+ Actions in `actions/` are the **single source of truth** for app operations. The agent calls them as tools, and the frontend calls them through `useActionQuery` / `useActionMutation`. The framework owns the HTTP transport behind those hooks. No duplicate `/api/` routes needed.
17
+
18
+ Before creating any custom REST/API route for app data, inspect `actions/` and the action table in `AGENTS.md`. If an action already exists, call it directly from the agent or with `useActionQuery` / `useActionMutation` from the UI. If the capability is missing, create or update a `defineAction`. Do not add `/api/*`, `server/routes/*`, or other pass-through endpoints whose main job is to call, repackage, or re-export an action.
15
19
 
16
20
  ## Why
17
21
 
18
- Actions give the agent callable tools with structured input/output, AND they give the frontend type-safe HTTP endpoints automatically. One implementation serves both the agent and the UI. They keep the agent's chat context clean, they're reusable, and they can be tested independently.
22
+ Actions give the agent callable tools with structured input/output, AND they give the frontend a typed client contract through hooks. One implementation serves both the agent and the UI. They keep the agent's chat context clean, they're reusable, and they can be tested independently.
23
+
24
+ ## Keep the Action Surface Small and Orthogonal
25
+
26
+ Every agent-exposed action is a tool in the model's context window. There is a real cost to each one: more tools means more for the model to read, disambiguate, and choose between, which degrades tool-selection quality. Treat the action list like an API you have to maintain — add the fewest, most orthogonal actions that cover the capability, not one per UI affordance.
27
+
28
+ - **Prefer one CRUD-style `update` over N per-field actions.** A single `update-<thing>` that takes a patch of optional fields beats `update-<thing>-name`, `update-<thing>-order`, `update-<thing>-color`, … The agent (and the UI) pass only the fields that change. Same for `create`/`delete` — one orthogonal action per resource, not one per code path.
29
+ - **Reach for a generic query / escape hatch before minting a new read action.** If the agent needs more or different data, do not add `get-<thing>-by-x`, `list-<thing>-filtered-by-y`, etc. For provider data, expose the shared `provider-api-catalog` / `provider-api-docs` / `provider-api-request` trio (see `templates/dispatch/actions/`) so the agent can hit any endpoint or filter without a new action each time. For app data in dev, the `db-query` tool already answers arbitrary read questions.
30
+ - **Hide UI-only or purely programmatic actions from the model with `agentTool: false`.** An action that only the frontend or an HTTP/cron caller needs should not spend a slot in the model's tool list. `agentTool: false` keeps it callable from `useActionMutation` / `callAction` / `/_agent-native/actions/<name>` while removing it from every agent tool surface (in-app assistant, MCP, A2A).
31
+ - **`agentTool: false` is NOT `toolCallable: false`.** They are different switches:
32
+ - `agentTool: false` → hidden from the **model entirely** (it is no longer a tool the agent can see or call). Still frontend/HTTP-callable.
33
+ - `toolCallable: false` → only blocks the **sandboxed extension ("tools") iframe bridge** (`appAction(...)`). The action stays fully visible to the model, the UI, the CLI, MCP, and A2A. Use it for high-blast-radius operations (account/org/auth changes), not for trimming the tool list.
34
+ - **Remove or hide stale actions.** When the UI stops using an action, delete it or set `agentTool: false` — do not leave it exposed to the model as dead tool weight. The advisory audit below helps you spot these.
35
+
36
+ ### Audit Script (Advisory)
37
+
38
+ `pnpm actions:audit [template ...]` (or `node scripts/audit-template-actions.mjs`) statically scans a template's `actions/` and prints two kinds of suggestions:
39
+
40
+ 1. **Likely UI-dead** — HTTP-exposed mutating actions whose name is never referenced under `app/` (candidates to delete or mark `agentTool: false`).
41
+ 2. **Likely redundant clusters** — groups like `update-foo-name` / `update-foo-order` that could collapse into one orthogonal `update-foo`.
42
+
43
+ It is **advisory only**: it always exits 0, never fails CI, and uses conservative heuristics, so expect some false positives (e.g. an action the agent calls but the UI doesn't). Use it as a prompt to review, not a gate.
19
44
 
20
45
  ## How to Create an Action
21
46
 
@@ -45,14 +70,59 @@ export default defineAction({
45
70
 
46
71
  The `schema` field accepts a Zod schema (or any Standard Schema-compatible library). It provides runtime validation with clear error messages (400 for HTTP, error result for agent), full TypeScript type inference for `run()` args, and auto-generated JSON Schema for the agent's tool definition. `zod` is a dependency of all templates.
47
72
 
73
+ When an action reads or writes app data, use Drizzle's query builder and portable operators from `drizzle-orm`. Do not use raw SQL, `getDbExec()`, or dialect-specific schema imports in normal actions unless there is a documented reason Drizzle cannot express the query.
74
+
75
+ When an action calls an external service, never hardcode API keys, bearer
76
+ tokens, webhook URLs, signing secrets, OAuth refresh tokens, private
77
+ Builder/internal data, or customer data. Read user/org/workspace credentials
78
+ from `readAppSecret`, `resolveCredential`, OAuth token helpers, or the provider
79
+ API credential adapter. Use `process.env` only for explicitly deploy-level
80
+ configuration, and keep examples to obvious placeholders.
81
+
48
82
  Tips:
49
83
  - Use `.describe()` for parameter descriptions
50
84
  - Use `.optional()` for optional params
51
- - Use `z.coerce.number()` / `z.coerce.boolean()` for params that arrive as strings from HTTP
85
+ - Use `z.coerce.number()` for numeric params that arrive as strings from HTTP.
86
+ For booleans, use an explicit string parser/helper instead of
87
+ `z.coerce.boolean()` because JavaScript treats any non-empty string,
88
+ including `"false"`, as truthy.
52
89
  - Use `z.enum(["draft", "published"])` for constrained values
53
90
 
54
91
  The legacy `parameters` field (plain JSON Schema object) still works as a fallback but does not provide runtime validation or type inference.
55
92
 
93
+ ## Decision Order
94
+
95
+ When you need app data or a mutation:
96
+
97
+ 1. **Use an existing action** if one already performs the operation.
98
+ 2. **Create or extend a `defineAction`** when the agent and UI both need a new operation.
99
+ 3. **Create a custom route only for route-only concerns** such as uploads, streaming, webhooks, OAuth callbacks, or a non-JSON protocol.
100
+
101
+ Do not build an umbrella REST API to make actions "easier" to call. Actions are already callable by agents, CLIs, React hooks, HTTP, MCP/A2A exposure, and external hosts through the framework.
102
+
103
+ ## Flexible Provider APIs
104
+
105
+ For provider integrations used in ad hoc analysis, querying, reporting, or
106
+ cross-source research, do not hardcode every provider endpoint as a separate
107
+ rigid action. Expose the shared provider API action trio instead:
108
+
109
+ - `provider-api-catalog`: lists provider base URLs, auth style, credential keys,
110
+ docs/spec URLs, placeholders, and examples without exposing secrets.
111
+ - `provider-api-docs`: fetches registered provider docs/spec URLs when the
112
+ exact endpoint, filter operator, payload shape, or pagination contract is
113
+ uncertain.
114
+ - `provider-api-request`: makes a constrained authenticated HTTP request to the
115
+ provider host, injects configured credentials, blocks private/internal URLs,
116
+ and redacts secrets.
117
+
118
+ Use `@agent-native/core/provider-api` as the shared substrate. A template should
119
+ only add a thin credential adapter when it has app-specific credential lookup
120
+ rules. Keep `provider-api-request` `http: false` unless you have a separate UI
121
+ permission model for arbitrary provider writes. Specific actions such as
122
+ `hubspot-deals`, `search-emails`, or `sync-source` are convenience shortcuts,
123
+ not capability limits; agents should fall back to the provider API trio when a
124
+ question requires an endpoint or filter that the shortcut does not model.
125
+
56
126
  ### The `http` Option
57
127
 
58
128
  Controls how the action is exposed as an HTTP endpoint:
@@ -99,7 +169,7 @@ run: async (args) => {
99
169
 
100
170
  ## Frontend Hooks
101
171
 
102
- The frontend calls action endpoints using React Query hooks from `@agent-native/core/client`:
172
+ The frontend calls actions using React Query hooks from `@agent-native/core/client`. Components should not hand-write `fetch("/_agent-native/actions/...")`; add or reuse a client hook/helper instead. Use `callAction` from the same package for imperative cases that do not fit a hook, such as debounced search, prefetching, or non-React event handlers.
103
173
 
104
174
  ### `useActionQuery` — for GET actions
105
175
 
@@ -135,6 +205,17 @@ function AddMealButton() {
135
205
 
136
206
  Mutations automatically invalidate all `["action"]` query keys on success, so GET queries refetch.
137
207
 
208
+ ### `callAction` — for imperative client code
209
+
210
+ ```ts
211
+ import { callAction } from "@agent-native/core/client";
212
+
213
+ const people = await callAction("search-people", { query }, { method: "GET" });
214
+ ```
215
+
216
+ Prefer hooks in React data flows. Use `callAction` when a hook would be awkward;
217
+ do not hand-write action route fetches in components.
218
+
138
219
  ## How to Run (Agent)
139
220
 
140
221
  ```bash
@@ -161,7 +242,7 @@ Most operations should be actions. You only need custom routes in `server/routes
161
242
  - **Webhooks** — external services POST to a specific URL
162
243
  - **OAuth callbacks** — redirect-based flows that need specific URL patterns
163
244
 
164
- If it's a standard CRUD operation or data query, use an action instead.
245
+ If it's a standard CRUD operation, data query, or a wrapper around an action, use the action instead.
165
246
 
166
247
  ## Legacy Pattern (bare export)
167
248
 
@@ -171,7 +252,6 @@ Older actions use a bare async function export with `parseArgs`:
171
252
  import { parseArgs, loadEnv, fail } from "@agent-native/core";
172
253
 
173
254
  export default async function myAction(args: string[]) {
174
- // Only for deploy-level runtime config. User/org credentials use secrets/OAuth.
175
255
  loadEnv();
176
256
  const parsed = parseArgs(args);
177
257
  // ...
@@ -186,11 +266,15 @@ This still works but is not auto-exposed as HTTP. Prefer `defineAction` for all
186
266
  - **Return structured data.** Return objects/arrays, not `JSON.stringify()`.
187
267
  - **Use `http: { method: "GET" }`** for read-only actions. Default is POST.
188
268
  - **Use `http: false`** for agent-only actions (`navigate`, `view-screen`).
269
+ - **Use `agentTool: false`** for UI-only / programmatic actions that should NOT be a tool in the model's context window. It stays frontend/HTTP-callable but is hidden from the agent. Distinct from `toolCallable: false`, which only blocks the sandboxed extension iframe bridge.
270
+ - **Document reusable actions.** If a new action should be called by agents outside one narrow screen, update `AGENTS.md` with when to use it, important args, and which return fields to preserve.
271
+ - **Promote workflow-heavy actions to skills.** If the action is part of a provider-backed, cross-app, MCP/A2A, or multi-step workflow, create or update a skill in `.agents/skills/` and add app-skill visibility (`internal`, `exported`, or `both`) when it should ship through a marketplace.
189
272
  - **Use `loadEnv()`** only for deploy-level configuration. User/org/workspace
190
273
  credentials belong in the encrypted secrets/credential/OAuth stores, never as
191
- hardcoded literals, shared env fallbacks, logs, or action responses.
274
+ hardcoded literals or shared env fallbacks.
192
275
  - **Use `fail()`** for user-friendly error messages (exits with message, no stack trace).
193
276
  - **Import from `@agent-native/core`** — Don't redefine `parseArgs()` or other utilities locally.
277
+ - **Do not re-export actions as REST.** The mounted `/_agent-native/actions/:name` endpoint is the REST surface; duplicating it under `/api/*` creates drift and hides the operation from agents.
194
278
 
195
279
  ## Common Patterns
196
280
 
@@ -263,5 +347,6 @@ export default defineAction({
263
347
 
264
348
  - **storing-data** — Actions read/write data in SQL
265
349
  - **delegate-to-agent** — The agent invokes actions via `pnpm action <name>`
266
- - **real-time-sync** — Database writes from actions trigger poll events to update the UI
350
+ - **real-time-sync** — Database writes from actions trigger change events to update the UI
267
351
  - **adding-a-feature** — Actions are area 2 of the four-area checklist
352
+ - **client-methods** — Client code uses named helpers/hooks instead of raw REST calls
@@ -1,9 +1,10 @@
1
1
  ---
2
2
  name: adding-a-feature
3
3
  description: >-
4
- The four-area checklist every new feature in this app must complete. Use
5
- when adding any feature, integration, or capability to keep the agent and
6
- UI in parity.
4
+ The four-area checklist every new feature must complete. Use when adding any
5
+ feature, integration, or capability to ensure the agent and UI stay in parity.
6
+ metadata:
7
+ internal: true
7
8
  ---
8
9
 
9
10
  # Adding a Feature — The Four-Area Checklist
@@ -14,59 +15,158 @@ Every new feature MUST update all four areas. Skipping any one breaks the agent-
14
15
 
15
16
  ## Why
16
17
 
17
- Agent-native apps are defined by parity: everything the UI can do, the agent can do, and vice versa. A feature that only has UI is invisible to the agent. A feature that only has actions is invisible to the user. A feature without app-state sync means the agent is blind to what the user is doing. And **a feature without auto-refresh wiring means the agent's writes are silently invisible until the user manually reloads** — that breaks the framework's #1 promise.
18
+ Agent-native apps are defined by parity: everything the UI can do, the agent can do, and vice versa. A feature that only has UI is invisible to the agent. A feature that only has scripts is invisible to the user. A feature without app-state sync means the agent is blind to what the user is doing.
18
19
 
19
20
  ## The Checklist
20
21
 
21
- ### 1. UI Component
22
+ When you add a new feature, work through these four areas in order:
22
23
 
23
- Build the user-facing interface — a page, component, dialog, or route. Use `useActionQuery` and `useActionMutation` from `@agent-native/core/client` for data fetching and mutations. You rarely need custom `/api/` routes.
24
+ ### 1. UI Component
24
25
 
25
- **Auto-refresh on agent writes is non-negotiable** when the agent mutates the data this UI shows, the UI must reflect the change without a manual refresh. Two paths, pick the right one:
26
+ Build the user-facing interface a page, component, dialog, or route. Use `useActionQuery` and `useActionMutation` from `@agent-native/core/client` to call actions for data fetching and mutations. Do not create a custom REST endpoint just so React can call action-backed data; the action endpoint already exists.
26
27
 
27
- - **`useActionQuery` (preferred)** — automatically covered. The framework's `useDbSync` invalidates `["action"]` on every change event, so every `useActionQuery` hook refetches when the agent runs an action. No extra wiring required.
28
+ **Auto-refresh on agent writes is non-negotiable** — when the agent mutates data, the UI must reflect the change without a manual refresh. There are two paths, and you must pick the right one:
28
29
 
29
- - **Raw `useQuery` with a custom key** needs explicit wiring. Fold `useChangeVersions([<source>, "action"])` from `@agent-native/core/client` into the `queryKey` and set `placeholderData: (prev) => prev`. The `"action"` source is the reliable signal — the agent runner emits it after every successful tool call. The resource-specific source (e.g. `"settings"`, `"app-state"`) is bonus. Without this wiring, agent writes will be invisible until manual refresh.
30
+ - **`useActionQuery` / `useActionMutation`** covered automatically. The framework's `useDbSync` invalidates `["action"]` on every change event, so every `useActionQuery` hook refetches on agent activity. No extra wiring required. **Prefer this path.**
31
+ - **Raw `useQuery` with custom keys** — needs explicit wiring. Fold `useChangeVersions([<source>, "action"])` from `@agent-native/core/client` into the `queryKey` and set `placeholderData: (prev) => prev`. The `action` source is the reliable signal (the agent runner emits it after every successful tool call); the resource-specific source (`"dashboards"`, `"analyses"`, `"settings"`, etc.) is bonus when emitted. Without this wiring, agent writes will be invisible until manual refresh — that breaks the framework's #1 promise.
30
32
 
31
33
  ```tsx
32
34
  import { useChangeVersions } from "@agent-native/core/client";
33
35
  import { useQuery } from "@tanstack/react-query";
34
36
 
35
- function useItem(id: string) {
36
- const v = useChangeVersions(["items", "action"]);
37
- return useQuery({
38
- queryKey: ["item", id, v],
39
- queryFn: () => fetchItem(id),
40
- placeholderData: (prev) => prev, // no flicker on refetch
41
- });
42
- }
37
+ const v = useChangeVersions(["dashboards", "action"]);
38
+ useQuery({
39
+ queryKey: ["dashboard", id, v],
40
+ queryFn: () => fetchDashboard(id),
41
+ placeholderData: (prev) => prev, // no flicker on refetch
42
+ });
43
43
  ```
44
44
 
45
45
  See the `real-time-sync` skill for the full pattern and source catalog.
46
46
 
47
47
  ### 2. Action
48
48
 
49
- Create an action in `actions/` using `defineAction`. This serves double duty: the agent calls it as a tool, and the framework auto-exposes it as an HTTP endpoint at `/_agent-native/actions/:name` for the UI to call. Set `http: { method: "GET" }` for read actions, leave default for writes, or set `http: false` for agent-only actions like `navigate` and `view-screen`.
49
+ Create an action in `actions/` using `defineAction`. This serves double duty: the agent calls it as a tool, and the UI calls it through `useActionQuery` / `useActionMutation` while the framework owns the HTTP transport. Set `http: { method: "GET" }` for read actions, leave default for writes, or set `http: false` for agent-only actions like `navigate` and `view-screen`.
50
+
51
+ Before adding a new route or endpoint, inspect the existing actions. Reuse an
52
+ action if it already covers the business operation, extend it if the shared
53
+ contract is incomplete, or create a new `defineAction` if the agent and UI both
54
+ need the capability. Do not add pass-through `/api/*` routes that re-export
55
+ actions. If client code needs a new framework/app route, expose a named helper
56
+ or hook first and use that helper from components and docs.
57
+
58
+ For provider-backed analysis/query/reporting integrations, do not turn every
59
+ provider endpoint or filter into a rigid action. Prefer the shared
60
+ `provider-api-catalog` / `provider-api-docs` / `provider-api-request` pattern
61
+ from `@agent-native/core/provider-api`, then add narrow convenience actions only
62
+ for workflows that truly deserve a first-class shortcut.
63
+
64
+ If the feature needs credentials, design the credential path in the same change.
65
+ Never hardcode API keys, tokens, webhook URLs, signing secrets, private
66
+ Builder/internal data, or customer data in the action, UI, seed data, fixtures,
67
+ docs, prompts, or generated extension/app content. Register required secrets,
68
+ use OAuth helpers, or read scoped values from the vault/credential store.
69
+
70
+ **If the action produces or lists a navigable resource**, add a `link` builder that returns `{ url: buildDeepLink({ app, view, params }), label }`. External coding agents and MCP hosts (Claude / ChatGPT / Claude Code / Cowork / Codex, over MCP/A2A) then surface an "Open in … →" deep link that drops the user back into the running UI focused on the record — for free. If a compatible MCP host should render an inline review/edit surface, also add `mcpApp` with `embedApp()` so the action embeds the real React app route instead of a one-off HTML UI. The `link` builder and `mcpApp` metadata must be pure and synchronous (no I/O). Any external-agent read/ingest action must be `http: { method: "GET" }` + `readOnly: true` + `publicAgent: { expose: true, readOnly: true, requiresAuth: true }`. See the `external-agents` skill.
50
71
 
51
72
  ### 3. Skills / Instructions
52
73
 
53
- Update `AGENTS.md` (the per-app guide) and/or create a skill in `.agents/skills/` if the feature introduces patterns the agent needs to know. At minimum, add the new actions to the action table in the template's `AGENTS.md`.
74
+ Update `AGENTS.md` and/or create a skill in `.agents/skills/` if the feature introduces patterns the agent needs to know. At minimum, add the new actions to the action table in the template's `AGENTS.md`.
75
+
76
+ Reusable actions are part of the app contract, not just implementation detail. When an action is useful outside one screen, update agent instructions in the same change so app agents know when to call it, which arguments matter, and what output to preserve. If the capability is workflow-heavy, cross-app, provider-backed, or has a non-obvious sequence of actions, add or update a skill instead of burying the behavior in one long `AGENTS.md` paragraph.
77
+
78
+ Instruction examples may name secret keys like `SLACK_WEBHOOK`, but must use
79
+ placeholders such as `${keys.SLACK_WEBHOOK}` or `<SLACK_WEBHOOK>`. Do not paste
80
+ real keys, internal data, or customer data into instructions as examples.
81
+
82
+ For app-backed skills, declare skill visibility in the app-skill manifest:
83
+
84
+ - `internal` — only the app's own agents should use it.
85
+ - `exported` — marketplace installs receive it, but the app does not need it loaded internally.
86
+ - `both` — shared between the app's internal agents and exported marketplace bundles.
54
87
 
55
88
  ### 4. Application State Sync
56
89
 
57
90
  Expose navigation and selection state so the agent knows what the user is looking at. Write to the `navigation` app-state key on route changes. Update the `view-screen` action to fetch relevant data for the new feature. Add a `navigate` command if the agent needs to open the new view.
58
91
 
92
+ ## Examples
93
+
94
+ ### Adding "compose email" to a mail app
95
+
96
+ | Area | What to build |
97
+ | --------------- | ---------------------------------------------------------------------------------------- |
98
+ | UI | Compose panel with tabs, to/cc/bcc fields, body editor. Use `useActionQuery`/`useActionMutation` for data. |
99
+ | Action | `manage-draft` action (create/update/delete drafts), `send-email` action |
100
+ | Skills/AGENTS | Document compose state shape, draft lifecycle, action args in AGENTS.md |
101
+ | App-state sync | `compose-{id}` keys for each draft tab, `navigation` includes compose state |
102
+
103
+ ### Adding "create form" to a forms app
104
+
105
+ | Area | What to build |
106
+ | --------------- | ---------------------------------------------------------------------------------------- |
107
+ | UI | Form builder page with drag-and-drop fields, preview, settings. Use `useActionQuery` for lists. |
108
+ | Action | `create-form` action, `update-form` action, `list-forms` action (GET) |
109
+ | Skills/AGENTS | Document form schema shape, field types, validation rules in AGENTS.md |
110
+ | App-state sync | `navigation` includes `{ view: "form-builder", formId: "..." }`, `view-screen` fetches form data |
111
+
112
+ ### Adding "chart type" to an analytics app
113
+
114
+ | Area | What to build |
115
+ | --------------- | ---------------------------------------------------------------------------------------- |
116
+ | UI | New chart component, chart type selector in dashboard |
117
+ | Action | `create-chart` or `update-dashboard` action that sets chart type and config |
118
+ | Skills/AGENTS | Document supported chart types, config options, data requirements |
119
+ | App-state sync | `navigation` includes selected chart/dashboard, `view-screen` returns chart config |
120
+
121
+ ## Adding a new route
122
+
123
+ Templates are single-page apps with client-side routing. The app shell (AgentSidebar + top-level nav) MUST persist across navigation — it is mounted once, either in `root.tsx` around `<Outlet />` or via a pathless `_app.tsx` layout route that all authed routes nest under.
124
+
125
+ **Never wrap each new route in its own `<AppLayout>` / `<Layout>`.** That causes React to unmount the entire app shell on every navigation, reloading the agent sidebar and destroying in-progress work.
126
+
127
+ - If the template has `<AppLayout>` in `root.tsx` — just render page content in your new route file, nothing else.
128
+ - If the template has `app/routes/_app.tsx` (pathless layout) — name your new route `_app.<segment>.tsx` to inherit the shell, or bare `<segment>.tsx` for public routes that should NOT have the shell.
129
+ - If a page needs per-route data (e.g. highlighting the active item in the sidebar), read it in the layout from `useParams()` / `useLocation()`. Don't pass it as a prop through every route file.
130
+
131
+ See the "Client-Side Routing" section in the root `CLAUDE.md` for full details.
132
+
59
133
  ## Anti-Patterns
60
134
 
61
- - **UI without actions** — The user can create things but the agent cannot. Breaks parity.
62
- - **Actions without UI** — The agent can do something the user cannot. Less common but still breaks parity.
63
- - **Mutations without auto-refresh wiring** — The agent says "done!" but the screen doesn't change until the user hits reload. This is the most common silent regression. If you used `useActionQuery` you're covered; if you used raw `useQuery`, fold `useChangeVersions` into the key. Always test by asking the agent to mutate the data and watching the UI without refreshing.
135
+ - **Per-route `<AppLayout>` wrappers** — Every route file wraps its content in `<AppLayout>` or `<Layout>`. React sees a different component at the outlet on each nav and unmounts the whole shell, causing the agent sidebar to reload on every click. Mount the shell once above `<Outlet />` (root.tsx or `_app.tsx` pathless layout).
136
+ - **UI without actions** — The user can create forms but the agent cannot. The agent says "I don't have access to that" when it should be able to do it.
137
+ - **Actions without AGENTS.md** — The actions exist but the agent doesn't know about them because they're not documented. The agent reinvents solutions instead of using the actions.
138
+ - **Duplicate API routes** — Creating `/api/` routes for operations that actions already handle, including pass-through routes that just call or repackage an action. Use `useActionQuery`/`useActionMutation` instead.
139
+ - **Raw client route calls** — Teaching or adding `fetch("/_agent-native/...")`,
140
+ `fetch(agentNativePath(...))`, or template `/api/*` calls in components for
141
+ normal app work. Add a named client helper/hook and call that instead.
142
+ - **Features without app-state** — The agent cannot see that the user is looking at a specific form, email, or chart. It asks "which one?" instead of acting on the current selection.
143
+ - **Actions without UI** — The agent can do something the user cannot. This is less common but still breaks parity.
64
144
 
65
145
  ## Verification
66
146
 
67
- For every new feature, manually verify:
147
+ After completing all four areas, verify:
68
148
 
69
149
  1. Can the user perform the operation from the UI?
70
- 2. Can the agent perform the operation via an action (`pnpm action <name>`)?
71
- 3. When the agent runs the action, **does the UI update within a second or two without a manual refresh**? If not, your query is missing `useActionQuery` or `useChangeVersions` wiring — go back to step 1.
72
- 4. Does `view-screen` return the new feature's state when the user is on that page?
150
+ 2. Can the agent perform the same operation via actions?
151
+ 3. Does `pnpm action view-screen` show the relevant state when the user is using the feature?
152
+ 4. Can the agent navigate to the feature view via the `navigate` action?
153
+ 5. Is the feature documented in AGENTS.md with action names and args?
154
+ 6. Are credentials and sensitive data supplied only through approved runtime
155
+ channels, with no hardcoded real keys, tokens, webhook URLs, Builder/internal
156
+ data, or customer data?
157
+
158
+ ## One more area — sharing
159
+
160
+ If the feature stores **user-authored resources** (documents, dashboards, forms, decks, etc.), make them ownable so they get private-by-default semantics and a share dialog for free. See the `sharing` skill.
161
+
162
+ TL;DR: spread `ownableColumns()` into the resource table, pair it with `createSharesTable(...)`, call `registerShareableResource(...)`, wrap list/read queries with `accessFilter`, guard writes with `assertAccess`, and drop `<ShareButton>` in the resource header. The `share-resource`, `unshare-resource`, `list-resource-shares`, and `set-resource-visibility` actions are auto-mounted framework-wide.
163
+
164
+ ## Related Skills
165
+
166
+ - **sharing** — How to make a new resource ownable (private by default, share with users/orgs/public)
167
+ - **context-awareness** — How to expose UI state to the agent (area 4 in detail)
168
+ - **actions** — How to create actions with `defineAction` and the `http` option (area 2 in detail)
169
+ - **external-agents** — Add a `link` builder so external agents (MCP/A2A) get an "Open in … →" deep link
170
+ - **create-skill** — How to create skills for new patterns (area 3 in detail)
171
+ - **storing-data** — Where to store the feature's data
172
+ - **real-time-sync** — How the UI stays in sync when the agent writes data
@@ -1,50 +1,76 @@
1
1
  ---
2
2
  name: capture-learnings
3
3
  description: >-
4
- Capture and apply accumulated knowledge in learnings.md. Use when the user
5
- corrects a mistake, when debugging reveals unexpected behavior, or when an
6
- architectural decision should be recorded for future reference.
4
+ Capture and apply accumulated knowledge via structured memory. Use when the
5
+ user gives feedback, shares preferences, corrects a mistake, or when you
6
+ discover something worth remembering for future conversations.
7
7
  user-invocable: false
8
+ metadata:
9
+ internal: true
8
10
  ---
9
11
 
10
12
  # Capture Learnings
11
13
 
12
- This is background knowledge, not a slash command. Read `learnings.md` before starting significant work. Update it when you discover something worth remembering.
14
+ This is background knowledge, not a slash command. **Your memory index is loaded at the start of every conversation.** Use `save-memory` proactively when you learn something worth remembering.
13
15
 
14
- ## When to Capture
16
+ ## How to Read & Write Memories
15
17
 
16
- Use judgment, not rules. Capture when:
18
+ Memories are stored as **resources** in the SQL database (personal scope), not as files on disk.
17
19
 
18
- - **Surprising behavior** Something didn't work as expected and you figured out why
19
- - **Repeated friction** You hit the same issue twice; write it down so there's no third time
20
- - **Architectural decisions** — Why something is done a certain way (the "why" isn't in the code)
21
- - **API/library quirks** Undocumented behavior, version-specific gotchas
22
- - **Performance insights** — What's slow and what fixed it
20
+ - **Save a memory:** `save-memory --name <name> --type <type> --description "..." --content "..."`
21
+ - **Read a memory:** `resource-read --path memory/<name>.md`
22
+ - **Delete a memory:** `delete-memory --name <name>`
23
+ - **List all memories:** `resource-list --prefix memory/`
23
24
 
24
- Don't capture:
25
+ ## Memory Types
25
26
 
26
- - Things that are obvious from reading the code
27
- - Standard language/framework behavior
28
- - Temporary debugging notes
27
+ | Type | Use for |
28
+ |------|---------|
29
+ | `user` | Preferences, role, personal context, contacts |
30
+ | `feedback` | Corrections, confirmed approaches, things to avoid or repeat |
31
+ | `project` | Ongoing work context, decisions, deadlines, status |
32
+ | `reference` | Pointers to external systems, URLs, API details |
29
33
 
30
- ## Format
34
+ ## When to Capture
31
35
 
32
- Add entries to `learnings.md` at the project root. Match the existing format — typically a heading per topic with a brief explanation:
36
+ ### User Preferences & Memory (`user`)
37
+ - **Tone and style** — "I prefer casual tone", "don't use emojis", "keep replies short"
38
+ - **Personal context** — contacts, relationships, habits ("my wife's email is...", "I'm in PST timezone")
39
+ - **Workflow preferences** — "always CC my assistant", "I like to review before sending"
40
+ - **Role and expertise** — "I'm a data scientist", "new to React"
41
+
42
+ ### Feedback & Corrections (`feedback`)
43
+ - **Corrections** — user says "no, do it this way" → capture the right way
44
+ - **Confirmed approaches** — user validates a non-obvious choice ("yes, that's perfect")
45
+ - **Repeated friction** — you hit the same issue twice; save it
46
+
47
+ ### Project Context (`project`)
48
+ - **Ongoing work** — who is doing what, why, by when
49
+ - **Decisions** — why something is done a certain way
50
+ - **Status** — current state of initiatives
51
+
52
+ ### References (`reference`)
53
+ - **External systems** — "bugs are tracked in Linear project INGEST"
54
+ - **URLs** — dashboards, documentation, tools
55
+ - **API quirks** — undocumented behavior, version-specific gotchas
56
+
57
+ ### Don't Capture
58
+ - Things obvious from reading the code
59
+ - Standard language/framework behavior
60
+ - Temporary debugging notes
61
+ - Anything already in AGENTS.md or skills
62
+ - Ephemeral task details (use tasks/plans instead)
33
63
 
34
- ```markdown
35
- ## [Topic]
64
+ ## Key Rules
36
65
 
37
- [What you learned and why it matters. Keep it to 2-3 sentences.]
38
- ```
66
+ 1. **Save proactively don't ask permission.** When you learn something, save it immediately.
67
+ 2. **One memory per topic** — e.g. `coding-style`, `project-alpha`, not one giant dump
68
+ 3. **Read before updating** — if a memory exists, read it first and merge, don't overwrite
69
+ 4. **Keep descriptions concise** — the index is loaded every conversation
70
+ 5. **Memories are SQL-backed** — safe for personal info, persist across sessions, not in git
39
71
 
40
72
  ## Graduation
41
73
 
42
- When a learning is referenced repeatedly, it's outgrowing `learnings.md`. Propose adding it to the relevant skill or creating a new skill via `create-skill`.
43
-
44
- - Updating `learnings.md` is a Tier 1 modification (data auto-apply)
45
- - Updating a SKILL.md based on learnings is Tier 2 (source — verify after)
46
-
47
- ## Related Skills
48
-
49
- - **self-modifying-code** — Learnings.md updates are Tier 1; skill updates are Tier 2
50
- - **create-skill** — When a learning graduates, create a skill from it
74
+ When a memory is referenced repeatedly, it may belong in AGENTS.md or a skill:
75
+ - Saving a memory is lightweight (auto-apply, personal scope)
76
+ - Updating AGENTS.md or a skill is heavier (affects all users/agents)
@@ -4,6 +4,8 @@ description: >-
4
4
  How to create new skills for an agent-native app. Use when adding a new
5
5
  skill, documenting a pattern the agent should follow, or creating reusable
6
6
  guidance for the agent.
7
+ metadata:
8
+ internal: true
7
9
  ---
8
10
 
9
11
  # Create a Skill
@@ -148,6 +150,32 @@ description: >-
148
150
  - Workflow/generator skills: verb-noun (`create-skill`, `capture-learnings`).
149
151
  - The directory name must match the `name` in frontmatter.
150
152
 
153
+ ## Skill Scope (runtime vs dev)
154
+
155
+ An optional `scope` frontmatter field controls which agent loads the skill:
156
+
157
+ - `both` (default when omitted) — loaded by the in-app runtime agent. Use for
158
+ any skill the runtime agent should follow.
159
+ - `runtime` — loaded only by the in-app runtime agent.
160
+ - `dev` — meant for the human's coding agent (e.g. Claude Code) only. **Excluded
161
+ from the runtime agent everywhere**: not in the system-prompt skills block and
162
+ not in `docs-search` results.
163
+
164
+ ```markdown
165
+ ---
166
+ name: release-checklist
167
+ description: >-
168
+ Steps for cutting a release. Use when preparing or publishing a new version.
169
+ scope: dev
170
+ ---
171
+ ```
172
+
173
+ Leave `scope` off for normal skills — the default (`both`) keeps them loading at
174
+ runtime, so this is fully backward compatible. To make a dev-only skill visible
175
+ to your coding agent but hidden from the runtime agent, mark it `scope: dev` and
176
+ optionally mirror it under `.claude/skills/<name>/SKILL.md` (Claude Code reads
177
+ `.claude/skills/` independently of the runtime's `.agents/skills/`).
178
+
151
179
  ## Tips
152
180
 
153
181
  - **Keep descriptions under 40 words** — they load into context on every