← Commit history

feat(apm): add apm license with 10 built-in licenses that keeps ash.pkg in sync

lennoxrose committed on Oct 18, 2026 at 01:21 UTC

a7a5352parent35e32ce

17 files changed+1285−2

CHANGELOG.mdmodified

+3−0
@@ -1,3 +1,6 @@
1+## 2026-10-18 (apm license)
2+- `apm license` lists the built-in licenses; `apm license <id> [--author <name>] [--year <yyyy>]` writes `LICENSE` (replacing any existing one) and sets `license:` in `ash.pkg`, so running it again with another id swaps both and leaves every other field alone. Built in as C string data (`apm/src/C/license`, about 170 KB): MIT, Apache-2.0, BSD-3-Clause, BSD-2-Clause, ISC, OFL-1.1, GPL-2.0, GPL-3.0, LGPL-2.1, LGPL-3.0. Texts are verbatim SPDX texts; MIT, BSD, ISC and OFL get the author and year filled in.
3+
14 ## 2026-10-18 (apm: the package manager, richer ash.pkg)
25 - **`forgepack` is now `apm`** ("Ash package manager"): folder `hearth/apm`, binary `bin/apm`, `make @apm`. Older changelog entries keep the old name.
36 - **`ash.pkg` carries npm-style metadata**: `name`, `version`, `description`, `author`, `license`, `homepage`, `repository`, `bugs`, `main` (entry class) and `keywords`, plus sections `[dependencies]`, `[dev-dependencies]`, `[libraries]` (external native libraries, recorded and listed only; `ashvm`/`kiln` do not consume them yet) and `[scripts]` (build instructions). Unknown sections warn; unknown header keys are ignored; files written before this change still load.

README.mdmodified

+3−0
@@ -144,8 +144,11 @@ apm add github:user/repo[@ref] [--as name] [--dev]
144144 apm install # fetch [dependencies] and [dev-dependencies] into ./@ash-modules/
145145 apm list # metadata, dependencies (and whether installed), libraries, scripts
146146 apm run <script> # run a [scripts] entry with sh -c; `apm build` / `apm test` are shorthands
147+apm license [<id>] [--author <name>] [--year <yyyy>] # list licenses / write LICENSE and set license: in ash.pkg
147148 ```
148149
150+`apm license MIT` writes a `LICENSE` file and sets `license: MIT` in `ash.pkg`; running it again with another id replaces both. The copyright holder defaults to `author:` (without the `<email>`), the year to the current year. Built in (no network): MIT, Apache-2.0, BSD-3-Clause, BSD-2-Clause, ISC, OFL-1.1, GPL-2.0, GPL-3.0, LGPL-2.1, LGPL-3.0 (texts from the SPDX list; the `-only` forms are accepted as aliases).
151+
149152 `[libraries]` records the external native libraries a package links; apm stores and lists them, but
150153 `ashvm` and `kiln` do not consume them yet. Scripts run with the same trust as `npm run`: only the
151154 project's own `ash.pkg` is consulted, never an installed dependency's.

hearth/apm/Makefilemodified

+4−1
@@ -9,7 +9,10 @@ APM_SRC = \
99 src/C/git_fetch.c \
1010 src/C/install.c \
1111 src/C/cmd.c \
12- src/C/ui.c
12+ src/C/ui.c \
13+ src/C/license/licenses.c \
14+ src/C/license/texts_permissive.c \
15+ src/C/license/texts_copyleft.c
1316
1417 # Objects and dependency files live in trees parallel to C/:
1518 # src/C/x.c -> src/O/x.o, src/D/x.d

hearth/apm/src/C/cmd.cmodified

+74−0
@@ -1,6 +1,7 @@
11 #define _XOPEN_SOURCE 700 // exposes PATH_MAX under -std=c11 (see ashvm/kiln's import_paths.c)
22 #include <stdio.h>
33 #include <stdlib.h>
4+#include <time.h>
45 #include <string.h>
56 #include <unistd.h>
67 #include <limits.h>
@@ -10,6 +11,7 @@
1011 #include "H/fsutil.h"
1112 #include "H/git_fetch.h"
1213 #include "H/ui.h"
14+#include "H/license/licenses.h"
1315
1416 static void infer_project_name(char *out, int out_size) {
1517 char cwd[PATH_MAX];
@@ -196,3 +198,75 @@ int cmd_run(const char *project_dir, int argc, char **argv) {
196198 }
197199 return 0;
198200 }
201+
202+static void print_license(const License *l) { ui_bullet("%-13s %s", l->id, l->name); }
203+
204+// apm license lists the available licenses
205+// apm license <id> [--author <name>] [--year <yyyy>]
206+// writes LICENSE (replacing any existing one) and sets `license:` in ash.pkg to <id>, so running it
207+// again with another id swaps both. The copyright holder defaults to ash.pkg's `author:` (without
208+// the <email>), the year to the current year.
209+int cmd_license(const char *project_dir, int argc, char **argv) {
210+ if (argc < 1) {
211+ ui_header("available licenses");
212+ license_each(print_license);
213+ return 0;
214+ }
215+ const License *lic = license_find(argv[0]);
216+ if (!lic) {
217+ ui_err("unknown license '%s' -- run 'apm license' to list the available ones", argv[0]);
218+ return 1;
219+ }
220+ const char *author_arg = NULL, *year_arg = NULL;
221+ for (int i = 1; i < argc; i++) {
222+ if (strcmp(argv[i], "--author") == 0 && i + 1 < argc) author_arg = argv[++i];
223+ else if (strcmp(argv[i], "--year") == 0 && i + 1 < argc) year_arg = argv[++i];
224+ else {
225+ ui_err("usage: apm license <id> [--author <name>] [--year <yyyy>]");
226+ return 1;
227+ }
228+ }
229+
230+ Manifest m;
231+ if (!manifest_load(project_dir, &m)) {
232+ char project_name[MANIFEST_NAME_LEN];
233+ infer_project_name(project_name, sizeof(project_name));
234+ manifest_init_default(&m, project_name);
235+ ui_info("no %s here, creating one", MANIFEST_FILE);
236+ }
237+
238+ char author[MANIFEST_NAME_LEN];
239+ if (author_arg) snprintf(author, sizeof(author), "%s", author_arg);
240+ else {
241+ snprintf(author, sizeof(author), "%s", m.author);
242+ char *angle = strchr(author, '<');
243+ if (angle) { *angle = '\0'; size_t n = strlen(author); while (n > 0 && author[n - 1] == ' ') author[--n] = '\0'; }
244+ }
245+ if (license_needs_author(lic) && author[0] == '\0') {
246+ ui_err("%s needs a copyright holder: pass --author <name> or set 'author:' in %s", lic->id, MANIFEST_FILE);
247+ return 1;
248+ }
249+
250+ char year[16];
251+ if (year_arg) snprintf(year, sizeof(year), "%s", year_arg);
252+ else {
253+ time_t now = time(NULL);
254+ strftime(year, sizeof(year), "%Y", localtime(&now));
255+ }
256+
257+ char *text = license_render(lic, year, author);
258+ if (!text) { ui_err("out of memory"); return 1; }
259+ char path[1024];
260+ snprintf(path, sizeof(path), "%s/LICENSE", project_dir);
261+ int existed = access(path, F_OK) == 0;
262+ FILE *f = fopen(path, "w");
263+ if (!f) { ui_err("could not write %s", path); free(text); return 1; }
264+ fputs(text, f);
265+ fclose(f);
266+ free(text);
267+
268+ snprintf(m.license, sizeof(m.license), "%s", lic->id);
269+ if (!manifest_save(project_dir, &m)) return 1;
270+ ui_ok("%s LICENSE (%s) and set license: %s in %s", existed ? "replaced" : "wrote", lic->name, lic->id, MANIFEST_FILE);
271+ return 0;
272+}

hearth/apm/src/C/license/licenses.cadded

+38−0
@@ -0,0 +1,38 @@
1+#include <stdio.h>
2+#include <stdlib.h>
3+#include <string.h>
4+#include <strings.h>
5+#include "H/license/licenses.h"
6+
7+const License *license_find(const char *id) {
8+ const License *tables[] = { licenses_permissive, licenses_copyleft };
9+ for (int t = 0; t < 2; t++) {
10+ for (const License *l = tables[t]; l->id; l++) {
11+ if (strcasecmp(l->id, id) == 0 || (l->alias && strcasecmp(l->alias, id) == 0)) return l;
12+ }
13+ }
14+ return NULL;
15+}
16+
17+void license_each(void (*fn)(const License *)) {
18+ for (const License *l = licenses_permissive; l->id; l++) fn(l);
19+ for (const License *l = licenses_copyleft; l->id; l++) fn(l);
20+}
21+
22+int license_needs_author(const License *l) {
23+ return strstr(l->text, "{{author}}") != NULL;
24+}
25+
26+char *license_render(const License *l, const char *year, const char *author) {
27+ size_t cap = strlen(l->text) + strlen(year) + strlen(author) + 1;
28+ char *out = malloc(cap);
29+ if (!out) return NULL;
30+ char *w = out;
31+ for (const char *p = l->text; *p;) {
32+ if (strncmp(p, "{{year}}", 8) == 0) { w += sprintf(w, "%s", year); p += 8; }
33+ else if (strncmp(p, "{{author}}", 10) == 0) { w += sprintf(w, "%s", author); p += 10; }
34+ else *w++ = *p++;
35+ }
36+ *w = '\0';
37+ return out;
38+}

hearth/apm/src/C/license/texts_copyleft.cadded

+839−0

Binary file or diff too large to show. View the file on GitHub

hearth/apm/src/C/license/texts_permissive.cadded

+267−0
@@ -0,0 +1,267 @@
1+#include "H/license/licenses.h"
2+
3+/* Permissive licenses. {{year}} and {{author}} are filled in by license_render(). */
4+const License licenses_permissive[] = {
5+ { "MIT", NULL, "MIT License",
6+ "MIT License\n"
7+ "\n"
8+ "Copyright (c) {{year}} {{author}}\n"
9+ "\n"
10+ "Permission is hereby granted, free of charge, to any person obtaining a copy\n"
11+ "of this software and associated documentation files (the \"Software\"), to deal\n"
12+ "in the Software without restriction, including without limitation the rights\n"
13+ "to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n"
14+ "copies of the Software, and to permit persons to whom the Software is\n"
15+ "furnished to do so, subject to the following conditions:\n"
16+ "\n"
17+ "The above copyright notice and this permission notice shall be included in all\n"
18+ "copies or substantial portions of the Software.\n"
19+ "\n"
20+ "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n"
21+ "IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n"
22+ "FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n"
23+ "AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n"
24+ "LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n"
25+ "OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n"
26+ "SOFTWARE.\n" },
27+ { "Apache-2.0", NULL, "Apache License 2.0",
28+ "Apache License\n"
29+ "Version 2.0, January 2004\n"
30+ "http://www.apache.org/licenses/\n"
31+ "\n"
32+ "TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n"
33+ "\n"
34+ "1. Definitions.\n"
35+ "\n"
36+ "\"License\" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.\n"
37+ "\n"
38+ "\"Licensor\" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.\n"
39+ "\n"
40+ "\"Legal Entity\" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, \"control\" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.\n"
41+ "\n"
42+ "\"You\" (or \"Your\") shall mean an individual or Legal Entity exercising permissions granted by this License.\n"
43+ "\n"
44+ "\"Source\" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.\n"
45+ "\n"
46+ "\"Object\" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.\n"
47+ "\n"
48+ "\"Work\" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).\n"
49+ "\n"
50+ "\"Derivative Works\" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.\n"
51+ "\n"
52+ "\"Contribution\" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, \"submitted\" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as \"Not a Contribution.\"\n"
53+ "\n"
54+ "\"Contributor\" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.\n"
55+ "\n"
56+ "2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.\n"
57+ "\n"
58+ "3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.\n"
59+ "\n"
60+ "4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:\n"
61+ "\n"
62+ " (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and\n"
63+ "\n"
64+ " (b) You must cause any modified files to carry prominent notices stating that You changed the files; and\n"
65+ "\n"
66+ " (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and\n"
67+ "\n"
68+ " (d) If the Work includes a \"NOTICE\" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.\n"
69+ "\n"
70+ " You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.\n"
71+ "\n"
72+ "5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.\n"
73+ "\n"
74+ "6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.\n"
75+ "\n"
76+ "7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.\n"
77+ "\n"
78+ "8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.\n"
79+ "\n"
80+ "9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.\n"
81+ "\n"
82+ "END OF TERMS AND CONDITIONS\n"
83+ "\n"
84+ "APPENDIX: How to apply the Apache License to your work.\n"
85+ "\n"
86+ "To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets \"[]\" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same \"printed page\" as the copyright notice for easier identification within third-party archives.\n"
87+ "\n"
88+ "Copyright [yyyy] [name of copyright owner]\n"
89+ "\n"
90+ "Licensed under the Apache License, Version 2.0 (the \"License\");\n"
91+ "you may not use this file except in compliance with the License.\n"
92+ "You may obtain a copy of the License at\n"
93+ "\n"
94+ "http://www.apache.org/licenses/LICENSE-2.0\n"
95+ "\n"
96+ "Unless required by applicable law or agreed to in writing, software\n"
97+ "distributed under the License is distributed on an \"AS IS\" BASIS,\n"
98+ "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"
99+ "See the License for the specific language governing permissions and\n"
100+ "limitations under the License.\n" },
101+ { "BSD-3-Clause", "BSD-3", "BSD 3-Clause \"New\" or \"Revised\" License",
102+ "BSD 3-Clause License\n"
103+ "\n"
104+ "Copyright (c) {{year}}, {{author}}\n"
105+ "All rights reserved.\n"
106+ "\n"
107+ "Redistribution and use in source and binary forms, with or without\n"
108+ "modification, are permitted provided that the following conditions are met:\n"
109+ "\n"
110+ "1. Redistributions of source code must retain the above copyright notice, this\n"
111+ " list of conditions and the following disclaimer.\n"
112+ "\n"
113+ "2. Redistributions in binary form must reproduce the above copyright notice,\n"
114+ " this list of conditions and the following disclaimer in the documentation\n"
115+ " and/or other materials provided with the distribution.\n"
116+ "\n"
117+ "3. Neither the name of the copyright holder nor the names of its\n"
118+ " contributors may be used to endorse or promote products derived from\n"
119+ " this software without specific prior written permission.\n"
120+ "\n"
121+ "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n"
122+ "AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n"
123+ "IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n"
124+ "DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\n"
125+ "FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n"
126+ "DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n"
127+ "SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n"
128+ "CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\n"
129+ "OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n"
130+ "OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n" },
131+ { "BSD-2-Clause", "BSD-2", "BSD 2-Clause \"Simplified\" License",
132+ "BSD 2-Clause License\n"
133+ "\n"
134+ "Copyright (c) {{year}}, {{author}}\n"
135+ "All rights reserved.\n"
136+ "\n"
137+ "Redistribution and use in source and binary forms, with or without\n"
138+ "modification, are permitted provided that the following conditions are met:\n"
139+ "\n"
140+ "1. Redistributions of source code must retain the above copyright notice, this\n"
141+ " list of conditions and the following disclaimer.\n"
142+ "\n"
143+ "2. Redistributions in binary form must reproduce the above copyright notice,\n"
144+ " this list of conditions and the following disclaimer in the documentation\n"
145+ " and/or other materials provided with the distribution.\n"
146+ "\n"
147+ "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n"
148+ "AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n"
149+ "IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n"
150+ "DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\n"
151+ "FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n"
152+ "DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n"
153+ "SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n"
154+ "CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\n"
155+ "OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n"
156+ "OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n" },
157+ { "ISC", NULL, "ISC License",
158+ "ISC License\n"
159+ "\n"
160+ "Copyright (c) {{year}}, {{author}}\n"
161+ "\n"
162+ "Permission to use, copy, modify, and/or distribute this software for any\n"
163+ "purpose with or without fee is hereby granted, provided that the above\n"
164+ "copyright notice and this permission notice appear in all copies.\n"
165+ "\n"
166+ "THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n"
167+ "REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n"
168+ "AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n"
169+ "INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n"
170+ "LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n"
171+ "OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n"
172+ "PERFORMANCE OF THIS SOFTWARE.\n" },
173+ { "OFL-1.1", NULL, "SIL Open Font License 1.1",
174+ "Copyright {{year}} {{author}}\n"
175+ "\n"
176+ "This Font Software is licensed under the SIL Open Font License, Version 1.1.\n"
177+ "This license is copied below, and is also available with a FAQ at:\n"
178+ "https://openfontlicense.org\n"
179+ "\n"
180+ "\n"
181+ "SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007\n"
182+ "-----------------------------------------------------------\n"
183+ "\n"
184+ "PREAMBLE\n"
185+ "The goals of the Open Font License (OFL) are to stimulate worldwide\n"
186+ "development of collaborative font projects, to support the font creation\n"
187+ "efforts of academic and linguistic communities, and to provide a free and\n"
188+ "open framework in which fonts may be shared and improved in partnership\n"
189+ "with others.\n"
190+ "\n"
191+ "The OFL allows the licensed fonts to be used, studied, modified and\n"
192+ "redistributed freely as long as they are not sold by themselves. The\n"
193+ "fonts, including any derivative works, can be bundled, embedded, \n"
194+ "redistributed and/or sold with any software provided that any reserved\n"
195+ "names are not used by derivative works. The fonts and derivatives,\n"
196+ "however, cannot be released under any other type of license. The\n"
197+ "requirement for fonts to remain under this license does not apply\n"
198+ "to any document created using the fonts or their derivatives.\n"
199+ "\n"
200+ "DEFINITIONS\n"
201+ "\"Font Software\" refers to the set of files released by the Copyright\n"
202+ "Holder(s) under this license and clearly marked as such. This may\n"
203+ "include source files, build scripts and documentation.\n"
204+ "\n"
205+ "\"Reserved Font Name\" refers to any names specified as such after the\n"
206+ "copyright statement(s).\n"
207+ "\n"
208+ "\"Original Version\" refers to the collection of Font Software components as\n"
209+ "distributed by the Copyright Holder(s).\n"
210+ "\n"
211+ "\"Modified Version\" refers to any derivative made by adding to, deleting,\n"
212+ "or substituting -- in part or in whole -- any of the components of the\n"
213+ "Original Version, by changing formats or by porting the Font Software to a\n"
214+ "new environment.\n"
215+ "\n"
216+ "\"Author\" refers to any designer, engineer, programmer, technical\n"
217+ "writer or other person who contributed to the Font Software.\n"
218+ "\n"
219+ "PERMISSION & CONDITIONS\n"
220+ "Permission is hereby granted, free of charge, to any person obtaining\n"
221+ "a copy of the Font Software, to use, study, copy, merge, embed, modify,\n"
222+ "redistribute, and sell modified and unmodified copies of the Font\n"
223+ "Software, subject to the following conditions:\n"
224+ "\n"
225+ "1) Neither the Font Software nor any of its individual components,\n"
226+ "in Original or Modified Versions, may be sold by itself.\n"
227+ "\n"
228+ "2) Original or Modified Versions of the Font Software may be bundled,\n"
229+ "redistributed and/or sold with any software, provided that each copy\n"
230+ "contains the above copyright notice and this license. These can be\n"
231+ "included either as stand-alone text files, human-readable headers or\n"
232+ "in the appropriate machine-readable metadata fields within text or\n"
233+ "binary files as long as those fields can be easily viewed by the user.\n"
234+ "\n"
235+ "3) No Modified Version of the Font Software may use the Reserved Font\n"
236+ "Name(s) unless explicit written permission is granted by the corresponding\n"
237+ "Copyright Holder. This restriction only applies to the primary font name as\n"
238+ "presented to the users.\n"
239+ "\n"
240+ "4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font\n"
241+ "Software shall not be used to promote, endorse or advertise any\n"
242+ "Modified Version, except to acknowledge the contribution(s) of the\n"
243+ "Copyright Holder(s) and the Author(s) or with their explicit written\n"
244+ "permission.\n"
245+ "\n"
246+ "5) The Font Software, modified or unmodified, in part or in whole,\n"
247+ "must be distributed entirely under this license, and must not be\n"
248+ "distributed under any other license. The requirement for fonts to\n"
249+ "remain under this license does not apply to any document created\n"
250+ "using the Font Software.\n"
251+ "\n"
252+ "TERMINATION\n"
253+ "This license becomes null and void if any of the above conditions are\n"
254+ "not met.\n"
255+ "\n"
256+ "DISCLAIMER\n"
257+ "THE FONT SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n"
258+ "EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF\n"
259+ "MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT\n"
260+ "OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE\n"
261+ "COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\n"
262+ "INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL\n"
263+ "DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n"
264+ "FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM\n"
265+ "OTHER DEALINGS IN THE FONT SOFTWARE.\n" },
266+ { NULL, NULL, NULL, NULL }
267+};

hearth/apm/src/C/main.cmodified

+2−0
@@ -10,6 +10,7 @@ static void print_usage(void) {
1010 printf(" apm add github:<user>/<repo>[@ref] [--as <name>] [--dev]\n");
1111 printf(" apm install\n");
1212 printf(" apm list\n");
13+ printf(" apm license [<id>] [--author <name>] [--year <yyyy>] list licenses / write LICENSE and set license: in ash.pkg\n");
1314 printf(" apm run <script> run a [scripts] entry of ash.pkg (apm build / apm test = run build / run test)\n");
1415 }
1516
@@ -25,6 +26,7 @@ int main(int argc, char **argv) {
2526 if (strcmp(command, "add") == 0) return cmd_add(project_dir, rest_argc, rest_argv);
2627 if (strcmp(command, "install") == 0) return cmd_install(project_dir, rest_argc, rest_argv);
2728 if (strcmp(command, "list") == 0) return cmd_list(project_dir, rest_argc, rest_argv);
29+ if (strcmp(command, "license") == 0) return cmd_license(project_dir, rest_argc, rest_argv);
2830 if (strcmp(command, "run") == 0) return cmd_run(project_dir, rest_argc, rest_argv);
2931 if (strcmp(command, "build") == 0 || strcmp(command, "test") == 0) {
3032 char *script[] = { (char *)command };

hearth/apm/src/D/cmd.dmodified

+2−1
@@ -1,8 +1,9 @@
11 src/O/cmd.o: src/C/cmd.c src/H/cmd.h src/H/manifest.h src/H/install.h \
2- src/H/fsutil.h src/H/git_fetch.h src/H/ui.h
2+ src/H/fsutil.h src/H/git_fetch.h src/H/ui.h src/H/license/licenses.h
33 src/H/cmd.h:
44 src/H/manifest.h:
55 src/H/install.h:
66 src/H/fsutil.h:
77 src/H/git_fetch.h:
88 src/H/ui.h:
9+src/H/license/licenses.h:

hearth/apm/src/D/license/.gitkeepadded

+0−0

No content changes. View the file on GitHub

hearth/apm/src/D/license/licenses.dadded

+3−0
@@ -0,0 +1,3 @@
1+src/O/license/licenses.o: src/C/license/licenses.c \
2+ src/H/license/licenses.h
3+src/H/license/licenses.h:

hearth/apm/src/D/license/texts_copyleft.dadded

+3−0
@@ -0,0 +1,3 @@
1+src/O/license/texts_copyleft.o: src/C/license/texts_copyleft.c \
2+ src/H/license/licenses.h
3+src/H/license/licenses.h:

hearth/apm/src/D/license/texts_permissive.dadded

+3−0
@@ -0,0 +1,3 @@
1+src/O/license/texts_permissive.o: src/C/license/texts_permissive.c \
2+ src/H/license/licenses.h
3+src/H/license/licenses.h:

hearth/apm/src/H/cmd.hmodified

+1−0
@@ -8,6 +8,7 @@ int cmd_init(const char *project_dir, int argc, char **argv);
88 int cmd_add(const char *project_dir, int argc, char **argv);
99 int cmd_install(const char *project_dir, int argc, char **argv);
1010 int cmd_list(const char *project_dir, int argc, char **argv);
11+int cmd_license(const char *project_dir, int argc, char **argv);
1112 int cmd_run(const char *project_dir, int argc, char **argv);
1213
1314 #endif

hearth/apm/src/H/license/licenses.hadded

+31−0
@@ -0,0 +1,31 @@
1+#ifndef APM_LICENSES_H
2+#define APM_LICENSES_H
3+
4+#include <stddef.h>
5+
6+// The licenses `apm license` can write, compiled in as C string data (no network, no files to ship).
7+// Texts are verbatim from the SPDX license list; MIT, BSD-2/3-Clause, ISC and OFL-1.1 contain the
8+// placeholders {{year}} and {{author}}, which license_render() fills in.
9+typedef struct {
10+ const char *id; // canonical id written to ash.pkg, e.g. "GPL-3.0"
11+ const char *alias; // also accepted on the command line (SPDX "-only" form, "BSD-3"), or NULL
12+ const char *name;
13+ const char *text;
14+} License;
15+
16+extern const License licenses_permissive[];
17+extern const License licenses_copyleft[];
18+
19+// Case-insensitive lookup by id or alias; NULL when unknown.
20+const License *license_find(const char *id);
21+
22+// Calls fn(license) for every available license, permissive ones first.
23+void license_each(void (*fn)(const License *));
24+
25+// 1 when the text has an {{author}} placeholder.
26+int license_needs_author(const License *l);
27+
28+// Returns the license text with {{year}} and {{author}} substituted (malloc'd, caller frees).
29+char *license_render(const License *l, const char *year, const char *author);
30+
31+#endif

hearth/apm/src/O/license/.gitkeepadded

+0−0

No content changes. View the file on GitHub

hearth/apm/tests/scripts/smoke_test.shmodified

+12−0
@@ -72,6 +72,18 @@ done
7272 out=$("$BIN" run test) && grep -q "^testing$" <<<"$out" || fail "apm run test"
7373 if "$BIN" run nonexistent > /dev/null 2>&1; then fail "unknown script should exit non-zero"; fi
7474
75+# licenses: write LICENSE and keep ash.pkg in sync; running again replaces both
76+"$BIN" license MIT --year 2025 > /dev/null || fail "apm license MIT"
77+grep -q "^Copyright (c) 2025 Ada <ada@example.com>$" LICENSE && fail "email must not end up in the copyright line"
78+grep -q "^Copyright (c) 2025 Ada$" LICENSE || fail "LICENSE copyright line (author from ash.pkg)"
79+grep -q "^license: MIT$" ash.pkg || fail "ash.pkg license not set to MIT"
80+"$BIN" license gpl-3.0-only > /dev/null || fail "apm license GPL-3.0 (alias, replace)"
81+grep -q "GNU GENERAL PUBLIC LICENSE" LICENSE || fail "LICENSE not replaced"
82+grep -q "^license: GPL-3.0$" ash.pkg || fail "ash.pkg license not updated"
83+grep -q "^build: echo building" ash.pkg || fail "ash.pkg lost other fields on license change"
84+"$BIN" license | grep -q "OFL-1.1" || fail "license list"
85+if "$BIN" license no-such-license > /dev/null 2>&1; then fail "unknown license should exit non-zero"; fi
86+
7587 if "$BIN" bogus-command > /dev/null 2>&1; then fail "unknown command should exit non-zero"; fi
7688
7789 echo "apm smoke test: OK"