create-amoxi-app 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.
- package/LICENSE +201 -0
- package/NOTICE +5 -0
- package/README.md +14 -2
- package/index.js +319 -0
- package/package.json +40 -4
- package/templates/LICENSE +22 -0
- package/templates/agent/README.md +34 -0
- package/templates/agent/src/agent/assistant.ts +18 -0
- package/templates/agent/src/agent/note-tools.ts +33 -0
- package/templates/agent/src/islands/Assistant.tsx +69 -0
- package/templates/agent/src/islands/NoteList.tsx +17 -0
- package/templates/agent/src/pages/assistant-page.tsx +27 -0
- package/templates/agent/src/styles/assistant.css +33 -0
- package/templates/agent/src/ui/layout.tsx +36 -0
- package/templates/agent/test/agent.test.ts +67 -0
- package/templates/api/src/notes/note-controller.ts +19 -0
- package/templates/api/src/notes/note-service.ts +27 -0
- package/templates/api/src/notes/note.ts +19 -0
- package/templates/api/test/app.test.ts +25 -0
- package/templates/shared/Dockerfile +38 -0
- package/templates/shared/README.md +25 -0
- package/templates/shared/_dockerignore +10 -0
- package/templates/shared/_env.example +4 -0
- package/templates/shared/_gitignore +14 -0
- package/templates/shared/application-production.json +3 -0
- package/templates/shared/application.json +4 -0
- package/templates/shared/src/main.ts +8 -0
- package/templates/shared/tsconfig.json +21 -0
- package/templates/web/public/favicon.svg +1 -0
- package/templates/web/src/islands/AddNote.tsx +40 -0
- package/templates/web/src/islands/Counter.tsx +11 -0
- package/templates/web/src/notes/note-controller.ts +19 -0
- package/templates/web/src/notes/note-service.ts +27 -0
- package/templates/web/src/notes/note.ts +19 -0
- package/templates/web/src/pages/home-page.tsx +105 -0
- package/templates/web/src/styles/app.css +105 -0
- package/templates/web/src/ui/layout.tsx +34 -0
- package/templates/web/test/app.test.ts +33 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
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 [yyyy] [name of copyright owner]
|
|
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.
|
package/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# create-amoxi-app
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Creates a new [Amoxi](https://www.npmjs.com/package/amoxi) app.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npx create-amoxi-app@latest my-app
|
|
7
|
+
# or
|
|
8
|
+
npm create amoxi-app@latest my-app
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
It asks which template to use when run in a terminal. Options: `--template web|agent|api` (pages, islands and a JSON API; the same plus an AI agent with a streaming chat; or an API only), `--no-install`, `--no-git`, `--yes`.
|
|
12
|
+
|
|
13
|
+
The generated `Dockerfile` installs with whichever lockfile the project has (npm, pnpm, yarn or bun), so run your package manager's install once before `docker build`.
|
|
14
|
+
|
|
15
|
+
Documentation: [karawash-projects.github.io/amoxi/docs](https://karawash-projects.github.io/amoxi/docs/).
|
package/index.js
ADDED
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Copyright 2026 Ahmad Karawash
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
'use strict';
|
|
6
|
+
/**
|
|
7
|
+
* create-amoxi-app: scaffolds a ready-to-run Amoxi project.
|
|
8
|
+
*
|
|
9
|
+
* npx create-amoxi-app@latest my-app
|
|
10
|
+
* npx create-amoxi-app@latest my-api --template api
|
|
11
|
+
*
|
|
12
|
+
* No dependencies; works on Windows, macOS and Linux.
|
|
13
|
+
*/
|
|
14
|
+
const fs = require('node:fs');
|
|
15
|
+
const path = require('node:path');
|
|
16
|
+
const { spawnSync } = require('node:child_process');
|
|
17
|
+
|
|
18
|
+
const VERSION = require('./package.json').version;
|
|
19
|
+
const isWin = process.platform === 'win32';
|
|
20
|
+
const tty = process.stdout.isTTY;
|
|
21
|
+
const paint = (code) => (s) => (tty ? `\x1b[${code}m${s}\x1b[0m` : String(s));
|
|
22
|
+
const bold = paint(1);
|
|
23
|
+
const dim = paint(2);
|
|
24
|
+
const green = paint(32);
|
|
25
|
+
const red = paint(31);
|
|
26
|
+
const cyan = paint(36);
|
|
27
|
+
|
|
28
|
+
const TEMPLATES = {
|
|
29
|
+
web: 'Pages, islands and a JSON API (full-stack)',
|
|
30
|
+
agent: 'The web template plus an AI agent with tools, streaming chat and generative UI',
|
|
31
|
+
api: 'JSON API only (backend service)',
|
|
32
|
+
};
|
|
33
|
+
/** Templates built on top of another one: copied in order, later files win. */
|
|
34
|
+
const LAYERS = { web: ['web'], agent: ['web', 'agent'], api: ['api'] };
|
|
35
|
+
|
|
36
|
+
const HELP = `
|
|
37
|
+
${bold('create-amoxi-app')} v${VERSION}
|
|
38
|
+
|
|
39
|
+
Usage:
|
|
40
|
+
create-amoxi-app <project-name> [options]
|
|
41
|
+
|
|
42
|
+
Options:
|
|
43
|
+
--template <web|agent|api>
|
|
44
|
+
web: pages, islands and a JSON API (default)
|
|
45
|
+
agent: web plus an AI agent with a streaming chat
|
|
46
|
+
api: a JSON API only
|
|
47
|
+
--framework <spec> Where amoxi comes from: a version range, a path to the
|
|
48
|
+
framework package or a .tgz (default: the local monorepo copy if
|
|
49
|
+
found, otherwise ^${VERSION} from npm)
|
|
50
|
+
--no-install Don't install dependencies
|
|
51
|
+
--no-git Don't initialise a git repository
|
|
52
|
+
-y, --yes Accept defaults without asking
|
|
53
|
+
-h, --help Show this help
|
|
54
|
+
`;
|
|
55
|
+
|
|
56
|
+
/** The project folder while it is being created: removed again if creating it fails partway. */
|
|
57
|
+
let unfinished;
|
|
58
|
+
|
|
59
|
+
function removeUnfinished() {
|
|
60
|
+
if (!unfinished) return;
|
|
61
|
+
const { target, existed } = unfinished;
|
|
62
|
+
unfinished = undefined;
|
|
63
|
+
try {
|
|
64
|
+
if (existed) for (const entry of fs.readdirSync(target)) fs.rmSync(path.join(target, entry), { recursive: true, force: true });
|
|
65
|
+
else fs.rmSync(target, { recursive: true, force: true });
|
|
66
|
+
} catch {
|
|
67
|
+
// Best effort: the message below still names the folder.
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function fail(message) {
|
|
72
|
+
removeUnfinished();
|
|
73
|
+
process.stderr.write(`\n${red('error')} ${message}\n\n`);
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Ctrl+C while the files are being written: don't leave a half-made project behind.
|
|
78
|
+
process.once('SIGINT', () => {
|
|
79
|
+
removeUnfinished();
|
|
80
|
+
process.exit(130);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
/** Options that take a value (--template web or --template=web). */
|
|
84
|
+
const VALUE_OPTIONS = new Set(['template', 'framework']);
|
|
85
|
+
|
|
86
|
+
function parseArgs(argv) {
|
|
87
|
+
const positionals = [];
|
|
88
|
+
const flags = { install: true, git: true };
|
|
89
|
+
for (let i = 0; i < argv.length; i++) {
|
|
90
|
+
const a = argv[i];
|
|
91
|
+
if (a === '-h' || a === '--help') flags.help = true;
|
|
92
|
+
else if (a === '-y' || a === '--yes') flags.yes = true;
|
|
93
|
+
else if (a === '--no-install') flags.install = false;
|
|
94
|
+
else if (a === '--no-git') flags.git = false;
|
|
95
|
+
else if (a.startsWith('-') && a !== '-') {
|
|
96
|
+
const eq = a.indexOf('=');
|
|
97
|
+
const option = eq === -1 ? a : a.slice(0, eq);
|
|
98
|
+
const name = option.replace(/^--/, '');
|
|
99
|
+
// An unknown option is an error, not a reason to take the next argument (the project name) as its value.
|
|
100
|
+
if (!option.startsWith('--') || !VALUE_OPTIONS.has(name)) fail(`Unknown option ${option}. Run create-amoxi-app --help to see the options.`);
|
|
101
|
+
const value = eq === -1 ? argv[++i] : a.slice(eq + 1);
|
|
102
|
+
if (value === undefined || value === '' || (eq === -1 && value.startsWith('-'))) fail(`Missing value for --${name}`);
|
|
103
|
+
flags[name] = value;
|
|
104
|
+
} else positionals.push(a);
|
|
105
|
+
}
|
|
106
|
+
if (positionals.length > 1) fail(`Expected one project name, got ${positionals.length}: ${positionals.join(' ')}`);
|
|
107
|
+
return { positionals, flags };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* How to start a package manager without a shell. On Windows npm, npx, pnpm and yarn are .cmd
|
|
112
|
+
* files, which only a shell can run, and handing argument lists to a shell is unsafe (Node warns
|
|
113
|
+
* about it, DEP0190). So they are started as Node scripts instead: the one the running package
|
|
114
|
+
* manager names in npm_execpath, or npm's own script next to node.exe. Elsewhere they run as usual.
|
|
115
|
+
*/
|
|
116
|
+
function packageManagerCommand(cmd, args) {
|
|
117
|
+
if (!isWin || !['npm', 'npx', 'pnpm', 'yarn'].includes(cmd)) return { file: cmd, args };
|
|
118
|
+
const execPath = process.env.npm_execpath;
|
|
119
|
+
if (execPath && fs.existsSync(execPath) && /\.(c?js|mjs)$/.test(execPath)) {
|
|
120
|
+
const base = path.basename(execPath).toLowerCase();
|
|
121
|
+
if (cmd === 'npm' && base.startsWith('npm-cli')) return { file: process.execPath, args: [execPath, ...args] };
|
|
122
|
+
const npxCli = path.join(path.dirname(execPath), 'npx-cli.js');
|
|
123
|
+
if (cmd === 'npx' && base.startsWith('npm-cli') && fs.existsSync(npxCli)) return { file: process.execPath, args: [npxCli, ...args] };
|
|
124
|
+
if (cmd !== 'npm' && cmd !== 'npx' && base.startsWith(cmd)) return { file: process.execPath, args: [execPath, ...args] };
|
|
125
|
+
}
|
|
126
|
+
const npmCli = path.join(path.dirname(process.execPath), 'node_modules', 'npm', 'bin', `${cmd === 'npx' ? 'npx' : 'npm'}-cli.js`);
|
|
127
|
+
if ((cmd === 'npm' || cmd === 'npx') && fs.existsSync(npmCli)) return { file: process.execPath, args: [npmCli, ...args] };
|
|
128
|
+
// Last resort: cmd.exe with every argument quoted; refuse characters cmd.exe would still interpret.
|
|
129
|
+
for (const a of args) {
|
|
130
|
+
if (/[%!"\r\n]/.test(a)) throw new Error(`Refusing to pass ${JSON.stringify(a)} to ${cmd} through cmd.exe`);
|
|
131
|
+
}
|
|
132
|
+
const line = [cmd, ...args].map((a) => (/^[\w./:=@\\-]+$/.test(a) ? a : `"${a}"`)).join(' ');
|
|
133
|
+
return { file: process.env.ComSpec || 'cmd.exe', args: ['/d', '/s', '/c', `"${line}"`], windowsVerbatimArguments: true };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Runs a command without a shell (see packageManagerCommand) and waits for it. */
|
|
137
|
+
function run(cmd, args, options = {}) {
|
|
138
|
+
const command = packageManagerCommand(cmd, args);
|
|
139
|
+
return spawnSync(command.file, command.args, { encoding: 'utf8', windowsHide: true, windowsVerbatimArguments: command.windowsVerbatimArguments, ...options });
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async function ask(question, fallback) {
|
|
143
|
+
if (!process.stdin.isTTY) return fallback;
|
|
144
|
+
const readline = require('node:readline/promises');
|
|
145
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
146
|
+
const answer = (await rl.question(`${question} ${dim(`(${fallback})`)} `)).trim();
|
|
147
|
+
rl.close();
|
|
148
|
+
return answer || fallback;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function validateName(name) {
|
|
152
|
+
if (name.length > 214) return 'must be at most 214 characters';
|
|
153
|
+
if (!/^[a-z0-9][a-z0-9._~-]*$/.test(name)) return 'may only contain lowercase letters, digits, "-", "_", "." and "~", and must start with a letter or digit';
|
|
154
|
+
if (['node_modules', 'favicon.ico'].includes(name)) return 'is a reserved name';
|
|
155
|
+
return undefined;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const DOTFILES = { _gitignore: '.gitignore', _dockerignore: '.dockerignore', '_env.example': '.env.example' };
|
|
159
|
+
|
|
160
|
+
function copyTemplate(src, dest, vars) {
|
|
161
|
+
for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
|
|
162
|
+
const from = path.join(src, entry.name);
|
|
163
|
+
const to = path.join(dest, DOTFILES[entry.name] ?? entry.name);
|
|
164
|
+
if (entry.isDirectory()) {
|
|
165
|
+
fs.mkdirSync(to, { recursive: true });
|
|
166
|
+
copyTemplate(from, to, vars);
|
|
167
|
+
} else {
|
|
168
|
+
let text = fs.readFileSync(from, 'utf8');
|
|
169
|
+
for (const [key, value] of Object.entries(vars)) text = text.split(`{{${key}}}`).join(value);
|
|
170
|
+
fs.writeFileSync(to, text);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Decides how the new app depends on amoxi. */
|
|
176
|
+
function resolveFramework(spec, target) {
|
|
177
|
+
// Running from a clone of the Amoxi repository (packages/create-amoxi-app next to
|
|
178
|
+
// packages/framework): use that framework build, so unreleased changes can be tried.
|
|
179
|
+
// Installed from npm, there is no such sibling and the published framework is used.
|
|
180
|
+
if (!spec) {
|
|
181
|
+
const localMonorepo = path.resolve(__dirname, '..', 'framework');
|
|
182
|
+
try {
|
|
183
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(localMonorepo, 'package.json'), 'utf8'));
|
|
184
|
+
if (pkg.name === 'amoxi' && fs.existsSync(path.join(localMonorepo, 'src', 'runtime'))) spec = localMonorepo;
|
|
185
|
+
} catch {
|
|
186
|
+
/* not a repository checkout */
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
if (!spec) return { dependency: `^${VERSION}`, note: `from npm (^${VERSION})` };
|
|
190
|
+
|
|
191
|
+
const abs = path.resolve(spec);
|
|
192
|
+
const vendor = path.join(target, 'vendor');
|
|
193
|
+
if (fs.existsSync(abs) && fs.statSync(abs).isFile() && abs.endsWith('.tgz')) {
|
|
194
|
+
fs.mkdirSync(vendor, { recursive: true });
|
|
195
|
+
fs.copyFileSync(abs, path.join(vendor, path.basename(abs)));
|
|
196
|
+
return { dependency: `file:vendor/${path.basename(abs)}`, note: `vendored from ${abs}` };
|
|
197
|
+
}
|
|
198
|
+
if (fs.existsSync(path.join(abs, 'package.json'))) {
|
|
199
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(abs, 'package.json'), 'utf8'));
|
|
200
|
+
if (pkg.name !== 'amoxi') fail(`${abs} is not the amoxi package`);
|
|
201
|
+
if (!fs.existsSync(path.join(abs, 'dist', 'runtime', 'index.js'))) {
|
|
202
|
+
fail(`The framework at ${abs} hasn't been built yet. Run "npm run build" in the Amoxi repository first.`);
|
|
203
|
+
}
|
|
204
|
+
// Pack it into the new project so the app is self-contained and portable (no symlinks).
|
|
205
|
+
fs.mkdirSync(vendor, { recursive: true });
|
|
206
|
+
const res = run('npm', ['pack', '--json', '--pack-destination', vendor], { cwd: abs });
|
|
207
|
+
if (res.status !== 0) fail(`Couldn't pack the framework:\n${res.stderr || res.stdout}`);
|
|
208
|
+
const filename = JSON.parse(res.stdout.slice(res.stdout.indexOf('[')))[0].filename;
|
|
209
|
+
return { dependency: `file:vendor/${filename}`, note: `packed from ${abs}` };
|
|
210
|
+
}
|
|
211
|
+
return { dependency: spec, note: `from npm (${spec})` };
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function detectPackageManager() {
|
|
215
|
+
const agent = process.env.npm_config_user_agent ?? '';
|
|
216
|
+
for (const pm of ['pnpm', 'yarn', 'bun']) if (agent.startsWith(pm)) return pm;
|
|
217
|
+
return 'npm';
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
async function main() {
|
|
221
|
+
const { positionals, flags } = parseArgs(process.argv.slice(2));
|
|
222
|
+
if (flags.help) {
|
|
223
|
+
process.stdout.write(HELP);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
const major = Number(process.versions.node.split('.')[0]);
|
|
227
|
+
if (major < 22) fail(`Amoxi needs Node.js 22 or newer; you have ${process.version}.`);
|
|
228
|
+
|
|
229
|
+
process.stdout.write(`\n${bold('Create an Amoxi app')}\n\n`);
|
|
230
|
+
const nameArg = positionals[0] ?? (flags.yes ? 'my-amoxi-app' : await ask('Project name?', 'my-amoxi-app'));
|
|
231
|
+
const target = path.resolve(nameArg);
|
|
232
|
+
const name = path.basename(target);
|
|
233
|
+
const nameProblem = validateName(name);
|
|
234
|
+
if (nameProblem) fail(`The project name "${name}" ${nameProblem}.`);
|
|
235
|
+
if (fs.existsSync(target) && fs.readdirSync(target).length > 0) {
|
|
236
|
+
fail(`The folder ${target} already exists and isn't empty. Choose another name or remove it.`);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
let template = flags.template;
|
|
240
|
+
if (!template) {
|
|
241
|
+
// Asked whenever someone is at the terminal (also when the project name was given); `web` with --yes or in scripts.
|
|
242
|
+
template = flags.yes ? 'web' : await ask(`Template? web = ${TEMPLATES.web}; agent = ${TEMPLATES.agent}; api = ${TEMPLATES.api}`, 'web');
|
|
243
|
+
}
|
|
244
|
+
if (!TEMPLATES[template]) fail(`Unknown template "${template}". Choose one of: ${Object.keys(TEMPLATES).join(', ')}.`);
|
|
245
|
+
|
|
246
|
+
const title = name.replace(/[-_.~]+/g, ' ').replace(/^\w/, (c) => c.toUpperCase());
|
|
247
|
+
unfinished = { target, existed: fs.existsSync(target) };
|
|
248
|
+
fs.mkdirSync(target, { recursive: true });
|
|
249
|
+
const vars = { APP_NAME: name, APP_TITLE: title };
|
|
250
|
+
copyTemplate(path.join(__dirname, 'templates', 'shared'), target, vars);
|
|
251
|
+
for (const layer of LAYERS[template]) copyTemplate(path.join(__dirname, 'templates', layer), target, vars);
|
|
252
|
+
if (template === 'api') {
|
|
253
|
+
// Git doesn't keep empty folders, and the Dockerfile copies public/: keep it in the repository.
|
|
254
|
+
fs.mkdirSync(path.join(target, 'public'), { recursive: true });
|
|
255
|
+
fs.writeFileSync(path.join(target, 'public', '.gitkeep'), '');
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const framework = resolveFramework(flags.framework, target);
|
|
259
|
+
const pkg = {
|
|
260
|
+
name,
|
|
261
|
+
version: '0.1.0',
|
|
262
|
+
private: true,
|
|
263
|
+
scripts: {
|
|
264
|
+
dev: 'amoxi dev',
|
|
265
|
+
build: 'amoxi build && tsc -p tsconfig.json',
|
|
266
|
+
start: 'amoxi start dist/src/main.js',
|
|
267
|
+
test: 'npm run build && node --test "dist/test/*.test.js"',
|
|
268
|
+
},
|
|
269
|
+
dependencies: { 'amoxi': framework.dependency },
|
|
270
|
+
devDependencies: { '@types/node': '^22.0.0', typescript: '~5.9.3' },
|
|
271
|
+
engines: { node: '>=22' },
|
|
272
|
+
};
|
|
273
|
+
fs.writeFileSync(path.join(target, 'package.json'), `${JSON.stringify(pkg, null, 2)}\n`);
|
|
274
|
+
// Every file is written: from here on the project stays, even if installing fails.
|
|
275
|
+
unfinished = undefined;
|
|
276
|
+
|
|
277
|
+
process.stdout.write(`${green('ok')} Created ${bold(name)} (${template} template) in ${target}\n`);
|
|
278
|
+
process.stdout.write(`${green('ok')} amoxi ${framework.note}\n`);
|
|
279
|
+
|
|
280
|
+
const pm = detectPackageManager();
|
|
281
|
+
let installFailed = false;
|
|
282
|
+
if (flags.install) {
|
|
283
|
+
process.stdout.write(`\nInstalling dependencies with ${pm}...\n\n`);
|
|
284
|
+
const res = run(pm, ['install'], { cwd: target, stdio: 'inherit' });
|
|
285
|
+
if (res.status !== 0) {
|
|
286
|
+
installFailed = true;
|
|
287
|
+
process.stdout.write(`\n${red('error')} Installing dependencies failed. Fix the problem above, then run "${pm} install" in ${name}.\n`);
|
|
288
|
+
} else {
|
|
289
|
+
process.stdout.write(`\n${green('ok')} Dependencies installed\n`);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
if (flags.git && run('git', ['--version']).status === 0 && !fs.existsSync(path.join(target, '.git'))) {
|
|
294
|
+
const inRepo = run('git', ['rev-parse', '--is-inside-work-tree'], { cwd: target }).stdout?.trim() === 'true';
|
|
295
|
+
if (!inRepo && run('git', ['init', '-q'], { cwd: target }).status === 0) {
|
|
296
|
+
run('git', ['add', '-A'], { cwd: target });
|
|
297
|
+
const commit = run('git', ['commit', '-q', '-m', 'Initial commit from create-amoxi-app'], { cwd: target });
|
|
298
|
+
process.stdout.write(`${green('ok')} Initialised a git repository${commit.status === 0 ? ' with an initial commit' : ''}\n`);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const runCmd = pm === 'npm' ? 'npm run' : pm;
|
|
303
|
+
const rel = path.relative(process.cwd(), target) || '.';
|
|
304
|
+
process.stdout.write(`
|
|
305
|
+
${bold('Next steps')}
|
|
306
|
+
|
|
307
|
+
${cyan(`cd ${rel.includes(' ') ? `"${rel}"` : rel}`)}${flags.install && !installFailed ? '' : `\n ${cyan(`${pm} install`)}`}
|
|
308
|
+
${cyan(`${runCmd} dev`)} then open http://localhost:8080
|
|
309
|
+
|
|
310
|
+
${runCmd} build production build
|
|
311
|
+
${pm === 'npm' ? 'npm start' : `${pm} start`} run it on every CPU core
|
|
312
|
+
${pm === 'npm' ? 'npm test' : `${pm} test`} build and run the tests
|
|
313
|
+
|
|
314
|
+
`);
|
|
315
|
+
// The project was created, but it isn't ready: scripts and CI must see the failure.
|
|
316
|
+
if (installFailed) process.exitCode = 1;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
main().catch((err) => fail(err instanceof Error ? err.stack : String(err)));
|
package/package.json
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-amoxi-app",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "Create an Amoxi app: npx create-amoxi-app@latest my-app",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"amoxi",
|
|
7
|
+
"create",
|
|
8
|
+
"scaffold",
|
|
9
|
+
"template"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://karawash-projects.github.io/amoxi/",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/karawash-projects/amoxi/issues"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/karawash-projects/amoxi.git",
|
|
18
|
+
"directory": "packages/create-amoxi-app"
|
|
19
|
+
},
|
|
20
|
+
"license": "Apache-2.0",
|
|
21
|
+
"author": "Ahmad Karawash",
|
|
22
|
+
"bin": {
|
|
23
|
+
"create-amoxi-app": "index.js"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"index.js",
|
|
27
|
+
"templates",
|
|
28
|
+
"README.md",
|
|
29
|
+
"LICENSE",
|
|
30
|
+
"NOTICE"
|
|
31
|
+
],
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=22"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"prepublishOnly": "node ../../scripts/check-package.mjs",
|
|
40
|
+
"test": "node --test \"test/*.test.cjs\""
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Starter templates for create-amoxi-app
|
|
2
|
+
|
|
3
|
+
The files in this folder are copied into the projects that create-amoxi-app
|
|
4
|
+
generates. They are licensed under the Zero-Clause BSD license (SPDX: 0BSD)
|
|
5
|
+
below, so a generated project is yours to use, change and license however you
|
|
6
|
+
like, with no attribution required. The create-amoxi-app tool itself is
|
|
7
|
+
licensed under the Apache License 2.0 (see ../LICENSE).
|
|
8
|
+
|
|
9
|
+
-------------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
Copyright (C) 2026 by Ahmad Karawash
|
|
12
|
+
|
|
13
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
14
|
+
purpose with or without fee is hereby granted.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
17
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
18
|
+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
19
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
20
|
+
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
21
|
+
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
|
22
|
+
THIS SOFTWARE.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# {{APP_TITLE}}
|
|
2
|
+
|
|
3
|
+
Created with `create-amoxi-app`.
|
|
4
|
+
|
|
5
|
+
## Commands
|
|
6
|
+
|
|
7
|
+
| | |
|
|
8
|
+
|---|---|
|
|
9
|
+
| `npm run dev` | Development server on http://localhost:8080; rebuilds and refreshes the browser on save |
|
|
10
|
+
| `npm run build` | Production build: `amoxi build` (wiring, validators, browser bundles) then `tsc` |
|
|
11
|
+
| `npm start` | Run the production build on every CPU core (`NODE_ENV=production`) |
|
|
12
|
+
| `npm test` | Build, then run the tests in `test/` |
|
|
13
|
+
|
|
14
|
+
## Configuration
|
|
15
|
+
|
|
16
|
+
No environment variables are required. Settings come from `application.json`, then `application-<profile>.json`, then `.env` files, then environment variables. The profile is `production` under `npm start` and `development` under `npm run dev`.
|
|
17
|
+
|
|
18
|
+
## Deploy
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
docker build -t {{APP_NAME}} .
|
|
22
|
+
docker run -p 8080:8080 {{APP_NAME}}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Health checks: `GET /amoxi/health/live` and `GET /amoxi/health/ready`.
|
|
26
|
+
|
|
27
|
+
## The AI assistant
|
|
28
|
+
|
|
29
|
+
`src/agent/` holds an agent (`@Agent`) and its tools (`@Tool`); `src/islands/Assistant.tsx` is the chat and `src/islands/NoteList.tsx` a component the agent can show (`@generative`). Open http://localhost:8080/assistant and try the suggested prompts.
|
|
30
|
+
|
|
31
|
+
- **No API key needed:** without one, Amoxi uses an offline demo model that picks tools by keyword. To use a real model, create `.env` (git-ignored, so the key is never committed) with `ANTHROPIC_API_KEY=...` or `OPENAI_API_KEY=...` (`OPENAI_BASE_URL` for Ollama, Azure OpenAI or another compatible server).
|
|
32
|
+
- **API:** `POST /agents/assistant/runs` with `{ "input": "Show my notes" }` (add `Accept: text/event-stream` to stream), then `GET /agents/assistant/runs/<id>`.
|
|
33
|
+
- **Storage:** conversations and runs are kept in `data/ai/`. Use PostgreSQL in production (see the Amoxi README, "AI agents").
|
|
34
|
+
- **Tests:** `test/agent.test.ts` shows the offline model and a scripted model (`ScriptedChatModel`) driving the agent deterministically.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Agent, type AgentRunContext } from 'amoxi/ai';
|
|
2
|
+
import { NoteTools } from './note-tools';
|
|
3
|
+
|
|
4
|
+
/** Answers questions about your notes and writes new ones. */
|
|
5
|
+
@Agent({
|
|
6
|
+
tools: [NoteTools],
|
|
7
|
+
ui: ['NoteList'],
|
|
8
|
+
examples: ['Show my notes', 'Add a note "Buy coffee beans"'],
|
|
9
|
+
})
|
|
10
|
+
export class Assistant {
|
|
11
|
+
instructions(ctx: AgentRunContext): string {
|
|
12
|
+
return [
|
|
13
|
+
'You are the assistant of a small notes app. Be brief and friendly.',
|
|
14
|
+
'Use the tools to read and save notes; never invent notes.',
|
|
15
|
+
`Today is ${ctx.now.toDateString()}.`,
|
|
16
|
+
].join('\n');
|
|
17
|
+
}
|
|
18
|
+
}
|