@mortar-ai/skill 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/SKILL.md CHANGED
@@ -52,31 +52,39 @@ below; if platform provisioning fails, report that platform failure.
52
52
 
53
53
  1. Call `mortar_schema` before designing or changing backend data. It returns
54
54
  the current live schema, including console changes.
55
- 2. For each schema change, call `mortar_migrate` once with one operation. It
56
- applies the live change first; only after success does Fabric append a
57
- migration record under `mortar/migrations/`.
58
- 3. `mortar/migrations/` is a platform-owned output journal. Never create or edit
59
- SQL there: a file in that directory does not execute or change the live
60
- tenant. Do not edit or create `mortar.config.json`. Do not edit generated
61
- `integrations/mortar/types.ts`; Fabric regenerates it from the live schema.
62
- 4. Install or update `@mortar-ai/client` with npm when needed and let npm own the
55
+ 2. Author database schema as exact Mortar logical SQL and submit `{ name, sql }`
56
+ to `mortar_migrate`. Fabric asks Mortar to parse a language-neutral typed
57
+ plan, applies the workspace review policy, writes those exact bytes under
58
+ `mortar/migrations/` with source-revision CAS, then Mortar re-verifies the
59
+ checksum and expected schema revision and commits the whole plan atomically.
60
+ 3. Use `mortar_resource` for non-database desired state. Function source and its
61
+ manifest live under `mortar/functions/<name>/`; bucket policy lives under
62
+ `mortar/storage/buckets/`; cron schedules live under `mortar/cron/`. Fabric
63
+ writes the approved artifact before reconciling the live resource.
64
+ 4. These source directories are platform-protected because direct edits would
65
+ bypass plan/apply. Submit the exact source through the matching tool; do not
66
+ edit or create `mortar.config.json`. Do not edit generated
67
+ `integrations/mortar/types.ts`; Fabric regenerates it from the post-apply live
68
+ schema. The same schema can generate TypeScript, Swift, Kotlin, and Dart app
69
+ data types; those outputs are derived and never drive migration execution.
70
+ 5. Install or update `@mortar-ai/client` with npm when needed and let npm own the
63
71
  lockfile. Atomic batches, server-side filtered mutations, and
64
72
  `DatabaseTransactions` require version 0.8.0 or newer. Do not rewrite
65
73
  unrelated dependencies.
66
- 5. Before a multi-step mutation, choose the real consistency boundary. A
74
+ 6. Before a multi-step mutation, choose the real consistency boundary. A
67
75
  one-table batch or filtered mutation may use the public singleton;
68
76
  cross-table row + queue transactions require trusted server code; object
69
77
  storage and external services never join a PostgreSQL transaction.
70
- 6. Type-check and build. Handle every `{ data, error }` SDK result in UI code.
78
+ 7. Type-check and build. Handle every `{ data, error }` SDK result in UI code.
71
79
 
72
- Supported migration kinds are `create_table`, `drop_table`, `set_table_access`,
73
- `add_column`, `drop_column`, `create_index`, `set_bucket_access`,
74
- `deploy_function`, `delete_function`, `upsert_cron`, and `delete_cron`.
75
- Destructive and backend-changing operations must respect the workspace approval
76
- gate. This list is exhaustive: arbitrary PostgreSQL, data backfills, PL/pgSQL
77
- functions, transactions, and triggers are not migration inputs. If required
78
- behavior cannot be expressed by one of these operations, report the unsupported
79
- Mortar capability instead of authoring a SQL file that only looks executable.
80
+ Supported database DDL is `CREATE TABLE`, `DROP TABLE`, `ALTER TABLE … ADD/DROP
81
+ COLUMN`, `ALTER TABLE … SET ACCESS`, and `CREATE INDEX`. Put
82
+ `-- mortar:access public_insert` (or another access mode) immediately before a
83
+ `CREATE TABLE` when the default `public_read` is wrong. Resource kinds are
84
+ `set_bucket_access`, `deploy_function`, `delete_function`, `upsert_cron`, and
85
+ `delete_cron`; they belong to `mortar_resource`, never SQL. Destructive and
86
+ backend-changing operations respect the workspace approval gate. Arbitrary
87
+ PostgreSQL, data backfills, PL/pgSQL, transactions, and triggers are not inputs.
80
88
 
81
89
  ## Access and safety invariants
82
90
 
@@ -105,6 +113,9 @@ Agent Skills hosts resolve the same paths relative to this `SKILL.md`.
105
113
 
106
114
  - Database CRUD, atomic row mutations, trusted cross-table transactions, and
107
115
  exact ACID boundaries: `references/database.md`
116
+ - Versioned SQL syntax, checksums/revisions, resource artifact layout, type
117
+ generation, legacy migrations, and the complete capability-to-source matrix:
118
+ `references/schema-migrations.md`
108
119
  - App-user signup/signin, OTP, session lifecycle, and private-user modeling:
109
120
  `references/auth.md`
110
121
  - Upload/download/list/signed URLs, immutable object versions, CORS, and
@@ -138,7 +149,8 @@ sed -n '1,240p' /tmp/skills/mortar/references/storage.md
138
149
  ## Completion checklist
139
150
 
140
151
  - Live schema was read before schema design.
141
- - Every live schema change went through one approved `mortar_migrate` operation.
152
+ - Every database schema change used reviewed exact SQL through `mortar_migrate`;
153
+ every function/bucket/cron change used `mortar_resource`.
142
154
  - Application code imports only the platform-owned singleton.
143
155
  - No secret/admin client or hand-written fallback configuration entered the
144
156
  client bundle.
package/manifest.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "schema_version": 1,
3
3
  "id": "mortar",
4
- "version": "0.5.0",
5
- "content_sha256": "sha256:cbfe4219fa15934c523c1c22fe9795489539d0083d199624d2d15ac50bfe7755",
4
+ "version": "0.6.0",
5
+ "content_sha256": "sha256:f3cf01640a48dca83ccfe49a744c33355a5009567a1706d5c59528d6ddd3ee92",
6
6
  "source_repo": "liamxujia/appunvs",
7
7
  "source_path": "mortar/skill",
8
8
  "distributions": [
@@ -11,6 +11,6 @@
11
11
  ],
12
12
  "npm": {
13
13
  "package": "@mortar-ai/skill",
14
- "version": "0.5.0"
14
+ "version": "0.6.0"
15
15
  }
16
16
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mortar-ai/skill",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Agent skill package for building Fabric applications on Mortar (BaaS), with compact core guidance and on-demand references.",
5
5
  "main": "index.js",
6
6
  "files": ["SKILL.md", "references", "manifest.json", "index.js", "README.md"],
@@ -21,8 +21,8 @@ module, not a closed product taxonomy. A capability may span multiple
21
21
  application, primitive, account, or API packages, and one application module
22
22
  may support several capabilities.
23
23
 
24
- The current application modules are `auth`, `cron`, `data`, `files`, `queue`,
25
- `realtime`, and `secret`. Functions, comms, analytics,
24
+ The current application modules are `auth`, `cron`, `data`, `files`,
25
+ `migration`, `queue`, `realtime`, and `secret`. Functions, comms, analytics,
26
26
  accounts, and custom domains remain capabilities even when their implementation
27
27
  spans primitive, API, account, or other packages rather than a same-named
28
28
  application directory. `internal/usage` separately owns metering, quota,
@@ -5,7 +5,7 @@ or atomic row-plus-job workflows. Cron and queue are shipped capabilities whose
5
5
  runtime availability depends on configuration; they are not “planned extension
6
6
  slots.”
7
7
 
8
- Fabric provisions schedules only through one `mortar_migrate` operation:
8
+ Fabric provisions schedules only through one `mortar_resource` operation:
9
9
  `upsert_cron` creates or updates a schedule for an already deployed function,
10
10
  and `delete_cron` removes it. Direct cron list/create/patch/delete endpoints are
11
11
  trusted operator surfaces. Cron is normally enabled and can be disabled by the
@@ -5,12 +5,17 @@ function logs. Cron is in `automation.md`; analytics is in `analytics.md`.
5
5
 
6
6
  ## Deploy and invoke functions
7
7
 
8
- Deploy or delete functions only through one `mortar_migrate` operation with
8
+ Deploy or delete functions only through one `mortar_resource` operation with
9
9
  kind `deploy_function` or `delete_function`. Do not edit `mortar.config.json`,
10
- write migration files, or call operator/admin SDK methods from application
10
+ directly write the protected function directory, or call operator/admin SDK methods from application
11
11
  code. Function list/deploy/delete/logs are trusted project or account/operator
12
12
  surfaces; the app-bundle client exposes invocation only.
13
13
 
14
+ The desired-state directory contains `function.json` plus the runtime entrypoint:
15
+ `index.js` for Node-compatible runtimes and `index.py` for Python-compatible
16
+ runtimes. Switching runtime removes the stale entrypoint; deleting a function
17
+ removes the manifest, both entrypoint forms, and the legacy flat `.js` artifact.
18
+
14
19
  Client bundles may invoke a function that the platform already deployed:
15
20
 
16
21
  ```ts
@@ -0,0 +1,98 @@
1
+ # Schema migrations and resource artifacts
2
+
3
+ Read this reference when authoring backend source, reviewing a typed migration
4
+ plan, resolving revision/checksum conflicts, generating app-data types, or
5
+ deciding whether a Mortar capability belongs in source at all.
6
+
7
+ ## One canonical plan, four derived type targets
8
+
9
+ Mortar parses SQL into `mortar.migration-plan.v1`, a language-neutral JSON plan.
10
+ That plan—not TypeScript, Swift, Kotlin, or Dart code—is the execution contract.
11
+ After a successful apply, the canonical live schema may generate app-data models
12
+ for all four SDK languages. Generated models are downstream output; never edit
13
+ them to request a schema change.
14
+
15
+ ## Versioned database SQL
16
+
17
+ Submit exact SQL through `mortar_migrate`:
18
+
19
+ ```sql
20
+ -- mortar:access public_insert
21
+ CREATE TABLE submissions (
22
+ email text NOT NULL,
23
+ score integer,
24
+ metadata jsonb
25
+ );
26
+
27
+ ALTER TABLE submissions ADD COLUMN reviewed boolean NOT NULL;
28
+ CREATE INDEX submissions_reviewed ON submissions (reviewed, created_at);
29
+ ALTER TABLE submissions SET ACCESS app_only;
30
+ ```
31
+
32
+ The parser accepts common PostgreSQL type spellings and canonicalizes them to
33
+ Mortar's logical types: `text`, `number`, `bool`, `json`, `timestamp`, and
34
+ `uuid`. It rejects row data, backfills, triggers, stored procedures, transaction
35
+ control, and calls that pretend functions/storage/cron are SQL.
36
+
37
+ Plan/apply guarantees:
38
+
39
+ - SHA-256 covers the exact SQL bytes written to source.
40
+ - `migration_id + checksum` is idempotent; reusing an id with different bytes is
41
+ a conflict.
42
+ - Every tenant has a monotonic schema revision. Apply fails if the reviewed
43
+ `expected_revision` is stale.
44
+ - All logical schema operations and the revision ledger row commit in one
45
+ tenant-scoped PostgreSQL transaction.
46
+ - Source is written with Fabric's source-revision CAS before apply. If apply
47
+ fails, the file remains an honest pending migration that can be fixed or
48
+ retried; no live mutation is wrapped afterwards as fake SQL.
49
+
50
+ `DROP TABLE` removes its rows and `DROP COLUMN` removes the schema declaration;
51
+ both are destructive plan diagnostics. Changing access must use `ALTER TABLE …
52
+ SET ACCESS`, never drop/recreate.
53
+
54
+ ## Non-database desired state
55
+
56
+ Use `mortar_resource` so Fabric writes the exact artifact before reconciling the
57
+ live resource:
58
+
59
+ | Source path | Managed desired state |
60
+ |---|---|
61
+ | `mortar/functions/<name>/index.js` or `index.py` | Runtime-specific function source |
62
+ | `mortar/functions/<name>/function.json` | Runtime and authoritative entrypoint |
63
+ | `mortar/storage/buckets/<name>.json` | Bucket access policy |
64
+ | `mortar/cron/<name>.json` | Schedule, target function, enabled state |
65
+
66
+ Deleting a function or cron removes its current-state artifact. These resources
67
+ may call external systems and do not join a database migration transaction.
68
+
69
+ ## Complete capability-to-source matrix
70
+
71
+ “Mortar supports it” does not imply it should be a source artifact:
72
+
73
+ | Capability | Source authority | Why |
74
+ |---|---|---|
75
+ | Database tables/columns/access/index intent | Versioned SQL migration | Durable ordered schema with atomic revision ledger |
76
+ | Functions | Function directory | Executable source plus runtime metadata, not SQL |
77
+ | Bucket policy | Bucket JSON | Durable access policy; object bytes are runtime data |
78
+ | Cron schedules | Cron JSON | Durable desired schedule; executions are runtime state |
79
+ | Auth users/sessions/OTP/reset | None | Identity and credentials are runtime/security state |
80
+ | Database rows and row transactions | None | Application data, not schema |
81
+ | Stored files and signed URLs | None | Runtime objects and ephemeral authorization |
82
+ | Realtime row changes/broadcast/presence | None | Events and presence are runtime/ephemeral state |
83
+ | Queue jobs/claims/retries | None | Runtime work state; enqueue may join a row transaction |
84
+ | Analytics events/summaries | None | Runtime observations and derived reporting |
85
+ | Email/SMS sends | None | External side effects; make business workflows idempotent |
86
+ | Secret values | Encrypted Mortar secret store only | Values must never enter project source; source may document names in application-owned docs |
87
+ | Usage, logs, billing ledger | None | Platform observations and accounting authority |
88
+ | Projects, keys, PATs, domains, plans, capacity | None | Account/control-plane state |
89
+
90
+ ## Legacy projects
91
+
92
+ Do not automatically replay or rewrite an existing migration history merely
93
+ because this workflow shipped. Old files can describe already-live schema, and
94
+ some projects may keep explicit operator SQL under `mortar/operations/` for
95
+ capabilities outside Mortar logical DDL. Treat those files as legacy history;
96
+ new supported schema changes start at the next migration id. Arbitrary operator
97
+ SQL remains a separately reviewed operational path and is not silently claimed
98
+ as replayable Mortar migration source.
@@ -23,6 +23,11 @@ retryable cleanup. Never construct, persist, or expose an internal physical
23
23
  object key. Application projects do not run or author the platform storage
24
24
  migration.
25
25
 
26
+ Set durable bucket access through `mortar_resource`; Fabric writes
27
+ `mortar/storage/buckets/<name>.json` before reconciling the live policy. Object
28
+ bytes, logical object keys, signed URLs, and cleanup jobs remain runtime state
29
+ and never enter this source artifact.
30
+
26
31
  This protocol prevents Mortar metadata from pointing at a partial upload, but a
27
32
  separate application row and an object upload are not one transaction. Generate
28
33
  an unguessable logical key. For a simple workflow, upload first and write the