aicms 0.0.0-stage → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/ARCHITECTURE.md +467 -0
  2. package/LICENSE +21 -0
  3. package/README.md +200 -2
  4. package/README.uk.md +201 -0
  5. package/dist/cli.d.ts +2 -0
  6. package/dist/cli.js +722 -0
  7. package/dist/config-edit.d.ts +18 -0
  8. package/dist/config-edit.js +201 -0
  9. package/dist/config.d.ts +55 -0
  10. package/dist/config.js +32 -0
  11. package/dist/edge.d.ts +22 -0
  12. package/dist/edge.js +56 -0
  13. package/dist/gates/a2a.d.ts +45 -0
  14. package/dist/gates/a2a.js +126 -0
  15. package/dist/gates/discovery.d.ts +36 -0
  16. package/dist/gates/discovery.js +54 -0
  17. package/dist/gates/events.d.ts +14 -0
  18. package/dist/gates/events.js +86 -0
  19. package/dist/gates/graphql.d.ts +41 -0
  20. package/dist/gates/graphql.js +226 -0
  21. package/dist/gates/mcp.d.ts +8 -0
  22. package/dist/gates/mcp.js +60 -0
  23. package/dist/gates/openapi.d.ts +56 -0
  24. package/dist/gates/openapi.js +61 -0
  25. package/dist/gates/rest.d.ts +21 -0
  26. package/dist/gates/rest.js +263 -0
  27. package/dist/gates/studio.d.ts +21 -0
  28. package/dist/gates/studio.js +107 -0
  29. package/dist/index.d.ts +18 -0
  30. package/dist/index.js +19 -0
  31. package/dist/kernel/action.d.ts +49 -0
  32. package/dist/kernel/action.js +22 -0
  33. package/dist/kernel/briefs.d.ts +161 -0
  34. package/dist/kernel/briefs.js +197 -0
  35. package/dist/kernel/changesets.d.ts +367 -0
  36. package/dist/kernel/changesets.js +765 -0
  37. package/dist/kernel/cms.d.ts +127 -0
  38. package/dist/kernel/cms.js +419 -0
  39. package/dist/kernel/core-actions.d.ts +5 -0
  40. package/dist/kernel/core-actions.js +487 -0
  41. package/dist/kernel/errors.d.ts +14 -0
  42. package/dist/kernel/errors.js +25 -0
  43. package/dist/kernel/install.d.ts +32 -0
  44. package/dist/kernel/install.js +34 -0
  45. package/dist/kernel/model-actions.d.ts +5 -0
  46. package/dist/kernel/model-actions.js +126 -0
  47. package/dist/kernel/modules.d.ts +221 -0
  48. package/dist/kernel/modules.js +207 -0
  49. package/dist/kernel/policy.d.ts +42 -0
  50. package/dist/kernel/policy.js +47 -0
  51. package/dist/load.d.ts +10 -0
  52. package/dist/load.js +63 -0
  53. package/dist/modules/catalog.d.ts +15 -0
  54. package/dist/modules/catalog.js +21 -0
  55. package/dist/modules/commerce.d.ts +67 -0
  56. package/dist/modules/commerce.js +260 -0
  57. package/dist/modules/git-sync.d.ts +20 -0
  58. package/dist/modules/git-sync.js +187 -0
  59. package/dist/modules/i18n.d.ts +6 -0
  60. package/dist/modules/i18n.js +168 -0
  61. package/dist/modules/index.d.ts +9 -0
  62. package/dist/modules/index.js +10 -0
  63. package/dist/modules/lint.d.ts +22 -0
  64. package/dist/modules/lint.js +126 -0
  65. package/dist/modules/media.d.ts +52 -0
  66. package/dist/modules/media.js +319 -0
  67. package/dist/modules/payments.d.ts +19 -0
  68. package/dist/modules/payments.js +110 -0
  69. package/dist/modules/search.d.ts +27 -0
  70. package/dist/modules/search.js +81 -0
  71. package/dist/modules/seo.d.ts +34 -0
  72. package/dist/modules/seo.js +189 -0
  73. package/dist/modules/text.d.ts +10 -0
  74. package/dist/modules/text.js +42 -0
  75. package/dist/node.d.ts +7 -0
  76. package/dist/node.js +11 -0
  77. package/dist/registry.d.ts +57 -0
  78. package/dist/registry.js +110 -0
  79. package/dist/schema/fields.d.ts +100 -0
  80. package/dist/schema/fields.js +134 -0
  81. package/dist/schema/markdown.d.ts +7 -0
  82. package/dist/schema/markdown.js +168 -0
  83. package/dist/schema/model.d.ts +44 -0
  84. package/dist/schema/model.js +104 -0
  85. package/dist/schema/slug.d.ts +2 -0
  86. package/dist/schema/slug.js +40 -0
  87. package/dist/store/d1.d.ts +30 -0
  88. package/dist/store/d1.js +27 -0
  89. package/dist/store/postgres.d.ts +164 -0
  90. package/dist/store/postgres.js +552 -0
  91. package/dist/store/sql.d.ts +135 -0
  92. package/dist/store/sql.js +530 -0
  93. package/dist/store/sqlite.d.ts +14 -0
  94. package/dist/store/sqlite.js +60 -0
  95. package/dist/store/types.d.ts +226 -0
  96. package/dist/store/types.js +21 -0
  97. package/dist/studio/assets/geologica-cyrillic-ext-wght-normal-C8B9Chlh.woff2 +0 -0
  98. package/dist/studio/assets/geologica-cyrillic-wght-normal-DbeVG3Ps.woff2 +0 -0
  99. package/dist/studio/assets/geologica-greek-wght-normal-DPM5d9ub.woff2 +0 -0
  100. package/dist/studio/assets/geologica-latin-ext-wght-normal-DZyYlgcm.woff2 +0 -0
  101. package/dist/studio/assets/geologica-latin-wght-normal-BBL8hQxZ.woff2 +0 -0
  102. package/dist/studio/assets/geologica-vietnamese-wght-normal-DcI17N1q.woff2 +0 -0
  103. package/dist/studio/assets/index-3dJ0YHxb.js +22 -0
  104. package/dist/studio/assets/index-DuyGLFw4.css +1 -0
  105. package/dist/studio/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2 +0 -0
  106. package/dist/studio/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2 +0 -0
  107. package/dist/studio/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
  108. package/dist/studio/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
  109. package/dist/studio/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
  110. package/dist/studio/assets/unbounded-cyrillic-wght-normal-C627f1f8.woff2 +0 -0
  111. package/dist/studio/assets/unbounded-latin-ext-wght-normal-D6H-S6MW.woff2 +0 -0
  112. package/dist/studio/assets/unbounded-latin-wght-normal-D5afBTBx.woff2 +0 -0
  113. package/dist/studio/assets/unbounded-vietnamese-wght-normal-rat7GD3o.woff2 +0 -0
  114. package/dist/studio/index.html +21 -0
  115. package/dist/typegen.d.ts +7 -0
  116. package/dist/typegen.js +55 -0
  117. package/package.json +88 -4
@@ -0,0 +1,467 @@
1
+ # AICMS — architecture
2
+
3
+ > A CMS where AI agents are first-class users and people are the editors and owners.
4
+ > Describe a model once and get REST, MCP tools, an admin and types.
5
+
6
+ Status: v0.4 · phase 3 works: Postgres, Cloudflare Workers with D1 and R2, real-time presence, a module registry, A2A and commerce, on top of phases 0–2 · [Українською](ARCHITECTURE.uk.md)
7
+
8
+ ---
9
+
10
+ ## 1. Why
11
+
12
+ WordPress grew out of a 2003 blog engine: thousands of core files, `wp_posts` + `wp_postmeta` instead of schemas, global hooks with priorities, a REST API bolted on later, and an admin that agents have to scrape. Agents need something else:
13
+
14
+ - **explicit schemas**, so they know what they may write;
15
+ - **typed tools** instead of HTML forms;
16
+ - **permission boundaries**, so an agent can't do more than intended;
17
+ - **drafts and rollback**, so an agent's mistake breaks nothing.
18
+
19
+ AICMS is built around those four needs. People get the same system through Studio, which makes it simpler for them too.
20
+
21
+ ## 2. Principles
22
+
23
+ 1. **One schema, everything else generated.** A model is described once in TypeScript. Tables, validation, REST, MCP tools, Studio forms, frontend types and agent docs all come from it.
24
+ 2. **Every operation is an Action.** Creating an entry, generating alt text, running an SEO audit: one shape with an input/output schema, scopes and hooks. Gates (MCP, REST, SDK, Studio) only call Actions.
25
+ 3. **Agents never write to production directly.** An agent's changes go into a changeset, pass checks and review, and only then get published. Every event is logged, so anything can be rolled back.
26
+ 4. **A module is one folder with one manifest.** It declares what it provides (`provides`) and what it needs (`requires`). No global hook soup.
27
+ 5. **As few files as possible.** A project is `aicms.config.ts`, a `models/` folder and, if needed, `modules/`. Everything generated lives in `.aicms/` and is never committed.
28
+ 6. **Headless, with first-class adapters.** Next.js, Nuxt, SvelteKit, Astro, React Router, Angular, Expo: a typed client, live preview, cache revalidation.
29
+ 7. **Web standards.** The kernel speaks `Request/Response`, so it runs on Node, Bun, Deno and Cloudflare Workers.
30
+
31
+ ## 3. Vocabulary: seven concepts
32
+
33
+ | Concept | What it is | Example |
34
+ |---|---|---|
35
+ | **Model** | A content type's schema plus instructions for agents | `post`, `product`, `review` |
36
+ | **Entry** | One record of a model, with its version history | “How to choose SPF for winter” |
37
+ | **Block** | A brick inside rich content | `paragraph`, `image`, `cta` |
38
+ | **Action** | Any operation with a typed input, output and scopes | `post.draft`, `seo.audit` |
39
+ | **Module** | A package of models, blocks, Actions, hooks and Studio panels | `seo`, `commerce`, `reviews` |
40
+ | **Agent** | An agent identity with scopes, a budget and a review mode | `writer`, `seo`, `moderator` |
41
+ | **Changeset** | A set of proposed changes waiting for checks and review | “writer: 3 new posts” |
42
+
43
+ There is nothing else to learn.
44
+
45
+ ## 4. Layers
46
+
47
+ ```
48
+ ┌──────────────────────────────────────────────────────────────┐
49
+ │ Agents (Claude, GPT, Gemini, your own) People (Studio) │
50
+ └───────────────┬──────────────────────────────────┬───────────┘
51
+ │ │
52
+ ┌───────────────▼──────────────────────────────────▼───────────┐
53
+ │ GATES MCP · REST + OpenAPI · GraphQL · SDK · Events · A2A │
54
+ │ (all generated from the Action registry) │
55
+ └───────────────┬──────────────────────────────────────────────┘
56
+ │ calls an Action
57
+ ┌───────────────▼──────────────────────────────────────────────┐
58
+ │ KERNEL │
59
+ │ Schema Engine → Action Bus → Policy (scopes, budgets, review) │
60
+ │ Content Store (entries, versions, changesets, event log) │
61
+ │ Module Loader (provides / requires, isolation) │
62
+ └───────┬───────────────────────────────┬──────────────────────┘
63
+ │ │
64
+ ┌───────▼─────────┐ ┌────────▼───────────────────────┐
65
+ │ MODULES │ │ ADAPTERS │
66
+ │ seo, i18n, │ │ DB: SQLite · Postgres · libSQL │
67
+ │ media, search, │ │ Media: local · S3 · R2 │
68
+ │ commerce, … │ │ Vector: sqlite-vec · pgvector │
69
+ └─────────────────┘ └────────────────────────────────┘
70
+ ```
71
+
72
+ ### 4.1 Schema Engine
73
+ - Reads models from `models/*.ts` and from modules.
74
+ - Produces JSON Schema for every model and every Action, OpenAPI, the agent manifest and `llms.txt`. TypeScript types: inside the CMS project they are inferred straight from the model (`InferModel<typeof post>`); a frontend in another repository gets them from `aicms types`, which `@aicms/client` takes as a type parameter.
75
+ - Validation uses Zod 4 (a Standard Schema implementation), so the same schema works on the server and in the browser.
76
+
77
+ ### 4.2 Action Bus
78
+ - A registry of every Action: kernel Actions (`cms.describe`, `cms.submit`…), the four generated per model (`post.list`, `post.get`, `post.draft`, `post.delete`) and module Actions.
79
+ - Every call runs through one pipeline:
80
+ `validate input → policy check → budget → run → event log → emit event`.
81
+ - Every gate (MCP, REST, CLI, Studio) is a thin wrapper over this pipeline, so behaviour is identical for people and agents.
82
+
83
+ ### 4.3 Policy
84
+ - **Scopes:** `post:read`, `post:draft` (create + update), `post:update.seo` (one field), `post:delete`, `post:*`, `changesets:review`, `agents:manage`, `events:read`, `briefs:write`, `*`. Module Actions declare their own scopes, e.g. `reviews:write`.
85
+ - **Field-level tool schemas:** a draft tool only lists the fields the agent may write. With `post:update.seo` the agent's `post_draft` tool contains `id` and `seo` and nothing else.
86
+ - **Review mode** per agent: `human` (a person approves), `auto` (merged when every check is green and no model requires a person), or a rule, `{ auto: ["post:update.seo", "tag:create"] }`: merged without a person only when every change is covered by those scopes. The default is `human`. A check warning always sends the change to a person.
87
+ - **The model has the last word:** if a model's `agent.can` doesn't include `publish`, any agent changeset that touches it waits for a person, whatever the agent's review mode.
88
+ - **Budgets:** `actionsPerHour` and `maxChangesetItems`.
89
+ - **Kill switch:** `aicms agent revoke <name>` revokes the agent's tokens and rejects all its unmerged changesets.
90
+
91
+ ### 4.4 Content Store
92
+ Six core tables, however many models you have:
93
+
94
+ | Table | Purpose |
95
+ |---|---|
96
+ | `entries` | current state: `id, model, locale, data (JSON), version` |
97
+ | `versions` | immutable history of every entry |
98
+ | `changesets` | branches of changes from agents and people |
99
+ | `events` | log of every Action: who, what, when, through which gate |
100
+ | `media` | files, metadata, alt text |
101
+ | `tokens` | agent tokens, stored only as SHA-256 hashes |
102
+
103
+ Fields marked `indexed: true` or `unique: true` get expression indexes (`json_extract(data, '$.slug')` in SQLite, `data->'slug'` on Postgres JSONB). Modules keep small values in a `kv` table; the search module keeps its own term index.
104
+
105
+ One `Store` interface, three adapters, and the whole test suite runs on each:
106
+
107
+ | `db:` | Where | Notes |
108
+ |---|---|---|
109
+ | `sqlite(".aicms/data.db")` | servers, the default | `node:sqlite`, nothing to install |
110
+ | `postgres({ url })` | servers | JSONB; `npm install pg`; merges in one transaction with row locks |
111
+ | `d1("DB")` | Cloudflare Workers | merges are planned, then applied in one atomic batch; the versions primary key catches concurrent changes |
112
+
113
+ ### 4.5 Module Loader
114
+ - Modules are listed in `aicms.config.ts`.
115
+ - The `requires → provides` graph is checked at startup and on `aicms add`.
116
+ - A module only sees its own models and the ones it lists in `uses`. A module's permissions are shown on install, like a phone app's.
117
+
118
+ ## 5. Project structure
119
+
120
+ ```
121
+ my-site/
122
+ ├── aicms.config.ts # DB, locales, modules, agents
123
+ ├── models/
124
+ │ ├── post.ts
125
+ │ └── tag.ts
126
+ ├── modules/ # optional: your own modules
127
+ │ └── reviews/
128
+ │ └── module.ts
129
+ └── .aicms/ # generated: database, cache (in .gitignore)
130
+ ```
131
+
132
+ ### 5.1 Config
133
+
134
+ ```ts
135
+ // aicms.config.ts
136
+ import { defineConfig, sqlite } from "aicms"
137
+
138
+ export default defineConfig({
139
+ db: sqlite(".aicms/data.db"), // postgres() comes in phase 3
140
+ locales: ["en", "uk"],
141
+ public: ["post:read", "tag:read"], // what anonymous requests may do
142
+ agents: {
143
+ writer: { scopes: ["post:draft", "tag:draft"], review: "human" },
144
+ seo: { scopes: ["post:update.seo"], review: "auto" },
145
+ moderator: { scopes: ["reviews:write"], budget: { actionsPerHour: 500 } },
146
+ },
147
+ webhooks: [{ url: "https://my-site.com/api/revalidate", events: ["changeset.merged"] }],
148
+ })
149
+ ```
150
+
151
+ Models are loaded from `models/` automatically; pass `models: [...]` to list them explicitly.
152
+
153
+ ### 5.2 Model
154
+
155
+ ```ts
156
+ // models/post.ts
157
+ import { defineModel, field } from "aicms"
158
+
159
+ export default defineModel({
160
+ name: "post",
161
+ label: "Posts",
162
+ fields: {
163
+ title: field.text({ required: true, max: 120 }),
164
+ slug: field.slug({ from: "title" }), // unique and indexed by default
165
+ cover: field.media(),
166
+ body: field.blocks(["paragraph", "heading", "image", "quote", "cta"]),
167
+ tags: field.ref("tag", { many: true }),
168
+ publishedAt: field.date({ indexed: true }),
169
+ },
170
+ agent: {
171
+ guide: "Short sentences, friendly expert tone. No clichés.",
172
+ can: ["create", "update"], // publishing stays with a person
173
+ },
174
+ })
175
+ ```
176
+
177
+ The `agent` block is the key difference from classic CMSs: instructions for agents live next to the schema. Agents receive them together with their tool list.
178
+
179
+ ## 6. Modules: like Lego
180
+
181
+ ### 6.1 Anatomy
182
+
183
+ ```ts
184
+ // modules/reviews/module.ts
185
+ import { defineModule, defineModel, field, action } from "aicms"
186
+
187
+ export default defineModule({
188
+ name: "reviews",
189
+ provides: ["reviews"],
190
+ requires: ["commerce"], // any implementation of commerce
191
+ uses: ["product"], // other models this module may touch
192
+
193
+ models: [
194
+ defineModel({
195
+ name: "review",
196
+ fields: {
197
+ product: field.ref("product"),
198
+ rating: field.number({ min: 1, max: 5, required: true }),
199
+ text: field.text(),
200
+ status: field.enum(["pending", "published", "rejected"]),
201
+ },
202
+ }),
203
+ ],
204
+
205
+ actions: {
206
+ moderate: action({
207
+ description: "Approve or reject a review",
208
+ scope: "reviews:write",
209
+ input: { id: field.id({ required: true }), ok: field.boolean({ required: true }) },
210
+ run: ({ input, ctx }) =>
211
+ ctx.draft("review", { id: input.id, status: input.ok ? "published" : "rejected" }),
212
+ }),
213
+ },
214
+
215
+ on: {
216
+ "changeset.merged": ({ payload, ctx }) => { /* notify, reindex, … */ },
217
+ },
218
+ })
219
+ ```
220
+
221
+ Inside `run`, `ctx` writes through the caller's changeset, so a module Action can never bypass review. Its reads include the caller's own drafts, so a module can check work before it is submitted.
222
+
223
+ A module may also have:
224
+
225
+ | Part | What it does | Example |
226
+ |---|---|---|
227
+ | options | modules are usually factories: `seo({ siteUrl })` | `aicms.config.ts` |
228
+ | `setup(ctx)` | runs once at start or install | build an index |
229
+ | `services` | the implementation of a capability in `provides` | `search` answers `cms.search` |
230
+ | `routes` | HTTP routes, `"GET /sitemap.xml"`, with `:params` | `/media/:id/:name` |
231
+ | `ctx.kv` | small JSON values that belong to the module | translation groups |
232
+ | `ctx.pending(id)` | someone's unpublished draft of an entry | "already waiting for review" |
233
+ | `checks` | content checks on every change to the models the module `uses`: errors block, warnings go to the reviewer | `lint` finds "[insert price]" |
234
+
235
+ Everything a module asks for is listed in its manifest (`cms_modules`, `aicms modules`, Studio): models it adds and uses, Actions with their scopes, routes and hooks. Modules can be installed into a running server; their tools, routes and GraphQL types appear at once.
236
+
237
+ ```bash
238
+ aicms add seo # an official module
239
+ aicms add ./modules/reviews # a local folder
240
+ aicms add @someone/aicms-x # an npm package (npm install + config)
241
+ aicms module new reviews # scaffold modules/reviews/module.ts
242
+ aicms remove seo # its data stays in the database
243
+ ```
244
+
245
+ `aicms add` writes the import and the entry in `modules`, pulls in official modules that provide what the new one requires, checks that the project still starts, and puts the file back if it doesn't.
246
+
247
+ ### 6.2 Capabilities instead of package dependencies
248
+
249
+ A module asks for a capability, not a package:
250
+
251
+ | `requires` | Who can provide it |
252
+ |---|---|
253
+ | `payments` | `stripe`, `paddle`, `adyen` |
254
+ | `shipping` | `dhl`, `ups`, `fedex` |
255
+ | `search` | `search-sqlite`, `search-pg`, `meilisearch` |
256
+ | `ai.image` | `openai-images`, `flux`, `local-sd` |
257
+
258
+ So modules can be swapped without rewriting the rest.
259
+
260
+ ### 6.3 Official modules
261
+
262
+ Shipped in phase 2 (`import { seo, search, media, i18n, gitSync } from "aicms/modules"`):
263
+
264
+ | Module | What it gives agents and people |
265
+ |---|---|
266
+ | `seo` | `seo_audit`: a 0–100 score with concrete fixes (title and description length, slug, word count, heading order, image alt text, internal links), working on drafts; `seo_report` for a whole model; `sitemap.xml` and `robots.txt` |
267
+ | `search` | ranked full-text search in any language (TF-IDF, title boost, prefix matching) on a portable index; `cms_search` uses it as soon as it is installed |
268
+ | `media` | a media library: uploads, imports from URLs (private networks blocked), image sizes, alt text an agent can fill in, inert SVG, files under `/media` |
269
+ | `i18n` | translation groups across locales, what's missing per locale, `i18n_translate` drafts a translation that goes through review |
270
+ | `git-sync` | published content mirrored to Markdown with frontmatter; edited files come back as a changeset (`aicms sync import`), so pull requests can feed the Inbox |
271
+
272
+ Added in phase 3:
273
+
274
+ | Module | What it gives |
275
+ |---|---|
276
+ | `commerce` | products and orders, a public checkout that prices on the server, stock, order statuses with history, `commerce_orders` / `commerce_set_status` / `commerce_stats`; requires `payments` |
277
+ | `manual-payments` | provides `payments`: bank transfer or cash on delivery, a person marks orders paid |
278
+ | `stripe` | provides `payments`: Stripe Checkout, signed webhooks, refunds |
279
+
280
+ Payment providers report through a `payment.updated` event, so swapping Stripe for another provider doesn't touch commerce.
281
+
282
+ Added in phase 4:
283
+
284
+ | Module | What it gives |
285
+ |---|---|
286
+ | `lint` | checks on every change: placeholders an agent left behind ("[insert price]", TODO, lorem ipsum) block the changeset; filler phrases ("delve", "it's important to note"), very long sentences, empty headings, images without alt text and dead links are warnings. The phrase list is yours to change. |
287
+
288
+ `seo` also became a check: problems its audit finds in the fields a change touches reach the reviewer as warnings.
289
+
290
+ Next: `forms` · `reviews` · `redirects` · `analytics`, multi-step workflows built on briefs, vector search and AI image tools.
291
+
292
+ ### 6.4 Agents proposing modules
293
+ An agent may propose installing a module. The proposal arrives in Inbox as a changeset of a special kind, listing the scopes and models the module asks for. A person with the `modules:install` scope installs it from the Inbox (`cms_propose_module`, then Approve); agents never install code themselves. A declined proposal is closed, not reopened.
294
+
295
+ ### 6.5 Registry
296
+
297
+ `docs/registry.json` (served at `https://malkovych.github.io/aicms/registry.json`) lists official and community modules with what each declares: provides, requires, uses, scopes, routes, hooks. `aicms search <words>` finds modules; `aicms add <name>` installs a community module from npm and refuses it if its manifest asks for more than its entry declares. Community modules are added in a terminal, where the code can be reviewed; the server never installs them by itself, and agents can only propose official modules. To list a module, open a pull request that adds its entry.
298
+
299
+ ## 7. Connecting agents
300
+
301
+ ### 7.1 Gates
302
+
303
+ | Gate | For | Address | Phase |
304
+ |---|---|---|---|
305
+ | **MCP** | Claude, Cursor, ChatGPT, any MCP client | `POST /mcp` (Streamable HTTP) or `aicms mcp` (stdio) | 0 |
306
+ | **REST + OpenAPI** | function calling in any LLM, n8n, scripts | `/api/v1/*`, `/openapi.json` | 0 |
307
+ | **Discovery** | anyone | `/llms.txt`, `/.well-known/aicms.json` | 0 |
308
+ | **Webhooks** | frontends, automations | `webhooks` in config | 0 |
309
+ | **SDK** | your own agents | `@aicms/client` (TS), `aicms` (PyPI) | 1 |
310
+ | **SSE events** | agents that react to changes | `/api/v1/events` | 1 |
311
+ | **GraphQL** | frontends with complex queries; references resolve to entries | `/graphql` | 2 ✓ |
312
+ | **A2A** | agent-to-agent: an Agent Card and JSON-RPC, every Action a skill | `/.well-known/agent-card.json`, `/a2a` | 3 ✓ |
313
+
314
+ ### 7.2 Tools an agent sees
315
+
316
+ An agent only sees what its scopes allow. MCP tool names use underscores (`post_draft`) because several LLM APIs reject dots in tool names; the Action is still called `post.draft` in REST and code.
317
+
318
+ | Tool | Action | What it does |
319
+ |---|---|---|
320
+ | `cms_describe` | `cms.describe` | models, fields, guides, the agent's own scopes and review mode |
321
+ | `cms_search` | `cms.search` | full-text search across readable models |
322
+ | `<model>_list` | `<model>.list` | filter by indexed fields, select fields, paginate |
323
+ | `<model>_get` | `<model>.get` | one entry by `id` or by a unique field such as `slug`; `drafts: true` includes your unpublished changes |
324
+ | `<model>_draft` | `<model>.draft` | create or change an entry inside the agent's changeset |
325
+ | `<model>_delete` | `<model>.delete` | propose deleting an entry |
326
+ | `cms_check` | `cms.check` | run every check on the drafts without submitting: errors, warnings and what submitting would do |
327
+ | `cms_submit` | `cms.submit` | run checks and send the changeset for review; `brief` links it to a brief, `publishAt` asks for a publish time |
328
+ | `cms_changes` | `cms.changes` | the agent's changesets, check results and reviewer comments |
329
+ | `cms_briefs` / `cms_brief_update` | `cms.briefs` … | the agent's briefs; take one, ask a question, give it back, finish it |
330
+ | `cms_brief` | `cms.brief` | write or change a brief: people and planning agents (`briefs:write`) |
331
+ | `cms_review` / `cms_merge` / `cms_reject` / `cms_unschedule` | `cms.review` … | for reviewers with `changesets:review`; `cms_merge({ at })` schedules |
332
+ | `cms_history` / `cms_restore` / `cms_revert` | `cms.history` … | an entry's versions; draft the restore of any version, or the undo of a merged changeset |
333
+ | `cms_discard` | `cms.discard` | drop drafts that weren't submitted |
334
+ | `cms_presence` | `cms.presence` | who is viewing or editing an entry right now, and whose drafts of it would conflict |
335
+ | `cms_modules` / `cms_propose_module` | `cms.modules` … | installed modules with their permissions, official ones to propose; `cms_install_module` for admins (`modules:install`) |
336
+ | `cms_agents` / `cms_token` / `cms_revoke` / `cms_log` | `cms.agents` … | for admins (`agents:manage`, `events:read`): agents, tokens, the action log |
337
+ | `<module>_<action>` | `<module>.<action>` | module Actions |
338
+
339
+ ### 7.3 Markdown in, blocks in the database
340
+ Agents read and write Markdown comfortably; people need a visual editor. AICMS stores blocks, and a `blocks` field accepts either a block array or Markdown with directive blocks (`:::cta{href="/sale" label="Shop now"}`). Over MCP, block fields are returned as Markdown by default; REST returns blocks. Same data, each side gets its own interface.
341
+
342
+ ### 7.4 Saving context
343
+ - `cms_describe` without arguments is brief; with `{ model }` it is detailed.
344
+ - Field selection: `post_get({ slug, fields: ["title", "slug"] })`.
345
+ - Compact responses without service noise.
346
+
347
+ ### 7.5 The path of an agent's change
348
+ 1. **Connect.** The agent arrives with a token and gets its tool list.
349
+ 2. **Learn.** `cms_describe` returns schemas, guides and examples, and says how many briefs wait for the agent.
350
+ 3. **Take the work.** `cms_briefs` lists what people asked for; `cms_brief_update` takes a brief or asks a question.
351
+ 4. **Draft.** Changes are written into a changeset; production is untouched.
352
+ 5. **Check.** `cms_check` (any time) and `cms_submit` run schema, uniqueness, reference and conflict checks, then the modules' checks. Errors come back to the agent with field-level messages; warnings travel with the changeset to the reviewer.
353
+ 6. **Review.** Automatic, or a person in Studio Inbox (or `aicms changes`, `aicms merge`, `aicms reject`). A rejection comment goes back to the agent through `cms_changes`, the `changeset.rejected` event and the brief's notes.
354
+ 7. **Publish.** Now, or at a time: merge writes new entry versions, logs the event and fires webhooks. A scheduled changeset is checked again when its time comes and goes back to its author if something changed meanwhile. Merging closes the brief.
355
+ 8. **Roll back.** Any version of an entry can be restored (`cms_restore`, or History in Studio), and a merged changeset can be undone as a whole (`cms_revert`). Both are drafted and published like any other change, so they are checked, reviewed and logged too.
356
+
357
+ ### 7.6 Briefs, checks and schedules
358
+
359
+ **Briefs** are work for agents: a title, details in Markdown, the agent (or any agent), what to produce, a due date and a publish time. People write them in Studio or with `aicms brief`; an agent with `briefs:write` can plan for others. Briefs and their notes live in kernel storage and travel as `brief.created` / `brief.updated` events to the agent they are for, over SSE and webhooks, so an agent runner can wake up when work arrives. Statuses: open → in progress → (has a question) → in review → done, or canceled.
360
+
361
+ **Checks** are module code: `checks: { name: ({ op, model, data, before, changed, author }, ctx) => findings }`. They run on submit and again before merging, only for the models the module `uses`. A good check looks only at the fields the change touches, so fixing a typo doesn't drag up old problems. A check that throws becomes a warning instead of blocking content.
362
+
363
+ **Schedules**: `cms_submit({ publishAt })` asks, `cms_merge({ at })` decides, `cms_unschedule` takes it back. `aicms dev` / `start` publishes due changesets every 30 seconds; on Cloudflare a cron trigger calls the Worker's `scheduled` handler (requests check once a minute as a fallback); `aicms publish-due` serves any other cron.
364
+
365
+ Changesets keep warnings, the publish time, who scheduled it and the brief in one JSON column, so the next field needs no migration on SQLite, D1 or Postgres.
366
+
367
+ ## 8. Studio: for people
368
+
369
+ Studio is served by the kernel at `/studio/`. You sign in with a one-time link from the terminal (`aicms login`; `aicms dev` prints one when it starts), which becomes a 30-day session cookie, so there is no password to leak. Studio calls the same Actions as agents through the same pipeline; its writes are logged with the gate `studio`.
370
+
371
+ Shipped in phase 1:
372
+
373
+ - **Inbox.** Changesets from agents with a word-level before/after diff, failed checks, and Approve / Request changes (the comment goes back to the agent) / Close. A merged changeset can be undone in one click.
374
+ - **Content.** Lists and forms generated from schemas: every field kind has an input, block fields get a Markdown editor with a live preview. Every entry has its history; any version can be opened and restored.
375
+ - **Agents.** Scopes, review mode, budget use, last activity and pending work. Issue a token (shown once, with the MCP command to connect) or revoke access.
376
+ - **Activity.** The action log of people and agents, live over SSE.
377
+ - English and Ukrainian, light and dark themes, phone-sized screens.
378
+
379
+ Added in phase 2: **Media** (a library with drag-and-drop upload and alt text), **Modules** (manifests and one-click install), module proposals in **Inbox**, a media picker in forms, and SEO and translation panels beside each entry.
380
+
381
+ Added in phase 3: **presence**. The editor shows who else is on an entry, people and agents (an agent drafting a change appears as editing it), and warns when someone else's draft of it would conflict.
382
+
383
+ Added in phase 4: **Briefs** (write work for agents, answer their questions in the notes), a **Scheduled** tab and check warnings in **Inbox**, "Schedule…" in Inbox and in the editor, and **⌘K**: a command palette for pages, models, new entries and briefs, with full-text search over entries.
384
+
385
+ Next: plain-language commands in ⌘K (“find posts without a cover” → `post.list` with a filter), co-editing with Yjs, a block editor beside the frontend's live preview, and roles for people other than the owner.
386
+
387
+ ## 9. Frameworks
388
+
389
+ | Adapter | What you get | Status |
390
+ |---|---|---|
391
+ | `@aicms/client` | typed client for any runtime with `fetch`, live events, `blocksToHtml` | phase 1 ✓ |
392
+ | `@aicms/next` | reads cached with per-model tags, `revalidateTag` from webhooks, `<Blocks />` for Server Components | phase 1 ✓ (Draft Mode preview next) |
393
+ | `@aicms/astro` | Content Layer loader with pre-rendered blocks | phase 1 ✓ |
394
+ | `aicms` (PyPI) | Python client, standard library only | phase 1 ✓ |
395
+ | `@aicms/nuxt` | a Nuxt module: `useAicms`, `useAicmsData`, a signed webhook that clears Nitro's page cache | phase 2 ✓ |
396
+ | `@aicms/sveltekit` | load helpers on SvelteKit's `fetch` with `depends`, cache headers, live `invalidate` on publish | phase 2 ✓ |
397
+ | `@aicms/react-router` | loaders for React Router 7 / Remix | later |
398
+ | `@aicms/angular` | services and resolvers | later |
399
+ | `@aicms/expo` | mobile client with an offline cache | later |
400
+
401
+ Common to all: a client typed from your schemas (`aicms types`), a `<Blocks />` component or `blocksToHtml`, and later an image component and a visual-editing overlay.
402
+
403
+ ```tsx
404
+ // lib/cms.ts
405
+ import { createAicms } from "@aicms/next"
406
+ import type { Schema } from "./aicms-types" // npx aicms types --out lib/aicms-types.ts
407
+ export const cms = createAicms<Schema>({ url: process.env.AICMS_URL! })
408
+
409
+ // app/blog/[slug]/page.tsx
410
+ import { Blocks } from "@aicms/next"
411
+ import { cms } from "@/lib/cms"
412
+
413
+ export default async function Post({ params }) {
414
+ const post = await cms.post.get({ slug: (await params).slug }) // typed from models/post.ts
415
+ return <Blocks value={post.body} />
416
+ }
417
+ ```
418
+
419
+ Deployment modes:
420
+ - **Embedded:** AICMS mounts as a route handler inside Next.js / Nuxt / SvelteKit. One deploy.
421
+ - **Standalone:** `aicms start` or a Docker image.
422
+ - **Edge:** Cloudflare Workers + D1 + R2: `export default createWorker(config)` from `aicms/edge`, Studio from Workers Assets, the owner token from a secret (`examples/edge`).
423
+
424
+ ## 10. Kernel stack
425
+
426
+ | Layer | Choice | Why |
427
+ |---|---|---|
428
+ | Language | TypeScript | types end to end, from schema to frontend |
429
+ | Database | `node:sqlite`, Postgres, D1 | SQLite built into Node 22+; Postgres (JSONB) and Cloudflare D1 behind the same `Store` interface |
430
+ | HTTP | Hono | runs on any runtime, web standards |
431
+ | Validation | Zod 4 | one schema → JSON Schema for agents |
432
+ | MCP | official TypeScript SDK | Streamable HTTP (web-standard transport) + stdio |
433
+ | Config loading | jiti | loads `aicms.config.ts` and models without a build step |
434
+ | Studio | React + Framer Motion | fast UI, smooth transitions |
435
+ | Realtime | Yjs | co-editing between people and agents |
436
+
437
+ ## 11. Compared with WordPress
438
+
439
+ | | WordPress | AICMS |
440
+ |---|---|---|
441
+ | Structure | thousands of core files, themes, plugins, `functions.php` | one package; a project = config + models |
442
+ | Data model | `wp_posts` + `wp_postmeta` (EAV) | typed models, six core tables |
443
+ | Extending | global hooks with priorities, plugin conflicts | modules with `provides / requires` and isolation |
444
+ | API | REST added later, partial | every Action → REST and MCP automatically |
445
+ | AI agents | plugins or scraping the admin | native MCP, scopes, changesets |
446
+ | Agent permissions | administrator role = everything | field-level scopes, budgets, review |
447
+ | History | revisions for posts only | an event log for everything |
448
+ | Frontend | PHP themes | any framework, typed SDK |
449
+
450
+ ## 12. Roadmap
451
+
452
+ | Phase | Scope | Outcome |
453
+ |---|---|---|
454
+ | **0. Kernel** ✓ | Schema Engine, Action Bus, policies, changesets, event log, SQLite store, REST, MCP, discovery, webhooks, CLI | an agent drafts content over MCP, a person merges it |
455
+ | **1. Human in the loop** ✓ | Studio MVP and Inbox, rollback, SSE events, TypeScript and Python SDKs, Next.js and Astro adapters | the first real site |
456
+ | **2. Lego** ✓ | module SDK, `aicms add`, official modules (seo, i18n, media, search, git-sync), agents propose modules via Inbox, GraphQL, Nuxt and SvelteKit | the ecosystem starts growing |
457
+ | **3. Scale** ✓ | Postgres and edge, real-time presence, module registry, A2A, commerce | production for shops and media |
458
+ | **4. Workflows** ✓ | briefs for agents, content checks and the lint module, review rules, scheduled publishing, ⌘K in Studio, `create-aicms` and a release pipeline for npm and PyPI | a team of agents works from briefs, a person approves and plans |
459
+
460
+ ## 13. Decisions
461
+
462
+ | Question | Decision |
463
+ |---|---|
464
+ | Content in the database or in git? | The database is the source of truth: changesets, field-level permissions, concurrent agents and transactions all need it. The `git-sync` module mirrors published content to Markdown + frontmatter files and turns pull requests into changesets, so developers and coding agents can still work through git. |
465
+ | Can an agent propose installing a module? | Yes, through Inbox, with the requested permissions shown. A person installs it. |
466
+ | Python SDK | Shipped in phase 1 with the TypeScript SDK: `sdk/python`, standard library only. |
467
+ | License | MIT for everything: kernel, SDKs, adapters and official modules. Free for any use, including commercial. If funding is ever needed, it comes from donations, not a paid edition. |
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 malkovych
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.