@sublang/spex 4.2.0 → 5.0.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 (100) hide show
  1. package/README.md +433 -89
  2. package/dist/cli.js +80 -42
  3. package/dist/commands/add.d.ts +12 -0
  4. package/dist/commands/add.js +138 -0
  5. package/dist/commands/auth-target.d.ts +11 -0
  6. package/dist/commands/auth-target.js +50 -0
  7. package/dist/commands/environment.d.ts +123 -0
  8. package/dist/commands/environment.js +411 -0
  9. package/dist/commands/export.d.ts +21 -0
  10. package/dist/commands/export.js +663 -0
  11. package/dist/commands/home.d.ts +56 -0
  12. package/dist/commands/home.js +215 -0
  13. package/dist/commands/install.d.ts +2 -0
  14. package/dist/commands/install.js +48 -0
  15. package/dist/commands/list.d.ts +2 -0
  16. package/dist/commands/list.js +87 -0
  17. package/dist/commands/login.d.ts +2 -0
  18. package/dist/commands/login.js +211 -0
  19. package/dist/commands/logout.d.ts +2 -0
  20. package/dist/commands/logout.js +74 -0
  21. package/dist/commands/publish.d.ts +2 -0
  22. package/dist/commands/publish.js +120 -0
  23. package/dist/commands/remove.d.ts +2 -0
  24. package/dist/commands/remove.js +34 -0
  25. package/dist/commands/run.d.ts +50 -0
  26. package/dist/commands/run.js +309 -0
  27. package/dist/commands/search.d.ts +2 -0
  28. package/dist/commands/search.js +34 -0
  29. package/dist/commands/settle.d.ts +124 -0
  30. package/dist/commands/settle.js +475 -0
  31. package/dist/commands/update.d.ts +2 -0
  32. package/dist/commands/update.js +37 -0
  33. package/dist/commands/whoami.d.ts +2 -0
  34. package/dist/commands/whoami.js +75 -0
  35. package/dist/lib/environment/agent-folders.d.ts +14 -0
  36. package/dist/lib/environment/agent-folders.js +11 -0
  37. package/dist/lib/environment/archive.d.ts +26 -0
  38. package/dist/lib/environment/archive.js +91 -0
  39. package/dist/lib/environment/builtins.d.ts +112 -0
  40. package/dist/lib/environment/builtins.js +539 -0
  41. package/dist/lib/environment/citations.d.ts +75 -0
  42. package/dist/lib/environment/citations.js +267 -0
  43. package/dist/lib/environment/exports.d.ts +190 -0
  44. package/dist/lib/environment/exports.js +1029 -0
  45. package/dist/lib/environment/format.d.ts +133 -0
  46. package/dist/lib/environment/format.js +651 -0
  47. package/dist/lib/environment/git-source.d.ts +41 -0
  48. package/dist/lib/environment/git-source.js +159 -0
  49. package/dist/lib/environment/index.d.ts +20 -0
  50. package/dist/lib/environment/index.js +27 -0
  51. package/dist/lib/environment/install.d.ts +140 -0
  52. package/dist/lib/environment/install.js +694 -0
  53. package/dist/lib/environment/layout.d.ts +15 -0
  54. package/dist/lib/environment/layout.js +50 -0
  55. package/dist/lib/environment/lock.d.ts +87 -0
  56. package/dist/lib/environment/lock.js +305 -0
  57. package/dist/lib/environment/marker.d.ts +15 -0
  58. package/dist/lib/environment/marker.js +31 -0
  59. package/dist/lib/environment/own-paths.d.ts +59 -0
  60. package/dist/lib/environment/own-paths.js +174 -0
  61. package/dist/lib/environment/placed-record.d.ts +32 -0
  62. package/dist/lib/environment/placed-record.js +72 -0
  63. package/dist/lib/environment/registries.d.ts +25 -0
  64. package/dist/lib/environment/registries.js +75 -0
  65. package/dist/lib/environment/registry.d.ts +173 -0
  66. package/dist/lib/environment/registry.js +390 -0
  67. package/dist/lib/environment/requests.d.ts +108 -0
  68. package/dist/lib/environment/requests.js +403 -0
  69. package/dist/lib/environment/resolve.d.ts +70 -0
  70. package/dist/lib/environment/resolve.js +451 -0
  71. package/dist/lib/environment/semver.d.ts +30 -0
  72. package/dist/lib/environment/semver.js +130 -0
  73. package/dist/lib/environment/store.d.ts +23 -0
  74. package/dist/lib/environment/store.js +123 -0
  75. package/dist/lib/environment/tar.d.ts +27 -0
  76. package/dist/lib/environment/tar.js +219 -0
  77. package/dist/lib/files.d.ts +66 -0
  78. package/dist/lib/files.js +233 -0
  79. package/dist/lib/git-host.d.ts +579 -0
  80. package/dist/lib/git-host.js +1363 -0
  81. package/dist/lib/home-file.d.ts +124 -0
  82. package/dist/lib/home-file.js +288 -0
  83. package/dist/lib/instance.d.ts +63 -0
  84. package/dist/lib/instance.js +130 -0
  85. package/dist/lib/words.d.ts +32 -0
  86. package/dist/lib/words.js +27 -0
  87. package/dist/lint.js +8 -0
  88. package/dist/testing/index.d.ts +1 -0
  89. package/dist/testing/index.js +7 -0
  90. package/dist/testing/standin-registry.d.ts +94 -0
  91. package/dist/testing/standin-registry.js +449 -0
  92. package/package.json +37 -3
  93. package/dist/attached-cli.d.ts +0 -13
  94. package/dist/attached-cli.js +0 -249
  95. package/dist/attached-client.d.ts +0 -53
  96. package/dist/attached-client.js +0 -237
  97. package/dist/generated-protocol.d.ts +0 -2
  98. package/dist/generated-protocol.js +0 -6
  99. package/dist/package-init.d.ts +0 -21
  100. package/dist/package-init.js +0 -442
@@ -1,442 +0,0 @@
1
- // SPDX-License-Identifier: Apache-2.0
2
- // SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
3
- // `spex package init` (attached-cli-12, DR-162): a spec package folder
4
- // made from a skill folder or a spec file already at hand, in the
5
- // release layout the core reads, with no server and no Spex storage.
6
- // Every rule is checked before anything is written; a refusal writes
7
- // nothing.
8
- import { chmodSync, copyFileSync, lstatSync, mkdirSync, readdirSync, readFileSync, realpathSync, renameSync, rmdirSync, rmSync, statSync, writeFileSync, } from "node:fs";
9
- import { randomBytes } from "node:crypto";
10
- import { basename, isAbsolute, join, relative, resolve, sep } from "node:path";
11
- export const PACKAGE_INIT_USAGE = `Usage: spex package init <org>/<name> [--skill <folder>]... [--spec <file>]
12
- [--language <tag>] [--description <text>]
13
- [--license <id>] [--move]
14
-
15
- Make spex-packages/<name>/ in the current directory from skill folders
16
- and/or a spec file, with no server:
17
- --skill <folder> An Agent Skills folder holding SKILL.md; repeatable
18
- --spec <file> The spec file, named <name>.md
19
- --language <tag> The artifacts' language (default en)
20
- --description <text> Default: the first skill's description, else the
21
- first paragraph under the spec's Intent heading
22
- --license <id> Default: read from ./LICENSE, else Apache-2.0
23
- --move Move the skill folders instead of copying them`;
24
- class InitRefusal extends Error {
25
- }
26
- function refuse(message) {
27
- throw new InitRefusal(message);
28
- }
29
- /** A lowercase kebab-case name of at most 64 characters: an org, a
30
- * package's name, and an Agent Skills name alike (environments-1). */
31
- const KEBAB = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
32
- const isName = (value) => value.length <= 64 && KEBAB.test(value);
33
- // BCP 47's langtag in its common form, or a private-use tag, as the
34
- // core reads a release's language folders.
35
- const LANGTAG = new RegExp("^(?:" +
36
- "(?:[a-z]{2,3}(?:-[a-z]{3}){0,3}|[a-z]{4}|[a-z]{5,8})" +
37
- "(?:-[a-z]{4})?" +
38
- "(?:-(?:[a-z]{2}|\\d{3}))?" +
39
- "(?:-(?:[a-z\\d]{5,8}|\\d[a-z\\d]{3}))*" +
40
- "(?:-[\\da-wyz](?:-[a-z\\d]{2,8})+)*" +
41
- "(?:-x(?:-[a-z\\d]{1,8})+)?" +
42
- "|x(?:-[a-z\\d]{1,8})+" +
43
- ")$", "i");
44
- const VALUED = new Set(["skill", "spec", "language", "description", "license"]);
45
- // eslint-disable-next-line no-control-regex
46
- const CONTROL = /[\u0000-\u001f\u007f-\u009f]/;
47
- /** Parse the whole invocation before reading or writing anything. */
48
- function parseInit(args) {
49
- const words = [];
50
- const skills = [];
51
- const single = {};
52
- let move = false;
53
- for (let i = 0; i < args.length; i++) {
54
- const arg = args[i];
55
- if (!arg.startsWith("-")) {
56
- words.push(arg);
57
- continue;
58
- }
59
- const match = /^--([a-z-]+)(?:=([\s\S]*))?$/.exec(arg);
60
- const key = match?.[1];
61
- if (key === "move") {
62
- if (match[2] !== undefined)
63
- refuse("--move takes no value.");
64
- if (move)
65
- refuse("Option --move was repeated.");
66
- move = true;
67
- continue;
68
- }
69
- if (!key || !VALUED.has(key))
70
- refuse(`Unknown option ${arg.split("=")[0]}. Use spex package init --help.`);
71
- const inline = match[2];
72
- const value = inline ?? args[++i];
73
- if (value === undefined || value === "" || (inline === undefined && value.startsWith("-")))
74
- refuse(`--${key} requires a value.`);
75
- if (key === "skill") {
76
- skills.push(value);
77
- continue;
78
- }
79
- if (Object.hasOwn(single, key))
80
- refuse(`Option --${key} was repeated.`);
81
- single[key] = value;
82
- }
83
- if (words.length !== 1)
84
- refuse("package init takes exactly one <org>/<name> argument. Use spex package init --help.");
85
- const parts = words[0].split("/");
86
- if (parts.length !== 2 || !isName(parts[0]) || !isName(parts[1]))
87
- refuse("The package name must be <org>/<name>, each part lowercase letters, digits and single hyphens, at most 64 characters.");
88
- const language = single.language ?? "en";
89
- if (!LANGTAG.test(language) || language.length > 64)
90
- refuse(`--language ${JSON.stringify(language)} is not a BCP 47 language tag such as en or zh-Hans.`);
91
- if (single.description !== undefined && CONTROL.test(single.description.replace(/[\n\t]/g, " ")))
92
- refuse("--description must not hold control characters.");
93
- if (single.license !== undefined && CONTROL.test(single.license))
94
- refuse("--license must not hold control characters.");
95
- if (single.license !== undefined && !single.license.trim())
96
- refuse("--license requires a value.");
97
- if (single.description !== undefined && !single.description.trim())
98
- refuse("--description requires a value.");
99
- return {
100
- org: parts[0],
101
- name: parts[1],
102
- skills,
103
- ...(single.spec !== undefined ? { spec: single.spec } : {}),
104
- language,
105
- ...(single.description !== undefined ? { description: single.description.trim() } : {}),
106
- ...(single.license !== undefined ? { license: single.license.trim() } : {}),
107
- move,
108
- };
109
- }
110
- // -- SKILL.md frontmatter ------------------------------------------------
111
- /** Plain YAML scalars the core schema reads as no string: a skill named
112
- * so would be refused by the core's reader. */
113
- const NON_STRING = /^(?:~|null|Null|NULL|true|True|TRUE|false|False|FALSE|[-+]?[0-9]+|0o[0-7]+|0x[0-9a-fA-F]+|[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)(?:[eE][-+]?[0-9]+)?|[-+]?\.(?:inf|Inf|INF)|\.(?:nan|NaN|NAN))$/;
114
- /** A plain value YAML refuses in a block mapping, so the core's reader
115
- * reads no frontmatter at all. */
116
- const REFUSED = Symbol("refused");
117
- /** The top-level string fields of a SKILL.md's YAML frontmatter that
118
- * matter here — `name` and `description` — read from the common YAML
119
- * forms: plain, single- or double-quoted, and `|` or `>` blocks. A field
120
- * of another form reads as absent. The frontmatter is found as a
121
- * release's readers find it, from the text's first character: nothing
122
- * before `---`, a byte order mark included, is skipped. */
123
- export function skillFrontmatter(text) {
124
- const match = /^---\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/.exec(text);
125
- if (!match)
126
- return {};
127
- const lines = match[1].split(/\r?\n/);
128
- const out = {};
129
- for (let i = 0; i < lines.length; i++) {
130
- const field = /^(name|description)[ \t]*:(?:[ \t]+(.*)|)$/.exec(lines[i]);
131
- if (!field)
132
- continue;
133
- const key = field[1];
134
- // The value's continuation: the lines indented below its key.
135
- const rest = [];
136
- while (i + 1 < lines.length && (/^[ \t]/.test(lines[i + 1]) || lines[i + 1].trim() === ""))
137
- rest.push(lines[++i]);
138
- while (rest.length && rest[rest.length - 1].trim() === "")
139
- rest.pop();
140
- const value = scalar((field[2] ?? "").trim(), rest);
141
- if (value === REFUSED)
142
- out.unreadable ??= key;
143
- else if (value !== undefined)
144
- out[key] = value;
145
- }
146
- return out;
147
- }
148
- function scalar(head, rest) {
149
- const block = /^([|>])[-+]?[1-9]?(?:[ \t]+#.*)?$/.exec(head);
150
- if (block) {
151
- const indent = Math.min(...rest.filter((line) => line.trim()).map((line) => /^[ \t]*/.exec(line)[0].length));
152
- const body = rest.map((line) => line.slice(Math.min(indent, line.length)));
153
- if (block[1] === "|")
154
- return body.join("\n").trim() || undefined;
155
- return body.join("\n").split(/\n[ \t]*\n/).map((p) => p.split("\n").map((l) => l.trim()).join(" ")).join("\n").trim() || undefined;
156
- }
157
- // A nested mapping is no string.
158
- if (head === "" && rest[0] !== undefined && /^[ \t]+[^ \t#'"][^:]*:(?:[ \t]|$)/.test(rest[0]))
159
- return undefined;
160
- const joined = [head, ...rest.map((line) => line.trim())].filter((part) => part !== "").join(" ");
161
- if (joined.startsWith('"')) {
162
- const end = /^"((?:[^"\\]|\\.)*)"[ \t]*(?:#.*)?$/.exec(joined);
163
- if (!end)
164
- return undefined;
165
- // An escaped space is a space; a tab stands as it is.
166
- try {
167
- return JSON.parse(`"${end[1].replace(/\\(?=[ \t])/g, "").replace(/\t/g, "\\t")}"`);
168
- }
169
- catch {
170
- return undefined;
171
- }
172
- }
173
- if (joined.startsWith("'")) {
174
- const end = /^'((?:[^']|'')*)'[ \t]*(?:#.*)?$/.exec(joined);
175
- return end ? end[1].replace(/''/g, "'") : undefined;
176
- }
177
- const plain = joined.replace(/[ \t]+#.*$/, "").trim();
178
- if (!plain || NON_STRING.test(plain) || /^[[{&*!|>%@`]/.test(plain))
179
- return undefined;
180
- // `key: value: more` is no YAML: the whole frontmatter is refused.
181
- if (/:[ \t]/.test(plain) || plain.endsWith(":"))
182
- return REFUSED;
183
- return plain;
184
- }
185
- // -- the spec's Intent ---------------------------------------------------
186
- /** The first paragraph under a spec's Intent heading, its lines joined. */
187
- export function intentParagraph(text) {
188
- const lines = text.replace(/^/, "").split(/\r?\n/);
189
- let i = lines.findIndex((line) => /^#{1,6}[ \t]+Intent[ \t]*#*[ \t]*$/i.test(line));
190
- if (i < 0)
191
- return undefined;
192
- i++;
193
- while (i < lines.length && lines[i].trim() === "")
194
- i++;
195
- const paragraph = [];
196
- while (i < lines.length && lines[i].trim() !== "" && !/^#{1,6}(?:[ \t]|$)/.test(lines[i]))
197
- paragraph.push(lines[i++].trim());
198
- return paragraph.join(" ") || undefined;
199
- }
200
- // -- the license ---------------------------------------------------------
201
- /** The license a project's root LICENSE names (attached-cli-12). */
202
- export function detectLicense(text) {
203
- const head = (text ?? "").replace(/^/, "").trimStart();
204
- if (head.startsWith("Apache License"))
205
- return "Apache-2.0";
206
- if (head.startsWith("MIT License"))
207
- return "MIT";
208
- return "Apache-2.0";
209
- }
210
- function lstatOrNull(path) {
211
- try {
212
- return lstatSync(path);
213
- }
214
- catch (error) {
215
- if (error.code === "ENOENT" || error.code === "ENOTDIR")
216
- return null;
217
- throw error;
218
- }
219
- }
220
- /** A skill folder read whole: only folders and regular files, no link. */
221
- function readSkill(argument, cwd) {
222
- const folder = resolve(cwd, argument);
223
- const stat = lstatOrNull(folder);
224
- if (stat?.isSymbolicLink())
225
- refuse(`--skill ${argument} is a link; give the skill's own folder.`);
226
- if (!stat?.isDirectory())
227
- refuse(`--skill ${argument} is no folder holding a SKILL.md.`);
228
- const dirs = [];
229
- const files = [];
230
- const walk = (relativeDir) => {
231
- for (const entry of readdirSync(join(folder, relativeDir)).sort()) {
232
- const path = relativeDir ? `${relativeDir}/${entry}` : entry;
233
- const entryStat = lstatSync(join(folder, path));
234
- if (entryStat.isSymbolicLink())
235
- refuse(`--skill ${argument} holds a link at ${path}; a package holds files only.`);
236
- if (entryStat.isDirectory()) {
237
- dirs.push(path);
238
- walk(path);
239
- }
240
- else if (entryStat.isFile())
241
- files.push(path);
242
- else
243
- refuse(`--skill ${argument} holds a special file at ${path}; a package holds files only.`);
244
- }
245
- };
246
- walk("");
247
- if (!files.includes("SKILL.md"))
248
- refuse(`--skill ${argument} holds no SKILL.md.`);
249
- const text = readFileSync(join(folder, "SKILL.md"), "utf8");
250
- // A release's readers find the frontmatter from the first byte, so a
251
- // byte order mark would hide the name from the app and the registry.
252
- if (text.startsWith("\uFEFF"))
253
- refuse(`--skill ${argument}: its SKILL.md begins with a byte order mark, which hides its frontmatter from a package's readers; save it as UTF-8 without one.`);
254
- const frontmatter = skillFrontmatter(text);
255
- if (frontmatter.unreadable)
256
- refuse(`--skill ${argument}: its SKILL.md frontmatter is no YAML, so its name cannot be read: the ${frontmatter.unreadable} holds ": " unquoted; put the value in quotes.`);
257
- if (frontmatter.name === undefined || !isName(frontmatter.name))
258
- refuse(`--skill ${argument}: its SKILL.md declares no Agent Skills name (lowercase letters, digits and single hyphens, at most 64 characters) as its frontmatter's name.`);
259
- return { folder, id: frontmatter.name, ...(frontmatter.description ? { description: frontmatter.description } : {}), dirs, files };
260
- }
261
- /** A string as a YAML double-quoted scalar: JSON's escapes, with the
262
- * characters YAML takes as unprintable escaped too. */
263
- function quoted(value) {
264
- // eslint-disable-next-line no-control-regex
265
- return JSON.stringify(value).replace(/[\u007f-\u009f]/g, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`);
266
- }
267
- function manifestText(options, description, license, skills) {
268
- const lines = [
269
- "format: 2",
270
- `org: ${quoted(options.org)}`,
271
- `name: ${quoted(options.name)}`,
272
- `version: ${quoted("0.1.0")}`,
273
- `description: ${quoted(description)}`,
274
- `license: ${quoted(license)}`,
275
- "artifacts:",
276
- ];
277
- for (const skill of skills)
278
- lines.push(` ${quoted(skill.id)}:`, " kind: skill", ` language: ${quoted(options.language)}`);
279
- if (options.spec !== undefined)
280
- lines.push(` ${quoted(options.name)}:`, " kind: spec", ` language: ${quoted(options.language)}`);
281
- return `${lines.join("\n")}\n`;
282
- }
283
- /** Whether the folder `outer` holds `spex-packages/<name>/` of the
284
- * working folder `cwd`, compared by real paths; a folder that cannot be
285
- * read holds nothing. */
286
- function holdsDestination(outer, cwd, name) {
287
- let path;
288
- try {
289
- path = relative(realpathSync(outer), join(realpathSync(cwd), "spex-packages", name));
290
- }
291
- catch {
292
- return false;
293
- }
294
- return path === "" || (path !== ".." && !path.startsWith(`..${sep}`) && !isAbsolute(path));
295
- }
296
- function copyFile(from, to) {
297
- copyFileSync(from, to);
298
- chmodSync(to, statSync(from).mode & 0o777);
299
- }
300
- /** Make the package folder (attached-cli-12); the exit code. */
301
- export function packageInit(args, cwd = process.cwd()) {
302
- if (args.includes("--help") || args.includes("-h")) {
303
- process.stdout.write(`${PACKAGE_INIT_USAGE}\n`);
304
- return 0;
305
- }
306
- try {
307
- const options = parseInit(args);
308
- const { org, name, language } = options;
309
- const pkg = `${org}/${name}`;
310
- if (options.skills.length === 0 && options.spec === undefined)
311
- refuse("Name at least one artifact: --skill <folder> or --spec <file>.");
312
- const parent = join(cwd, "spex-packages");
313
- const destination = join(parent, name);
314
- const parentStat = lstatOrNull(parent);
315
- if (parentStat && !parentStat.isDirectory())
316
- refuse("spex-packages in the current directory is not a folder.");
317
- if (lstatOrNull(destination))
318
- refuse(`spex-packages/${name}/ already exists; nothing was written.`);
319
- const skills = [];
320
- for (const argument of options.skills) {
321
- if (options.move && holdsDestination(resolve(cwd, argument), cwd, name))
322
- refuse(`--move cannot move ${argument}: it holds spex-packages/${name}/.`);
323
- const skill = readSkill(argument, cwd);
324
- if (skills.some((other) => other.id === skill.id))
325
- refuse(`Two skills declare the id ${skill.id}; each skill needs its own name.`);
326
- if (options.spec !== undefined && skill.id === name)
327
- refuse(`The skill ${skill.id} has the spec's id ${name}; a package names each artifact once, so rename the skill or the package.`);
328
- skills.push(skill);
329
- }
330
- let specText;
331
- if (options.spec !== undefined) {
332
- const file = resolve(cwd, options.spec);
333
- let stat = null;
334
- try {
335
- stat = statSync(file);
336
- }
337
- catch {
338
- stat = null;
339
- }
340
- if (!stat?.isFile())
341
- refuse(`--spec ${options.spec} is no file.`);
342
- if (basename(file) !== `${name}.md`)
343
- refuse(`The spec file must be named ${name}.md, since its items are ${name}-<N>; rename it or the package.`);
344
- specText = readFileSync(file);
345
- }
346
- const description = options.description
347
- ?? skills[0]?.description
348
- ?? (specText ? intentParagraph(specText.toString("utf8")) : undefined);
349
- if (!description)
350
- refuse("No description was found in the first skill's SKILL.md or under the spec's Intent heading; pass --description <text>.");
351
- const licenseFile = join(cwd, "LICENSE");
352
- let licenseText;
353
- try {
354
- if (statSync(licenseFile).isFile())
355
- licenseText = readFileSync(licenseFile);
356
- }
357
- catch {
358
- licenseText = undefined;
359
- }
360
- const license = options.license ?? detectLicense(licenseText?.toString("utf8"));
361
- // Everything is written into a staging folder beside the
362
- // destination, renamed into place whole; only then are moved skill
363
- // folders removed.
364
- const madeParent = !parentStat;
365
- mkdirSync(parent, { recursive: true });
366
- // Made as any folder is, not owner-only as a temporary one.
367
- const staging = join(parent, `.${name}.init-${randomBytes(6).toString("hex")}`);
368
- mkdirSync(staging);
369
- try {
370
- writeFileSync(join(staging, "meta.yaml"), manifestText(options, description, license, skills));
371
- writeFileSync(join(staging, "README.md"), `# ${pkg}\n\n${description}\n`);
372
- if (licenseText)
373
- writeFileSync(join(staging, "LICENSE"), licenseText);
374
- for (const skill of skills) {
375
- const into = join(staging, "skills", language, skill.id);
376
- mkdirSync(into, { recursive: true });
377
- for (const dir of skill.dirs)
378
- mkdirSync(join(into, ...dir.split("/")), { recursive: true });
379
- for (const file of skill.files)
380
- copyFile(join(skill.folder, ...file.split("/")), join(into, ...file.split("/")));
381
- }
382
- if (specText) {
383
- mkdirSync(join(staging, "specs", language), { recursive: true });
384
- writeFileSync(join(staging, "specs", language, `${name}.md`), specText);
385
- }
386
- renameSync(staging, destination);
387
- }
388
- catch (error) {
389
- rmSync(staging, { recursive: true, force: true });
390
- if (madeParent) {
391
- try {
392
- rmdirSync(parent);
393
- }
394
- catch { /* holds something else now */ }
395
- }
396
- throw error;
397
- }
398
- // Each moved skill now stands in the package: its former folder goes.
399
- const left = [];
400
- if (options.move) {
401
- for (const [index, skill] of skills.entries()) {
402
- try {
403
- rmSync(skill.folder, { recursive: true, force: true });
404
- }
405
- catch (error) {
406
- left.push(`${options.skills[index]} (${error.code ?? "not removed"})`);
407
- }
408
- }
409
- }
410
- const folder = `spex-packages/${name}`;
411
- const made = [
412
- ...skills.map((skill) => `skill ${skill.id}`),
413
- ...(options.spec !== undefined ? [`spec ${name}`] : []),
414
- ].join(", ");
415
- process.stdout.write([
416
- `Made ${folder}/ for ${pkg} (${made}${options.move && skills.length ? `; ${skills.length === 1 ? "the skill folder was" : "the skill folders were"} moved into it` : ""}).`,
417
- "",
418
- "Next, in the Spex app: Playbooks → Add from folder with",
419
- ` ${pkg} and ${folder}, then Publish on its row.`,
420
- "Or with the CLI, from this folder while the Spex app runs:",
421
- ` spex package add ${pkg} --path ${folder}`,
422
- ` spex package publish ${folder} --dry-run`,
423
- " (then publish again without --dry-run)",
424
- "",
425
- ].join("\n"));
426
- if (left.length) {
427
- process.stderr.write(`The package holds a copy, but these skill folders could not be removed; remove them yourself: ${left.join(", ")}\n`);
428
- return 1;
429
- }
430
- return 0;
431
- }
432
- catch (error) {
433
- if (error instanceof InitRefusal) {
434
- process.stderr.write(`${error.message}\n`);
435
- return 1;
436
- }
437
- const code = error.code;
438
- process.stderr.write(`package init failed${code ? ` (${code})` : ""}: ${error instanceof Error ? error.message : String(error)}\n`);
439
- return 1;
440
- }
441
- }
442
- //# sourceMappingURL=package-init.js.map