refactor: split repo into docs/ mockup/ app/
- move static mockups from resource/ui to mockup/ - move React app scaffold from resource/ui to app/ - move prome.md + images to docs/ - drop empty resource/jsonfile and resource/ - add root .gitignore - rewrite README for new layout - fix paths in mockup/index.html (resource/ui -> mockup, docs/prome.md)
This commit is contained in:
1 parent
8e87e47017
commit
92a2adad6a
133 files changed
+23416
-50
No files matched your search
@@ -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