reboot alterflixhub
This commit is contained in:
commit
1e84023a44
188 files changed
+31629
No files matched your search
@@ -0,0 +1,200 @@
|
||||
---
|
||||
name: build-an-app
|
||||
description: >-
|
||||
Fast end-to-end workflow for turning this starter into a working domain app
|
||||
from a short or vague request. Use when asked to build, make, create, or
|
||||
prototype an app, tool, tracker, dashboard, booking, inventory, or CRM
|
||||
system with Agent-Native. Read before the first edit.
|
||||
scope: both
|
||||
metadata:
|
||||
internal: true
|
||||
---
|
||||
|
||||
# Build an App
|
||||
|
||||
Done means one useful domain workflow with a designed route, shared UI/agent
|
||||
actions, correct access, agent context, and a smoke run that proves its key
|
||||
rule. Finish a narrow slice before expanding it.
|
||||
|
||||
This skill edits source files. If this session cannot write files (a deployed
|
||||
app's runtime agent), say the change needs a code session and stop.
|
||||
|
||||
The four-area parity rule from `adding-a-feature` (UI, action, instructions,
|
||||
application state) applies to everything you add. This skill supplies the
|
||||
order and decisions; use the edit-point reference for the scaffold you have.
|
||||
|
||||
## 1. Orient
|
||||
|
||||
Read `AGENTS.md`, this skill, and only the files you will edit. Skip broad repo
|
||||
surveys, `README.md`, and `DESIGN.md`. Use the bundled docs/source commands in
|
||||
`AGENTS.md` only to answer a concrete API question; do not web-research
|
||||
framework APIs.
|
||||
|
||||
## 2. Decide
|
||||
|
||||
Choose these six things before writing code:
|
||||
|
||||
1. **Slice**: the one workflow that proves the app. For a booking app: create a
|
||||
booking, reject an overlap, cancel, weekly grid per room. Name what you are
|
||||
deferring (recurrence, notifications, roles, integrations) unless requested.
|
||||
2. **Who sees each table**: pick one row of the access table in
|
||||
`references/data-and-access.md`: private, team-visible, shared on invite, or a
|
||||
child that inherits its parent's access. Making a team resource private per
|
||||
user is the usual wrong turn. Everyone then sees an empty list, and no
|
||||
conflict check can see anyone else's rows. Give each table `owner_email`
|
||||
and/or `org_id`, directly or via `ownableColumns()`; `org_id` alone passes
|
||||
`[db-tool-scoping]`. Doctor checks the schema marker, not query authorization;
|
||||
never denylist or opt out `rooms` or `bookings`.
|
||||
3. **Invariants**: rules that must hold under concurrent requests (no overlap,
|
||||
stock never negative, unique slug). Enforce them in a write action inside a
|
||||
transaction or with a database constraint; the UI alone is insufficient.
|
||||
4. **Actions**: `list-<things>`, `create-<thing>`, a single `update-<thing>`
|
||||
patch per resource, and the domain verbs (`cancel-booking`). Fewer,
|
||||
orthogonal tools make the agent choose better.
|
||||
5. **Route**: give the domain its own route (for example, `/rooms`). Preserve
|
||||
existing routes and set `app.homePath` so sign-in lands on the domain when
|
||||
that is the requested home screen.
|
||||
6. **Agent context**: URL ids and filters (for example `roomId`, `week`) that
|
||||
belong in `navigation`.
|
||||
|
||||
## 3. Build: write everything, then verify once
|
||||
|
||||
In a generated app, read `package.json` at
|
||||
`["agent-native"].scaffold.template` and choose the matching reference:
|
||||
|
||||
- `builder-code-starter`: this starter has no Chat shell. Use `AGENTS.md`,
|
||||
`DEVELOPING.md`, and `drizzle/START_HERE.md` for edit points.
|
||||
- `default`: `references/edit-points-default.md`
|
||||
- workspace root: use `adding-workspace-apps` to create an app, then follow the
|
||||
new app's own `AGENTS.md` and scaffold reference.
|
||||
- another domain template: use its `AGENTS.md` and `adding-a-feature`; do not
|
||||
apply Chat or default shell instructions to it.
|
||||
|
||||
If metadata is absent, inspect the actual route, layout, plugin, and navigation
|
||||
files before choosing an edit point. Do not infer a shell from the app name.
|
||||
|
||||
Write the UI, actions, instructions, and state before running the verification
|
||||
steps below. Do not leave placeholder or comment-only screens.
|
||||
|
||||
`references/rooms-example.md` gives a booking slice to adapt. It was verified
|
||||
against the Chat starter; use the selected edit-point reference for the shell.
|
||||
Use `frontend-design` for a deliberate visual direction and finish the
|
||||
requested screens and interactions.
|
||||
|
||||
### Data
|
||||
|
||||
- Use PostgreSQL only, and keep migrations additive: new columns are nullable
|
||||
or have a default, and nothing is dropped or renamed. Never edit an applied
|
||||
entry; append a new named one.
|
||||
- Set `ownerEmail` from `ctx.userEmail` and `orgId` from `ctx.orgId` on inserts
|
||||
where those columns exist. Never rely on a development identity fallback.
|
||||
- Ids are text from `crypto.randomUUID()`.
|
||||
- Bound every list (a time range or `.limit()`), select only the columns it
|
||||
renders, and index the columns it filters and sorts on.
|
||||
- Store normalized UTC ISO timestamps; collect/display local times in the
|
||||
user's timezone. Validate offsets at the action boundary before parsing.
|
||||
|
||||
The access table, the concurrency pattern, and the security rules are in
|
||||
`references/data-and-access.md`.
|
||||
|
||||
### Actions
|
||||
|
||||
- `schema` is zod, with `.describe()` on every field stating its units and
|
||||
format (for example, "ISO 8601 date-time with offset").
|
||||
- Reads use `http: { method: "GET" }` and `readOnly: true`. Leave writes on the
|
||||
default POST so `useActionMutation` needs no `method`.
|
||||
- Reject with `fail(message, { errorCode, statusCode })` from
|
||||
`@agent-native/core/action`: 409 for a conflict, 404 for not found, 403 for
|
||||
forbidden. A returned `{ error }` is counted as success everywhere, and a
|
||||
bare `throw` reaches the browser as a generic 500.
|
||||
- Return plain objects that include the `id`. Keep LLM calls out of actions;
|
||||
AI-shaped work belongs in the agent chat.
|
||||
- When the request is batch-shaped ("add these 20"), write one action that
|
||||
takes an array and writes it in one transaction.
|
||||
|
||||
### UI
|
||||
|
||||
- Load and write data with `useActionQuery` and `useActionMutation` from
|
||||
`@agent-native/core/client/hooks`. No `fetch`, and no `/api/*` routes for app
|
||||
data. Those routes are only for uploads, webhooks, OAuth callbacks, and streaming.
|
||||
- While data loads, show a `Skeleton` in the shape of the final layout, not a
|
||||
spinner or "Loading…".
|
||||
- Writes should feel instant. In `onMutate`, update `["action", "<name>", params]`
|
||||
with `setQueryData`; in `onError`, roll back and show
|
||||
`toast.error(actionErrorMessage(error) ?? "<fallback>")`.
|
||||
- Import controls from `@/components/ui/*`. When one is missing (dialog,
|
||||
select, skeleton, alert-dialog), add a one-line re-export like `button.tsx`:
|
||||
`export * from "@agent-native/toolkit/ui/dialog";`.
|
||||
- Use Tabler icons only. Confirm with `AlertDialog`; never use `window.confirm`,
|
||||
`alert`, or `prompt`.
|
||||
- Don't add a page title that repeats the nav item, a subtitle under a title,
|
||||
or a stats strip. The data is the page. For visual direction, see `frontend-design`.
|
||||
- Follow the app's existing localization pattern for user-facing copy.
|
||||
- Add a pure `link` builder with `buildDeepLink()` to actions that create or
|
||||
list navigable resources; see `adding-a-feature` for the shape.
|
||||
|
||||
### Agent instructions
|
||||
|
||||
Append one section of about 1,500 characters at most to `AGENTS.md`. The
|
||||
runtime prompt cuts the file off at 6,000 characters. Cover:
|
||||
|
||||
- a one-line purpose with the routes
|
||||
- the invariants, and how to report a rejection
|
||||
- time and format conventions
|
||||
- the new `navigation` fields
|
||||
- an action table with unpadded cells
|
||||
|
||||
Keep the action table aligned with the scaffold's primary tool list when one
|
||||
exists; other actions should remain discoverable through `tool-search`. Leave
|
||||
unrelated AGENTS.md sections, README, and DESIGN.md as they are.
|
||||
|
||||
### Real-time
|
||||
|
||||
Agent writes need no wiring, because the chat run refreshes action queries
|
||||
after each tool. Add `useDbSync({ realtime: { reason } })` to a page only when
|
||||
other people change its data while it is open and the user must see the change
|
||||
before refreshing. A booking grid doesn't qualify: the server rejects bookings
|
||||
made from a stale view. See `real-time-sync`.
|
||||
|
||||
## 4. Verify, once, in this order
|
||||
|
||||
1. Start `pnpm exec agent-native dev` in the background, without `--open`, and
|
||||
wait for the ready URL. Startup regenerates `.generated/action-types.d.ts`
|
||||
and the actions registry, so a typecheck run before this is meaningless.
|
||||
On loopback, automatic dev sign-in works when the local database has no real
|
||||
users. If the sign-in page appears, use an existing local account or switch
|
||||
to a separate disposable local database; do not create accounts or set
|
||||
`AUTH_DISABLED`.
|
||||
2. Run `pnpm typecheck`, then `pnpm agent-native:doctor`. Plain `pnpm doctor`
|
||||
runs pnpm's own command and exits 0 without running Agent-Native Doctor. Fix
|
||||
every finding, then rerun only what failed.
|
||||
3. Check the agent path. Call a guarded write twice with the same input via
|
||||
`pnpm action <name> --key value`. The second call must fail with the expected
|
||||
message; read back the saved state through the matching list/get action.
|
||||
The CLI prints the failure message, not its structured `errorCode`, so also
|
||||
verify any code-specific behavior in the action contract or browser.
|
||||
4. Run one browser smoke on the domain route:
|
||||
- create a record
|
||||
- trigger the rejection: a toast appears and nothing is written
|
||||
- cancel or undo, repeat the previously rejected write, and confirm it
|
||||
succeeds
|
||||
|
||||
Inspect console and network failures. Fix errors from the new route or actions
|
||||
and identify existing scaffold messages separately. The only expected 4xx/5xx
|
||||
is the rejection being tested. Capture the finished workflow.
|
||||
5. Stop the dev server and close the tab.
|
||||
|
||||
Skip the production build, unrelated test suites, and README or DESIGN rewrites.
|
||||
To triage failures, see `references/verification.md`.
|
||||
|
||||
## 5. Report
|
||||
|
||||
State what works and the proof, what you deferred, and anything the user still
|
||||
has to do (for example, set `DATABASE_URL` before deploying). Never report a
|
||||
check you didn't run.
|
||||
|
||||
## Related
|
||||
|
||||
- `adding-a-feature`: the parity checklist for each later feature in this app.
|
||||
- `frontend-design`, `actions`, `sharing`, `real-time-sync`, and `security`:
|
||||
go deeper on one area when the references aren't enough.
|
||||
@@ -0,0 +1,91 @@
|
||||
# Data and access decisions
|
||||
|
||||
Use this when choosing who may see a row or when adding a schema/migration. A
|
||||
table's columns control framework SQL-tool scoping; app actions still need their
|
||||
own access checks for the people and records they return.
|
||||
|
||||
## Choose the row model
|
||||
|
||||
| Data | Columns | App action behavior |
|
||||
| ---------------------------------------------------------------- | ---------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||
| Private to its creator (notes, drafts) | `owner_email` | Filter reads and writes by `ctx.userEmail`; set the owner on insert. |
|
||||
| Shareable resource (documents, dashboards) | `...ownableColumns()` plus `createSharesTable()` and `registerShareableResource()` | Use `accessFilter(table, shares)` for lists; use `assertAccess(type, id, role)` before reads/writes by id. Choose `private`, `org`, or `public` visibility deliberately. |
|
||||
| Team resource (rooms, products, customers) | Same shareable-resource columns | Use `visibility: "org"` when an org is active. Without an org, choose a deliberate private or no-create behavior. |
|
||||
| Child of a resource (bookings in a room, line items in an order) | `parent_id`, `owner_email`, and the parent's `org_id` when present | Check access to the parent in the action, then scope every child query by parent id and tenant. Apply child-specific rules in the write action. |
|
||||
| Organization-only rows (for example, membership records) | `org_id` only | Filter each app action by the active org; this does not support private ownership or per-user share grants. |
|
||||
| Public URL (published form or booking page) | Separate slug/token | Use a public route with its own validation and read policy; sharing visibility does not create anonymous URL access. |
|
||||
|
||||
Do not make a shared team resource private by adding only `owner_email`: that
|
||||
causes normal app actions and lists to hide coworkers' rows. Use
|
||||
`ownableColumns()` and the registered sharing helpers. Conversely, a room's
|
||||
bookings can inherit the room's access if the booking actions check the room
|
||||
before returning its rows.
|
||||
|
||||
### What agent SQL tools can see
|
||||
|
||||
`db-query`/`db-exec` create scoped views: an `owner_email` table is limited to
|
||||
the current owner. If the caller has an active org and the table also has
|
||||
`org_id`, rows are further limited to that org or a null org; without an active
|
||||
org, only the owner filter applies. An `org_id`-only table is limited to the
|
||||
current org and denied when there is no org. A table with neither column is
|
||||
denied. This is deliberately narrower than share grants, so use typed app
|
||||
actions to list team-shared records or children that inherit parent access.
|
||||
Do not add filters to raw SQL that duplicate these views.
|
||||
|
||||
The same row scoping does not replace action authorization. `accessFilter`
|
||||
resolves resource visibility/share grants; `assertAccess` checks one resource
|
||||
and role. The person who owns a row and a person with an org role are different
|
||||
access concepts.
|
||||
|
||||
## Schema and migrations
|
||||
|
||||
- PostgreSQL only. Define tables with `drizzle-orm/pg-core`; use
|
||||
`drizzle-orm` query operators. Import framework sharing helpers from
|
||||
`@agent-native/core/db/schema` only for ownable resources.
|
||||
- Chat has no database files or Drizzle migration config. Add
|
||||
`server/db/schema.ts`, `server/db/index.ts` with `createGetDb(schema)`, and
|
||||
`server/plugins/db.ts` with `runMigrations([...], { table })`. Follow the
|
||||
bundled Database docs. Other starters may document their own migration path.
|
||||
- Each migration entry needs a unique stable `{ version, name, sql }`. Never
|
||||
renumber or edit an applied entry; append a new additive migration.
|
||||
- Additive only: new columns are nullable or have a default, and nothing is
|
||||
dropped, renamed, or retyped. Keep SQL DDL aligned with the Drizzle schema.
|
||||
- Use text ids from `crypto.randomUUID()`. For sortable time text, normalize
|
||||
every input to UTC `Date#toISOString()` before storing or comparing it.
|
||||
- Use a `CHECK` or `UNIQUE` constraint for single-row rules such as valid
|
||||
status, `end > start`, or unique slugs.
|
||||
|
||||
`ownableColumns()` provides a development fallback owner value for framework
|
||||
compatibility. App actions must still set the authenticated `ownerEmail` from
|
||||
`ctx.userEmail`; never rely on that fallback to identify a real user.
|
||||
|
||||
## Invariants across rows
|
||||
|
||||
For rules such as no overlapping bookings or no overselling:
|
||||
|
||||
1. Validate and normalize input, then check the caller's access to the parent.
|
||||
2. Start `getDb().transaction(async (tx) => { ... })`.
|
||||
3. Lock the parent row with `tx.select(...).from(parent).where(...).for("update")`
|
||||
so concurrent writers for that parent serialize.
|
||||
4. Query for conflicts with `tx`; if one exists, use `fail()` with a stable
|
||||
`errorCode`, `statusCode: 409`, and a safe conflict identifier.
|
||||
5. Insert with `tx` and return the saved result. Do not open a separate query
|
||||
or call another action from inside the transaction callback.
|
||||
|
||||
The lock is effective only when every writer follows the same parent-lock
|
||||
protocol. Put the invariant in one action and use a database constraint when a
|
||||
single-row constraint can express it.
|
||||
|
||||
## Query and security defaults
|
||||
|
||||
- Give every action a zod schema. Bound every list with a time range, `.limit()`,
|
||||
or pagination; select only fields the caller needs; index hot filters/sorts.
|
||||
- Use parameterized Drizzle queries. Never concatenate user input into SQL.
|
||||
- Keep secrets in workspace connections or the vault, not source, SQL, seeds, or
|
||||
instructions. See the `secrets` skill before adding credentials.
|
||||
- Put file/image/audio/video/PDF payloads in configured blob storage and save
|
||||
only the returned URL or opaque id in SQL.
|
||||
- Add a custom `/api/*` route only for uploads, webhooks, OAuth callbacks,
|
||||
streaming, or public unauthenticated responses. Use actions for app data.
|
||||
- Keep startup limited to framework/plugin initialization and migrations;
|
||||
put imports, backfills, and provider calls behind an action or job.
|
||||
@@ -0,0 +1,23 @@
|
||||
# Default scaffold edit points
|
||||
|
||||
Use only when `package.json["agent-native"].scaffold.template` is `default`.
|
||||
This scaffold has a document/provider root and a sample `/home` route. It has
|
||||
no Chat sidebar, `Layout.tsx`, `server/plugins/agent-chat.ts`, or
|
||||
`INITIAL_TOOL_NAMES` list.
|
||||
|
||||
| File | Change |
|
||||
| ----------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `server/db/schema.ts` (new) | Define PostgreSQL tables with `drizzle-orm/pg-core`; use the shared schema helpers when access/sharing needs them |
|
||||
| `server/db/index.ts` (new) | Export `getDb = createGetDb(schema)` and register shareable resources as needed |
|
||||
| `server/plugins/db.ts` (new) | Add named, additive migrations with `runMigrations` |
|
||||
| `actions/<verb>-<noun>.ts` | One default-exported `defineAction` per file; the filename becomes the tool name |
|
||||
| `app/routes.ts` and `app/routes/<domain>.tsx` | `flatRoutes()` discovers route files; add the domain route and nested routes using the filename conventions already present |
|
||||
| `app/root.tsx` | Keep the document, providers, and `<Outlet />`; do not replace it with a domain shell |
|
||||
| `app/hooks/use-navigation-state.ts` | Extend the current path-derived navigation state only when the agent needs selected domain ids or filters beyond the current URL |
|
||||
| `server/plugins/agent-native-email-branding.ts` | Set `app.homePath` to the requested authenticated home route; the create command adds this plugin when it renames the scaffold |
|
||||
| `AGENTS.md` | Add a concise domain section with routes, invariants, state, and primary actions |
|
||||
|
||||
`app/routes/_index.tsx` is the sign-in landing route. `app/routes/home.tsx`
|
||||
is the authenticated sample page. Preserve both unless the requested workflow
|
||||
specifically replaces the home experience. The default template has no app
|
||||
navigation shell to extend; add only the navigation the product needs.
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,57 @@
|
||||
# Verification: run order and triage
|
||||
|
||||
## Run order and why
|
||||
|
||||
1. **Dev server first.** Run `pnpm exec agent-native dev` in the background.
|
||||
`pnpm dev` also works but passes `--open` and launches a browser. Starting
|
||||
the server runs your migrations and regenerates `.generated/action-types.d.ts`
|
||||
and `.generated/actions-registry.ts`. Until it has run, `useActionQuery("new-action")`
|
||||
cannot type-check and the agent cannot see the new tools.
|
||||
2. **`pnpm typecheck`.** This runs React Router typegen, then `tsc --noEmit`.
|
||||
It does not regenerate action types; step 1 does that.
|
||||
3. **`pnpm agent-native:doctor`.** It scans `actions/` and `server/` for
|
||||
unscoped queries on ownable tables, credentials read from `process.env`,
|
||||
and similar mistakes. If the script is missing, run `pnpm exec agent-native doctor`.
|
||||
4. **Agent path.** Run `pnpm action <name> --key value`. When the dev server is
|
||||
running, the CLI forwards the call to it, so it shares the same database and
|
||||
dev identity. Call the guarded write twice with the same input and verify
|
||||
the second fails with the expected message; read the saved state through the
|
||||
matching list/get action. The CLI prints failure messages, not structured
|
||||
`errorCode` values, so verify code-specific behavior in the action contract
|
||||
or browser. Raw `db-query` views are scoped to the current owner or
|
||||
organization and do not include all records granted through app-level sharing.
|
||||
5. **One browser smoke** on the domain route: create, the rejected case, and
|
||||
undo or cancel. Inspect console and failed network requests. Fix errors from
|
||||
the new route or actions; identify existing scaffold messages separately.
|
||||
On loopback, automatic dev sign-in works while the database has no real
|
||||
users. If it shows a sign-in page, use an existing local account or a
|
||||
separate disposable local database; do not create accounts or set
|
||||
`AUTH_DISABLED`. Capture the finished workflow.
|
||||
6. **Clean up.** Close the tab and stop the dev server.
|
||||
|
||||
Run each check once. After a fix, rerun only the check that failed. Don't
|
||||
add a production build, new test files, or a second full pass.
|
||||
|
||||
## Triage
|
||||
|
||||
| Symptom | Usual cause | Fix |
|
||||
| ----------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `useActionQuery("x")` type error, or the action is unknown to the agent | `.generated/*` is stale | Make sure the dev server is running, save the action file, and rerun typecheck |
|
||||
| `relation "x" does not exist` | The table has no migration entry, or `server/plugins/db.ts` doesn't default-export `runMigrations(...)` | Add the entry and restart dev |
|
||||
| Migration ignored after an edit | You changed an entry that had already run | Revert the edit and append a new named entry |
|
||||
| 405 from an action | The HTTP method and the hook disagree | Reads use `http: { method: "GET" }` with `useActionQuery`; writes use the default POST with `useActionMutation` |
|
||||
| Toast says "Internal server error" | A bare `throw` | Throw with `fail(message, { statusCode })` |
|
||||
| A rejected write shows as a success | The action returned `{ error }` | Throw with `fail()` |
|
||||
| `view-screen` reports `view: "chat"` on a domain page | `viewForPath` has no case for the route | Add the case |
|
||||
| The agent asks "which one?" on a detail page | The id isn't in `navigation` | Add it in `getNavigationState` |
|
||||
| The agent doesn't reach for the new actions | They aren't in `INITIAL_TOOL_NAMES` or `AGENTS.md` | Add them to both |
|
||||
| Sign-in lands on `/home` | `homePath` is unset, or set somewhere other than a server plugin | Set it with `defineAppConfig` in `server/plugins/` and restart dev |
|
||||
| Sign-in page during the smoke | The DB has a real user, `AGENT_NATIVE_DISABLE_AUTO_DEV_ACCOUNT=1`, or the server isn't loopback development | Use an existing local account or a separate disposable local DB; verify loopback dev and clear the opt-out. Don't create accounts or set `AUTH_DISABLED` |
|
||||
| Doctor reports an unscoped query | An ownable table is read without an access helper in that statement or block | Put `accessFilter(...)` in the query's `where`, or call `assertAccess` first in the same block |
|
||||
| `Named export 'IconX' not found` | The icon name was guessed | Grep the exact name in `node_modules/@tabler/icons-react/dist/tabler-icons-react.d.ts` |
|
||||
| A `@/components/ui/<x>` import fails | The starter doesn't ship that primitive | Add `export * from "@agent-native/toolkit/ui/<x>";` |
|
||||
| The UI doesn't update after an agent write | The page uses raw `useQuery`, not the action hooks | Switch to `useActionQuery` |
|
||||
| Two quick writes both succeed despite a rule | The check runs outside a transaction or without a lock | Use the lock-then-check pattern in `data-and-access.md` |
|
||||
|
||||
If you couldn't run a step (no browser tool, port blocked), say so in the
|
||||
report. Don't claim it passed.
|
||||
Reference in new issue
Block a user