@assemora/cli 0.1.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 (76) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +272 -0
  3. package/bin.mjs +31 -0
  4. package/dist/args.d.ts +35 -0
  5. package/dist/args.d.ts.map +1 -0
  6. package/dist/args.js +104 -0
  7. package/dist/args.js.map +1 -0
  8. package/dist/bin.d.ts +3 -0
  9. package/dist/bin.d.ts.map +1 -0
  10. package/dist/bin.js +11 -0
  11. package/dist/bin.js.map +1 -0
  12. package/dist/commands/agents.d.ts +50 -0
  13. package/dist/commands/agents.d.ts.map +1 -0
  14. package/dist/commands/agents.js +169 -0
  15. package/dist/commands/agents.js.map +1 -0
  16. package/dist/commands/artifacts.d.ts +5 -0
  17. package/dist/commands/artifacts.d.ts.map +1 -0
  18. package/dist/commands/artifacts.js +126 -0
  19. package/dist/commands/artifacts.js.map +1 -0
  20. package/dist/commands/console.d.ts +25 -0
  21. package/dist/commands/console.d.ts.map +1 -0
  22. package/dist/commands/console.js +99 -0
  23. package/dist/commands/console.js.map +1 -0
  24. package/dist/commands/db.d.ts +48 -0
  25. package/dist/commands/db.d.ts.map +1 -0
  26. package/dist/commands/db.js +585 -0
  27. package/dist/commands/db.js.map +1 -0
  28. package/dist/commands/index.d.ts +21 -0
  29. package/dist/commands/index.d.ts.map +1 -0
  30. package/dist/commands/index.js +21 -0
  31. package/dist/commands/index.js.map +1 -0
  32. package/dist/commands/inspect.d.ts +8 -0
  33. package/dist/commands/inspect.d.ts.map +1 -0
  34. package/dist/commands/inspect.js +280 -0
  35. package/dist/commands/inspect.js.map +1 -0
  36. package/dist/commands/make.d.ts +29 -0
  37. package/dist/commands/make.d.ts.map +1 -0
  38. package/dist/commands/make.js +393 -0
  39. package/dist/commands/make.js.map +1 -0
  40. package/dist/commands/mcp.d.ts +19 -0
  41. package/dist/commands/mcp.d.ts.map +1 -0
  42. package/dist/commands/mcp.js +116 -0
  43. package/dist/commands/mcp.js.map +1 -0
  44. package/dist/commands/new.d.ts +20 -0
  45. package/dist/commands/new.d.ts.map +1 -0
  46. package/dist/commands/new.js +83 -0
  47. package/dist/commands/new.js.map +1 -0
  48. package/dist/commands/run.d.ts +20 -0
  49. package/dist/commands/run.d.ts.map +1 -0
  50. package/dist/commands/run.js +355 -0
  51. package/dist/commands/run.js.map +1 -0
  52. package/dist/commands/watchdog.d.ts +2 -0
  53. package/dist/commands/watchdog.d.ts.map +1 -0
  54. package/dist/commands/watchdog.js +74 -0
  55. package/dist/commands/watchdog.js.map +1 -0
  56. package/dist/config.d.ts +89 -0
  57. package/dist/config.d.ts.map +1 -0
  58. package/dist/config.js +156 -0
  59. package/dist/config.js.map +1 -0
  60. package/dist/index.d.ts +19 -0
  61. package/dist/index.d.ts.map +1 -0
  62. package/dist/index.js +133 -0
  63. package/dist/index.js.map +1 -0
  64. package/dist/output.d.ts +96 -0
  65. package/dist/output.d.ts.map +1 -0
  66. package/dist/output.js +181 -0
  67. package/dist/output.js.map +1 -0
  68. package/dist/project.d.ts +44 -0
  69. package/dist/project.d.ts.map +1 -0
  70. package/dist/project.js +102 -0
  71. package/dist/project.js.map +1 -0
  72. package/dist/registry.d.ts +48 -0
  73. package/dist/registry.d.ts.map +1 -0
  74. package/dist/registry.js +74 -0
  75. package/dist/registry.js.map +1 -0
  76. package/package.json +49 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Assemora
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
package/README.md ADDED
@@ -0,0 +1,272 @@
1
+ # @assemora/cli
2
+
3
+ The `assemora` executable (SPEC.md §77).
4
+
5
+ ```bash
6
+ assemora dev # run the project, restarting when a file changes
7
+ assemora make:model Post
8
+ assemora db:generate add-posts
9
+ assemora db:migrate
10
+ assemora routes
11
+ ```
12
+
13
+ ## It is a client of the application, not a second one
14
+
15
+ The CLI never imports a feature package. It does not import `@assemora/auth`,
16
+ `@assemora/pages`, `@assemora/media`, `@assemora/resources`, `@assemora/http` or
17
+ `@assemora/mcp`, and `pnpm boundaries` fails the build if it ever does.
18
+
19
+ It gets the application by importing the *project's own code* at runtime through
20
+ `assemora.config.ts`, and then asks it questions: `app.registry.describe()` for
21
+ routes, models, resources, blocks, commands and queries, and
22
+ `app.queries.execute('auth.agents.list', …)` for anything that is data rather than
23
+ declaration. Listing agents therefore goes through the Query Bus, is authorized and is
24
+ audited, exactly as it would be from Studio or from an agent. The CLI is one more
25
+ client of the application layer (ADR-0021).
26
+
27
+ Two things follow, and they are the honest cost rather than bugs. An application that
28
+ cannot be constructed cannot be introspected: `assemora routes` boots the app, which
29
+ means it also opens a database connection. And `assemora agents` is subject to
30
+ policies — run it as nobody and it does not list nothing, it refuses, which is correct
31
+ and will surprise somebody at least once. The refusal says so and names the flag:
32
+ `--actor <id>` is how you say who is asking.
33
+
34
+ The alternative was a CLI that parses the project's TypeScript, which would need a
35
+ second implementation of what a model, a resource and a block are. The Schema Registry
36
+ exists so that no subsystem keeps its own copy.
37
+
38
+ ## `assemora.config.ts`
39
+
40
+ ```ts
41
+ import { defineConfig } from '@assemora/cli'
42
+
43
+ export default defineConfig({
44
+ // How the CLI gets an application. It is NOT booted — the CLI boots it, once.
45
+ app: () => import('./src/app.ts').then((module) => module.createApp()),
46
+
47
+ // What `assemora dev` and `assemora start` run, relative to this file.
48
+ server: 'src/server.ts',
49
+
50
+ paths: {
51
+ source: 'src',
52
+ migrations: 'database/migrations',
53
+ generated: '.assemora/generated',
54
+ },
55
+
56
+ openapi: { out: 'openapi.json', info: { title: 'My project', version: '0.1.0' } },
57
+ sdk: { out: 'src/generated/sdk.ts' },
58
+ })
59
+ ```
60
+
61
+ `defineConfig` is identity plus types. It exists so the object is checked where it is
62
+ written, which is the only place a mistake in it is cheap to fix.
63
+
64
+ Every path is relative to the directory holding the config, so `assemora db:migrate`
65
+ means the same thing typed from `src/` as from the root — the config is found by
66
+ walking up from the working directory, `assemora.config.ts` first and then
67
+ `assemora.config.js`. Node 24 strips TypeScript types natively, so a `.ts` config is
68
+ imported directly: no transpiler, no dependency, and the file the developer edits is
69
+ the file that runs.
70
+
71
+ `app` hands back an application that has *not* been booted. The CLI boots it once per
72
+ process, so two commands in one process — and `console`, which is many — share a
73
+ single application and a single database pool.
74
+
75
+ Everything is optional except `app`. `paths` defaults to the three values above;
76
+ `api:openapi` falls back to `openapi.json` and takes its title and version from the
77
+ project's `package.json`; `sdk:generate` falls back to `<source>/generated/sdk.ts`.
78
+
79
+ ## The commands
80
+
81
+ Grouped as SPEC.md §77 groups them, which is how `assemora` with no arguments prints
82
+ them.
83
+
84
+ ### Project
85
+
86
+ | | |
87
+ | --- | --- |
88
+ | `assemora new <name>` | scaffold a new project |
89
+
90
+ It calls `scaffold()` from `create-assemora` — the same code path as
91
+ `pnpm create assemora`. This is the convenience, not a second implementation.
92
+
93
+ ### Run
94
+
95
+ | | |
96
+ | --- | --- |
97
+ | `assemora dev` | run the server and restart it when a file changes |
98
+ | `assemora build` | typecheck, regenerate what the config declares, run the project's build |
99
+ | `assemora start` | run the server |
100
+
101
+ `dev` and `start` spawn `node [--watch] <config.server>` under the same Node the CLI is
102
+ running under, streaming its output, forwarding SIGINT, SIGTERM and SIGHUP and exiting
103
+ with its code. Everything after `--` is node's: `assemora dev -- --inspect` runs
104
+ `node --watch --inspect src/server.ts`.
105
+
106
+ The child runs in a process group of its own and every signal is sent to that group,
107
+ because `node --watch` is a wrapper and the server holding the port is its child — a
108
+ signal delivered to the watcher alone would leave the server running with init for a
109
+ parent. A second signal escalates to SIGKILL, on the group for the same reason.
110
+
111
+ `build` is "everything that must be current before this is deployed", in three steps:
112
+ a typecheck with the project's own TypeScript and its own `tsconfig.json` (skip it with
113
+ `--no-typecheck`), then exactly what the config declares — by running `api:openapi` and
114
+ `sdk:generate` rather than by generating anything itself — and then the project's own
115
+ `build` script, if it declares one, with the package manager the project names. That
116
+ script runs last because the generated SDK is an input to whatever bundles it.
117
+
118
+ ### Generate
119
+
120
+ | | |
121
+ | --- | --- |
122
+ | `assemora make:model Post` | `src/models/post.ts` |
123
+ | `assemora make:resource Post` | `src/resources/posts.ts` |
124
+ | `assemora make:block hero` | `src/blocks/hero.ts` |
125
+ | `assemora make:module blog` | `src/modules/blog.ts` |
126
+ | `assemora make:command posts.publish` | `src/commands/publish-post.ts` |
127
+ | `assemora make:policy posts` | `src/policies/posts.ts` |
128
+
129
+ One file into `paths.source`, refusing to overwrite unless `--force`. `BlogPost`,
130
+ `blog_post`, `blog-post` and `blogPost` produce a byte-identical file, so nobody has
131
+ to remember which spelling the generator wanted.
132
+
133
+ The path goes to stdout and the next step goes to stderr, so
134
+ `assemora make:model Post` can be piped into an editor. What is generated compiles
135
+ against the real APIs, and `make.test.ts` is what proves it: a generator that emits
136
+ code the framework rejects is worse than no generator.
137
+
138
+ ### Database
139
+
140
+ | | |
141
+ | --- | --- |
142
+ | `assemora db:generate [name] [--check] [--force]` | write a migration for everything the models changed |
143
+ | `assemora db:migrate` | apply every migration that has not run yet |
144
+ | `assemora db:rollback` | undo the most recently applied migration |
145
+ | `assemora db:status` | list every migration and whether it is applied |
146
+
147
+ `db:generate` diffs the snapshot at `<generated>/schema.json` against the booted
148
+ application's model registry, writes `<migrations>/<NNNN>_<name>.sql` and moves the
149
+ snapshot forward — in that order, so a snapshot never runs ahead of a migration that
150
+ was not written. Every destructive change is printed as a warning naming the table and
151
+ the column. `--check` writes nothing and exits `1` if a migration would be generated,
152
+ which is what CI runs.
153
+
154
+ The diff is taken against the snapshot rather than against a live database, so
155
+ generation is deterministic, works offline, and produces the same migration for two
156
+ developers whose databases have drifted. `db:status` is where drift against a real
157
+ database is reported.
158
+
159
+ A missing snapshot means "nothing has been created yet", which is true for the first
160
+ migration and a lie once `<migrations>` holds one — the migration generated then
161
+ re-creates every table and `db:migrate` fails on the first that already exists. So
162
+ `db:generate` refuses that combination and names both files: the snapshot belongs in
163
+ version control, and a checkout that received the migrations without it is the state to
164
+ fix. `--force` diffs against an empty schema anyway, for a project whose migrations were
165
+ written by hand and never had a snapshot.
166
+
167
+ A pending migration that changes or destroys stored data needs `--force` outside
168
+ development, and so does any rollback (SPEC.md §34). The CLI has `NODE_ENV` and
169
+ nothing else to go on, so the question is answered the safe way round: `development`
170
+ and `test` are development, and everything else — staging, a typo, an unset variable
171
+ — is treated as production.
172
+
173
+ #### The migration file format
174
+
175
+ ```sql
176
+ -- 0002_add-sku
177
+ -- Written by `assemora db:generate`. A comment beginning `-- +` is read back by
178
+ -- `assemora db:migrate`; every other comment in this file is for you.
179
+ -- +destructive drops column products.legacy_sku
180
+
181
+ -- +migration up
182
+ alter table "products" add column "sku" varchar(255);
183
+
184
+ -- +migration down
185
+ alter table "products" drop column "sku";
186
+ ```
187
+
188
+ A plain `.sql` file, because the whole point of generating one is that a person reads
189
+ it in a pull request before it ever reaches a database. One rule makes it both
190
+ parseable and reviewable: **a comment beginning `-- +` is a directive, and every other
191
+ comment is prose**. There are two directives — `+migration up` / `+migration down`
192
+ open a section, and `+destructive <sentence>` is what `db:migrate` prints before it
193
+ runs. A directive that is not recognised is refused rather than ignored, because a
194
+ typo in `-- +migration down` would otherwise put a `drop` in the section that runs
195
+ forwards.
196
+
197
+ Statements are separated by `;`, exactly as anybody would write them, so the file is
198
+ also runnable with `psql -f`. A semicolon inside a string, a quoted identifier or a
199
+ dollar-quoted body is part of the statement rather than the end of it.
200
+
201
+ The filename is `<number>_<name>.sql`. The number decides the order, so a file without
202
+ one is refused rather than sorted somewhere arbitrary, and two files sharing a number
203
+ — two branches that each generated `0004` — are refused by name rather than resolved
204
+ by whatever order the filesystem offers. A file with no `-- +migration` marker at all
205
+ is read as an `up` migration, which is what somebody who dropped a `.sql` file into
206
+ the directory meant. A migration with no `down` section is refused by
207
+ `db:rollback` by name, rather than quietly running nothing and marking itself undone.
208
+
209
+ ### Inspect
210
+
211
+ | | |
212
+ | --- | --- |
213
+ | `assemora routes` | the HTTP routes this application registers |
214
+ | `assemora models` | the models it declares, with their tables and relations |
215
+ | `assemora resources` | the resources it declares, and the models behind them |
216
+ | `assemora blocks` | the block types a page can be assembled from |
217
+ | `assemora agents` | the agent identities this application knows |
218
+
219
+ All five take `--json`, because the next thing anybody does with a listing is pipe it —
220
+ and every log the booted application writes goes to stderr for the same reason, so what
221
+ is on stdout is the answer and nothing else. `agents` additionally takes `--actor <id>`,
222
+ `--page` and `--per-page`. An application built without `@assemora/auth` registers no
223
+ `auth.agents.list`, and `agents` says that plainly rather than failing on an unknown
224
+ query. A read the authorizer refuses names `--actor`, because running as nobody is the
225
+ commonest way to meet that refusal and the authorizer has never heard of a flag.
226
+
227
+ ### Artifacts
228
+
229
+ | | |
230
+ | --- | --- |
231
+ | `assemora api:openapi` | write the OpenAPI 3.1 document |
232
+ | `assemora sdk:generate` | write the typed client |
233
+
234
+ `--out <file>` beats the config, the config beats the default, and `--stdout` beats
235
+ all three by naming no file at all — and writes nothing else, so it pipes.
236
+
237
+ ### Console
238
+
239
+ | | |
240
+ | --- | --- |
241
+ | `assemora console` | open a REPL holding the booted application |
242
+
243
+ `app`, `commands`, `queries` and `registry` are in scope, plus
244
+ `as(actorId, operation)` which runs an operation inside a user context. There is no
245
+ database handle in scope and this package could not obtain one: a mutation typed here
246
+ passes validation, authorization, revisions and audit exactly as one typed anywhere
247
+ else does. `.exit` closes the application, so the pool it opened goes with it.
248
+
249
+ ## Exit codes
250
+
251
+ `0` succeeded, `1` the command failed, `2` the invocation was wrong — an unknown
252
+ command, a missing argument, `--page two`. The distinction matters to a script: `2`
253
+ says the arguments were nonsense and retrying will not help, while `1` says the work
254
+ was attempted and did not finish.
255
+
256
+ Errors print one clear sentence to stderr. `--debug` adds the stack and every cause
257
+ below it.
258
+
259
+ `run(argv)` returns the exit code and never calls `process.exit`, so the whole CLI is
260
+ drivable from a test in-process. `bin.ts` is the only thing that ends the process, and
261
+ it sets `process.exitCode` rather than exiting, so a piped listing is flushed rather
262
+ than truncated mid-line.
263
+
264
+ ## Adding a command
265
+
266
+ One `defineCommand` in the group that owns it, registered into the table in
267
+ `registry.ts`. The help is printed from the table rather than written out beside it,
268
+ so there is no second list to keep in step. A group reaches the table by being
269
+ imported from `commands/index.ts`, and a group needing a heavy import —
270
+ `@assemora/database-postgres` for `db:*`, the SDK generator for `sdk:generate` —
271
+ reaches for it inside its handler rather than at the top of its module, so
272
+ `assemora --help` stays instant.
package/bin.mjs ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * The file `assemora` is linked to.
4
+ *
5
+ * A package manager creates the executable when a package is *installed*, and `dist/`
6
+ * does not exist at that moment: it is gitignored and written by `pnpm build`, which
7
+ * runs afterwards. A `bin` pointing straight at `dist/bin.js` is therefore a link to
8
+ * nothing on a fresh clone — pnpm warns once and moves on, and every script that types
9
+ * `assemora` fails for the life of that checkout, which is how CI came to fail on a
10
+ * repository whose sources were fine.
11
+ *
12
+ * So the linked file is committed, and it loads the build. It is `.mjs` rather than
13
+ * TypeScript for the same reason `scripts/copy-templates.mjs` is: it has to run before
14
+ * this package has a build of its own.
15
+ *
16
+ * The build is looked for rather than caught. Catching `ERR_MODULE_NOT_FOUND` around
17
+ * the import would also swallow a missing dependency *inside* the CLI and report it as
18
+ * an unbuilt package, which is a worse lie than the error it replaces.
19
+ */
20
+ import { existsSync } from 'node:fs'
21
+
22
+ const compiled = new URL('./dist/bin.js', import.meta.url)
23
+
24
+ if (existsSync(compiled)) {
25
+ await import(compiled.href)
26
+ } else {
27
+ // `process.exitCode` rather than `process.exit()`, for the reason `src/bin.ts` gives:
28
+ // exiting outright truncates what is still being written.
29
+ process.stderr.write('assemora: @assemora/cli is not built. Run `pnpm build` first.\n')
30
+ process.exitCode = 1
31
+ }
package/dist/args.d.ts ADDED
@@ -0,0 +1,35 @@
1
+ /**
2
+ * argv, parsed by hand (SPEC.md §77).
3
+ *
4
+ * `node:util`'s `parseArgs` was the obvious alternative and it wants every option
5
+ * declared before the first token is read, so that it knows which ones take a value.
6
+ * The command table here is assembled by seven independent modules that know nothing
7
+ * about each other's flags (ADR-0021), so the parser has to work without that table.
8
+ * A third-party parser was never a candidate: the CLI is a framework's front door and
9
+ * has to install instantly, which is the same reason it has no dependencies at all.
10
+ */
11
+ export type ParsedArgs = {
12
+ /** The first token that is not a flag — `make:model`, `db:migrate`, `routes`. */
13
+ readonly command: string | undefined;
14
+ /** Everything else that is not a flag, in order, with the command removed. */
15
+ readonly positionals: readonly string[];
16
+ /**
17
+ * Flags by their written name, `--dry-run` included: no camel-casing happens, so
18
+ * what a handler asks for is what the user typed. A repeated flag keeps the last
19
+ * value, because that is what a shell alias plus an override is meant to do.
20
+ */
21
+ readonly flags: Readonly<Record<string, string | boolean>>;
22
+ /** Everything after `--`, untouched. `dev` forwards it to node. */
23
+ readonly passthrough: readonly string[];
24
+ };
25
+ export declare const parseArgs: (argv: readonly string[]) => ParsedArgs;
26
+ /**
27
+ * A flag's value, or the fallback.
28
+ *
29
+ * A flag written without a value has no string to give, so `--out --json` answers
30
+ * the fallback rather than the word `true`: a handler that wanted a path should ask
31
+ * for one, not receive a plausible-looking lie.
32
+ */
33
+ export declare const flag: (args: ParsedArgs, name: string, fallback?: string) => string | undefined;
34
+ export declare const bool: (args: ParsedArgs, name: string) => boolean;
35
+ //# sourceMappingURL=args.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../src/args.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,MAAM,UAAU,GAAG;IACvB,iFAAiF;IACjF,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;IACpC,8EAA8E;IAC9E,QAAQ,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,CAAA;IACvC;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAA;IAC1D,mEAAmE;IACnE,QAAQ,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,CAAA;CACxC,CAAA;AAmBD,eAAO,MAAM,SAAS,SAAU,SAAS,MAAM,EAAE,KAAG,UAgEnD,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,IAAI,SAAU,UAAU,QAAQ,MAAM,aAAa,MAAM,KAAG,MAAM,GAAG,SAIjF,CAAA;AAKD,eAAO,MAAM,IAAI,SAAU,UAAU,QAAQ,MAAM,KAAG,OAOrD,CAAA"}
package/dist/args.js ADDED
@@ -0,0 +1,104 @@
1
+ /**
2
+ * argv, parsed by hand (SPEC.md §77).
3
+ *
4
+ * `node:util`'s `parseArgs` was the obvious alternative and it wants every option
5
+ * declared before the first token is read, so that it knows which ones take a value.
6
+ * The command table here is assembled by seven independent modules that know nothing
7
+ * about each other's flags (ADR-0021), so the parser has to work without that table.
8
+ * A third-party parser was never a candidate: the CLI is a framework's front door and
9
+ * has to install instantly, which is the same reason it has no dependencies at all.
10
+ */
11
+ /**
12
+ * Whether a token is a flag rather than a value.
13
+ *
14
+ * This is the whole answer to "how does `--out value` know that `value` is not the
15
+ * next flag": a token starting with `-` is a flag and never a value. `-` alone is a
16
+ * value, because that is what it conventionally means, and `-1` is a value too — no
17
+ * short flag is a digit, and `--limit -1` is far more common than a flag named `1`.
18
+ * Anything genuinely ambiguous is written `--flag=value`, which never guesses.
19
+ *
20
+ * The price of having no option table is that a value-taking flag written *before*
21
+ * the command would swallow it: `assemora --out x routes` leaves no command behind.
22
+ * Flags follow the command — which is how the help prints every usage line, and how
23
+ * anybody types it — so the case is documented rather than guessed at.
24
+ */
25
+ const isFlagToken = (token) => token !== undefined && token.length > 1 && token.startsWith('-') && !/^-\d/.test(token);
26
+ export const parseArgs = (argv) => {
27
+ const positionals = [];
28
+ const flags = {};
29
+ let passthrough = [];
30
+ let index = 0;
31
+ while (index < argv.length) {
32
+ const token = argv[index];
33
+ index += 1;
34
+ if (token === undefined)
35
+ continue;
36
+ // The first `--` ends the parse. A second one is somebody else's argument.
37
+ if (token === '--') {
38
+ passthrough = argv.slice(index);
39
+ break;
40
+ }
41
+ if (!isFlagToken(token)) {
42
+ positionals.push(token);
43
+ continue;
44
+ }
45
+ const long = token.startsWith('--');
46
+ const body = token.slice(long ? 2 : 1);
47
+ const separator = body.indexOf('=');
48
+ if (separator >= 0) {
49
+ const name = body.slice(0, separator);
50
+ // `--=value` names nothing; treat it as text rather than inventing an empty key.
51
+ if (name === '')
52
+ positionals.push(token);
53
+ else
54
+ flags[name] = body.slice(separator + 1);
55
+ continue;
56
+ }
57
+ // A cluster is `-fj`, and only its last letter can take the following value —
58
+ // the earlier letters have nowhere to put one.
59
+ const names = long ? [body] : [...body];
60
+ const last = names.length - 1;
61
+ names.forEach((name, position) => {
62
+ if (position < last) {
63
+ flags[name] = true;
64
+ return;
65
+ }
66
+ const next = argv[index];
67
+ if (next !== undefined && !isFlagToken(next)) {
68
+ flags[name] = next;
69
+ index += 1;
70
+ }
71
+ else {
72
+ flags[name] = true;
73
+ }
74
+ });
75
+ }
76
+ return {
77
+ command: positionals[0],
78
+ positionals: positionals.slice(1),
79
+ flags,
80
+ passthrough,
81
+ };
82
+ };
83
+ /**
84
+ * A flag's value, or the fallback.
85
+ *
86
+ * A flag written without a value has no string to give, so `--out --json` answers
87
+ * the fallback rather than the word `true`: a handler that wanted a path should ask
88
+ * for one, not receive a plausible-looking lie.
89
+ */
90
+ export const flag = (args, name, fallback) => {
91
+ const value = args.flags[name];
92
+ return typeof value === 'string' ? value : fallback;
93
+ };
94
+ /** What a scripted `--force=$SOMETHING` means when `$SOMETHING` is empty or a denial. */
95
+ const DENIALS = new Set(['', 'false', '0', 'no', 'off']);
96
+ export const bool = (args, name) => {
97
+ const value = args.flags[name];
98
+ if (value === undefined)
99
+ return false;
100
+ if (typeof value === 'boolean')
101
+ return value;
102
+ return !DENIALS.has(value.toLowerCase());
103
+ };
104
+ //# sourceMappingURL=args.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"args.js","sourceRoot":"","sources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