@devel-solid/agentscli-hub 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +65 -2
  3. package/dist/assets/.agents/skills/agentscli-hub-edit-agents/SKILL.md +23 -0
  4. package/dist/assets/.agents/skills/agentscli-hub-edit-agents/scripts/THIRD_PARTY_LICENSES.txt +916 -0
  5. package/dist/assets/.agents/skills/agentscli-hub-edit-agents/scripts/support.mjs +16705 -0
  6. package/dist/assets/.agents/skills/agentscli-hub-edit-agents/scripts/validate.mjs +43 -0
  7. package/dist/assets/.agents/skills/agentscli-hub-publish/SKILL.md +25 -0
  8. package/dist/assets/.agents/skills/agentscli-hub-publish/references/publication.md +13 -0
  9. package/dist/assets/.agents/skills/agentscli-hub-publish/scripts/THIRD_PARTY_LICENSES.txt +916 -0
  10. package/dist/assets/.agents/skills/agentscli-hub-publish/scripts/release.mjs +551 -0
  11. package/dist/assets/.agents/skills/agentscli-hub-publish/scripts/support.mjs +16705 -0
  12. package/dist/assets/.agents/skills/agentscli-hub-write-conventions/SKILL.md +23 -0
  13. package/dist/assets/.agents/skills/agentscli-hub-write-conventions/scripts/THIRD_PARTY_LICENSES.txt +916 -0
  14. package/dist/assets/.agents/skills/agentscli-hub-write-conventions/scripts/support.mjs +16705 -0
  15. package/dist/assets/.agents/skills/agentscli-hub-write-conventions/scripts/validate.mjs +43 -0
  16. package/dist/assets/.agents/skills/agentscli-hub-write-shared-conventions/SKILL.md +23 -0
  17. package/dist/assets/.agents/skills/agentscli-hub-write-shared-conventions/scripts/THIRD_PARTY_LICENSES.txt +916 -0
  18. package/dist/assets/.agents/skills/agentscli-hub-write-shared-conventions/scripts/support.mjs +16705 -0
  19. package/dist/assets/.agents/skills/agentscli-hub-write-shared-conventions/scripts/validate.mjs +43 -0
  20. package/dist/assets/.agents/skills/agentscli-hub-write-shared-skills/SKILL.md +25 -0
  21. package/dist/assets/.agents/skills/agentscli-hub-write-shared-skills/references/resource-format.md +47 -0
  22. package/dist/assets/.agents/skills/agentscli-hub-write-shared-skills/scripts/THIRD_PARTY_LICENSES.txt +916 -0
  23. package/dist/assets/.agents/skills/agentscli-hub-write-shared-skills/scripts/support.mjs +16705 -0
  24. package/dist/assets/.agents/skills/agentscli-hub-write-shared-skills/scripts/validate.mjs +43 -0
  25. package/dist/assets/.gitattributes +4 -0
  26. package/dist/assets/AGENTS.md +23 -0
  27. package/dist/assets/README.md +13 -0
  28. package/dist/assets/agentscli-hub.yml +2 -0
  29. package/dist/assets/conventions/.gitkeep +0 -0
  30. package/dist/assets/docs/conventions/resource-authoring.md +13 -0
  31. package/dist/assets/gitignore.tpl +2 -0
  32. package/dist/assets/skills/.gitkeep +0 -0
  33. package/dist/cli.js +9 -0
  34. package/dist/runtime.js +610 -0
  35. package/package.json +37 -4
@@ -0,0 +1,551 @@
1
+ import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
+
3
+ // assets/templates/skills/agentscli-hub-publish/scripts/release.mjs
4
+ import * as nodeFs from "node:fs";
5
+ import path from "node:path";
6
+ import { pathToFileURL } from "node:url";
7
+ import { spawnSync } from "node:child_process";
8
+ import { randomUUID } from "node:crypto";
9
+ import {
10
+ inspectHub,
11
+ parseManifest,
12
+ semver,
13
+ portablePath,
14
+ fail
15
+ } from "./support.mjs";
16
+ function bumpVersion(version, impact) {
17
+ if (!semver(version) || !["patch", "minor", "major"].includes(impact))
18
+ fail("version", "Choose agent-assessed patch, minor, or major impact.");
19
+ const [major, minor, patch] = version.split(/[+-]/)[0].split(".").map(Number);
20
+ const candidate = impact === "major" ? `${major + 1}.0.0` : impact === "minor" ? `${major}.${minor + 1}.0` : `${major}.${minor}.${patch + 1}`;
21
+ if (!semver(candidate))
22
+ fail(
23
+ "version",
24
+ "Derived content version exceeds the supported safe integer range."
25
+ );
26
+ return candidate;
27
+ }
28
+ function compareVersions(a, b) {
29
+ const parts = (value) => {
30
+ const [core, pre] = value.split("+")[0].split(/-(.*)/s);
31
+ return { core: core.split(".").map(Number), pre: pre?.split(".") };
32
+ };
33
+ const left = parts(a), right = parts(b);
34
+ for (let index = 0; index < 3; index++)
35
+ if (left.core[index] !== right.core[index])
36
+ return left.core[index] - right.core[index];
37
+ if (!left.pre || !right.pre) return left.pre ? -1 : right.pre ? 1 : 0;
38
+ for (let index = 0; index < Math.max(left.pre.length, right.pre.length); index++) {
39
+ const x = left.pre[index], y = right.pre[index];
40
+ if (x === y) continue;
41
+ if (x === void 0 || y === void 0) return x === void 0 ? -1 : 1;
42
+ const xn = /^\d+$/.test(x), yn = /^\d+$/.test(y);
43
+ if (xn && yn)
44
+ return x.length === y.length ? x < y ? -1 : 1 : x.length - y.length;
45
+ if (xn !== yn) return xn ? -1 : 1;
46
+ return x < y ? -1 : 1;
47
+ }
48
+ return 0;
49
+ }
50
+ function selectVersion(baseline, impact, override) {
51
+ if (override !== void 0 && (!semver(override) || baseline && compareVersions(override, baseline) <= 0))
52
+ fail(
53
+ "version",
54
+ "An explicit version must be semantic versioning and newer than the published baseline."
55
+ );
56
+ return override ?? (baseline ? bumpVersion(baseline, impact) : "1.0.0");
57
+ }
58
+ function parseRefs(text) {
59
+ const refs = /* @__PURE__ */ new Map();
60
+ for (const line of text.trim().split(/\r?\n/)) {
61
+ if (!line) continue;
62
+ const match = /^([0-9a-f]{40}|[0-9a-f]{64})\s+(refs\/(?:heads|tags)\/[^\s]+)$/.exec(
63
+ line
64
+ );
65
+ if (!match)
66
+ fail("refs", "Native Git returned malformed remote references.");
67
+ refs.set(match[2], match[1]);
68
+ }
69
+ for (const [name, commit] of [...refs])
70
+ if (name.endsWith("^{}")) {
71
+ refs.set(name.slice(0, -3), commit);
72
+ refs.delete(name);
73
+ }
74
+ return refs;
75
+ }
76
+ function parseStatus(text) {
77
+ const parts = text.split("\0");
78
+ const files = [];
79
+ for (let index = 0; index < parts.length; index++) {
80
+ const entry = parts[index];
81
+ if (!entry) continue;
82
+ if (entry.length < 4 || entry[2] !== " ")
83
+ fail("status", "Native Git returned malformed status.");
84
+ const status = entry.slice(0, 2), file = entry.slice(3);
85
+ if (!portablePath(file))
86
+ fail("unsafe-path", "Changed path is not portable.", file);
87
+ files.push({ path: file, status });
88
+ if (/[RC]/.test(status)) {
89
+ const original = parts[++index];
90
+ if (!portablePath(original))
91
+ fail("unsafe-path", "Rename source is not portable.", original);
92
+ files.push({ path: original, status: " D" });
93
+ }
94
+ }
95
+ return files;
96
+ }
97
+ function nativeGit(args, { cwd, allowFailure = false } = {}) {
98
+ const result = spawnSync("git", ["-c", "core.hooksPath=/dev/null", ...args], {
99
+ cwd,
100
+ encoding: "utf8",
101
+ windowsHide: true,
102
+ shell: false
103
+ });
104
+ if (result.error || result.status !== 0) {
105
+ if (allowFailure) return null;
106
+ fail(
107
+ "git",
108
+ "Native Git operation failed. Check the configured destination, access, and repository state; no credentials are printed."
109
+ );
110
+ }
111
+ return result.stdout.replace(/[\r\n]+$/, "");
112
+ }
113
+ function eligible(file) {
114
+ return [
115
+ "agentscli-hub.yml",
116
+ "AGENTS.md",
117
+ "README.md",
118
+ ".gitattributes",
119
+ ".gitignore"
120
+ ].includes(file) || ["docs/conventions/", "conventions/", "skills/", ".agents/skills/"].some(
121
+ (prefix) => file.startsWith(prefix)
122
+ );
123
+ }
124
+ function safeDestination(value, label) {
125
+ if (typeof value !== "string" || !value || value.startsWith("-") || /[\x00-\x20\x7f]/.test(value))
126
+ fail("destination", `Invalid ${label}.`);
127
+ return value;
128
+ }
129
+ function optional(git, args, root) {
130
+ try {
131
+ return git(args, { cwd: root, allowFailure: true });
132
+ } catch (error) {
133
+ if (error.code === "git") return null;
134
+ throw error;
135
+ }
136
+ }
137
+ function ancestor(git, older, newer, root) {
138
+ if (older === newer) return true;
139
+ return optional(git, ["merge-base", "--is-ancestor", older, newer], root) !== null;
140
+ }
141
+ function destination(options, git, root) {
142
+ const branch = options.branch ?? optional(git, ["symbolic-ref", "--quiet", "--short", "HEAD"], root);
143
+ if (!branch)
144
+ fail(
145
+ "destination",
146
+ "A concrete branch is missing; supply --branch after resolving the intended publication branch."
147
+ );
148
+ safeDestination(branch, "branch");
149
+ if (/\.\.|[~^:?*\[\\]|\/$|^\//.test(branch))
150
+ fail("destination", "Invalid branch.");
151
+ let remote = options.remote ?? optional(git, ["config", "--get", `branch.${branch}.remote`], root);
152
+ if (!remote) {
153
+ const candidates = (git(["remote"], { cwd: root }) ?? "").split(/\r?\n/).filter(Boolean);
154
+ if (candidates.length === 1) remote = candidates[0];
155
+ }
156
+ if (!remote || remote === ".")
157
+ fail(
158
+ "destination",
159
+ "A concrete remote is missing or ambiguous; configure or supply --remote."
160
+ );
161
+ safeDestination(remote, "remote");
162
+ const endpoint = git(["remote", "get-url", "--push", remote], { cwd: root });
163
+ safeDestination(endpoint, "configured remote endpoint");
164
+ const merge = options.branch ? void 0 : optional(git, ["config", "--get", `branch.${branch}.merge`], root);
165
+ const targetBranch = merge?.startsWith("refs/heads/") ? merge.slice(11) : branch;
166
+ safeDestination(targetBranch, "destination branch");
167
+ return { remote, branch: targetBranch, localBranch: branch };
168
+ }
169
+ function prepareRelease(options, { fs = nodeFs, git = nativeGit, inspect = inspectHub } = {}) {
170
+ const root = path.resolve(options.root);
171
+ const inspection = inspect(root, { fs });
172
+ const manifest = inspection.manifest;
173
+ const target = destination(options, git, root);
174
+ const remoteRefs = parseRefs(
175
+ git(["ls-remote", target.remote, "refs/heads/*", "refs/tags/*"], {
176
+ cwd: root
177
+ })
178
+ );
179
+ const head = optional(git, ["rev-parse", "--verify", "HEAD"], root);
180
+ if (head && !/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/.test(head))
181
+ fail("git", "Unexpected HEAD identity.");
182
+ const changes = parseStatus(
183
+ git(["status", "--porcelain=v1", "-z", "--untracked-files=all"], {
184
+ cwd: root
185
+ })
186
+ );
187
+ const requested = options.paths ?? [];
188
+ for (const file of requested)
189
+ if (!portablePath(file) || !eligible(file))
190
+ fail(
191
+ "scope",
192
+ "Publication scope must contain only explicit hub resource paths.",
193
+ file
194
+ );
195
+ const selected = changes.filter(
196
+ (item) => eligible(item.path) && (!requested.length || requested.some(
197
+ (file) => item.path === file || item.path.startsWith(`${file}/`)
198
+ ))
199
+ );
200
+ for (const item of selected)
201
+ if (item.status[0] !== " " && item.status[0] !== "?" && item.status[1] !== " ")
202
+ fail(
203
+ "staging",
204
+ "A selected path has both staged and unstaged edits. Reconcile its intended content before publication.",
205
+ item.path
206
+ );
207
+ const published = [];
208
+ for (const [ref, commit2] of remoteRefs) {
209
+ const version2 = ref.startsWith("refs/tags/v") ? ref.slice(11) : void 0;
210
+ if (!semver(version2)) continue;
211
+ const content = optional(
212
+ git,
213
+ ["show", `${commit2}:agentscli-hub.yml`],
214
+ root
215
+ );
216
+ if (content === null)
217
+ fail(
218
+ "history",
219
+ "Published tag objects are not available locally. Reconcile/fetch the native Git history before retrying; preview does not fetch."
220
+ );
221
+ if (parseManifest(content).version !== version2)
222
+ fail(
223
+ "manifest-tag",
224
+ "A published tag disagrees with its committed hub manifest."
225
+ );
226
+ if (head && ancestor(git, commit2, head, root))
227
+ published.push({ version: version2, commit: commit2 });
228
+ }
229
+ published.sort((a, b) => compareVersions(b.version, a.version));
230
+ const baseline = published[0];
231
+ const localCurrentTag = optional(
232
+ git,
233
+ ["rev-parse", "--verify", `refs/tags/v${manifest.version}^{commit}`],
234
+ root
235
+ );
236
+ const currentRemoteTag = remoteRefs.get(`refs/tags/v${manifest.version}`);
237
+ if (localCurrentTag && currentRemoteTag && localCurrentTag !== currentRemoteTag)
238
+ fail("tag-conflict", "Local and remote immutable content tags disagree.");
239
+ const contentChanges = selected.filter(
240
+ (item) => item.path !== "agentscli-hub.yml"
241
+ );
242
+ const committedChanges = baseline && head ? git(["diff", "--name-only", "-z", baseline.commit, head], { cwd: root }).split("\0").filter(
243
+ (file) => file && eligible(file) && file !== "agentscli-hub.yml"
244
+ ) : [];
245
+ const unchangedPublished = baseline && manifest.version === baseline.version && selected.length === 0 && committedChanges.length === 0;
246
+ const existingCandidate = head && (localCurrentTag === head || currentRemoteTag === head) && contentChanges.length === 0;
247
+ const version = unchangedPublished ? baseline.version : existingCandidate ? manifest.version : selectVersion(baseline?.version, options.bump, options.version);
248
+ if (options.version && existingCandidate && options.version !== version)
249
+ fail(
250
+ "version",
251
+ "An unfinished candidate already exists; retry that exact candidate before creating another version."
252
+ );
253
+ const tag = `v${version}`;
254
+ const localTag = optional(
255
+ git,
256
+ ["rev-parse", "--verify", `refs/tags/${tag}^{commit}`],
257
+ root
258
+ );
259
+ const remoteTag = remoteRefs.get(`refs/tags/${tag}`);
260
+ let commit = unchangedPublished ? baseline.commit : existingCandidate ? head : void 0;
261
+ const manifestAtHead = head ? optional(git, ["show", `${head}:agentscli-hub.yml`], root) : null;
262
+ if (!commit && contentChanges.length === 0 && manifestAtHead && parseManifest(manifestAtHead).version === version && manifest.version === version)
263
+ commit = head;
264
+ if (localTag && (!commit || localTag !== commit))
265
+ fail(
266
+ "tag-conflict",
267
+ "The candidate version already has a different immutable local tag."
268
+ );
269
+ if (remoteTag && (!commit || remoteTag !== commit))
270
+ fail(
271
+ "tag-conflict",
272
+ "The candidate version already has a different immutable remote tag."
273
+ );
274
+ if (manifest.version !== version && manifest.version !== baseline?.version)
275
+ fail(
276
+ "manifest-version",
277
+ "The working manifest is neither the published baseline nor this exact candidate."
278
+ );
279
+ const branchRef = `refs/heads/${target.branch}`;
280
+ const remoteBranch = remoteRefs.get(branchRef);
281
+ if (remoteBranch && head && !ancestor(git, remoteBranch, head, root) && !(commit && ancestor(git, commit, remoteBranch, root)))
282
+ fail(
283
+ "diverged",
284
+ "The publication branch diverged or required objects are unavailable. Reconcile native Git history before retrying."
285
+ );
286
+ const branchVerified = !!commit && !!remoteBranch && ancestor(git, commit, remoteBranch, root);
287
+ const tagVerified = !!commit && remoteTag === commit;
288
+ const noChanges = (existingCandidate || unchangedPublished) && branchVerified && tagVerified && selected.length === 0;
289
+ return {
290
+ root,
291
+ ...target,
292
+ baseline: baseline?.version,
293
+ version,
294
+ tag,
295
+ commit,
296
+ head,
297
+ branchRef,
298
+ remoteBranch,
299
+ remoteTag,
300
+ localTag,
301
+ branchVerified,
302
+ tagVerified,
303
+ noChanges,
304
+ paths: [
305
+ .../* @__PURE__ */ new Set([...selected.map((item) => item.path), "agentscli-hub.yml"])
306
+ ].sort(),
307
+ manifestText: `schemaVersion: 1
308
+ version: ${version}
309
+ `,
310
+ effects: noChanges ? [] : [
311
+ !commit && "manifest/commit",
312
+ !localTag && "tag",
313
+ !branchVerified && "push-branch",
314
+ !tagVerified && "push-tag"
315
+ ].filter(Boolean)
316
+ };
317
+ }
318
+ function verifyRelease(candidate, { git = nativeGit } = {}) {
319
+ if (!candidate.commit) return { ok: false, branch: false, tag: false };
320
+ const refs = parseRefs(
321
+ git(
322
+ [
323
+ "ls-remote",
324
+ candidate.remote,
325
+ candidate.branchRef,
326
+ `refs/tags/${candidate.tag}`,
327
+ `refs/tags/${candidate.tag}^{}`
328
+ ],
329
+ { cwd: candidate.root }
330
+ )
331
+ );
332
+ const remoteBranch = refs.get(candidate.branchRef);
333
+ const remoteTag = refs.get(`refs/tags/${candidate.tag}`);
334
+ if (remoteTag && remoteTag !== candidate.commit)
335
+ fail("tag-conflict", "The remote tag identifies a conflicting commit.");
336
+ const branch = !!remoteBranch && ancestor(git, candidate.commit, remoteBranch, candidate.root);
337
+ const tag = remoteTag === candidate.commit;
338
+ return { ok: branch && tag, branch, tag };
339
+ }
340
+ function publishRelease(options, adapters = {}) {
341
+ const { fs = nodeFs, git = nativeGit, inspect = inspectHub } = adapters;
342
+ let candidate;
343
+ const completed = [];
344
+ try {
345
+ candidate = prepareRelease(options, { fs, git, inspect });
346
+ if (options.preview)
347
+ return {
348
+ ok: true,
349
+ preview: true,
350
+ candidate,
351
+ completed,
352
+ pending: candidate.effects
353
+ };
354
+ if (candidate.noChanges)
355
+ return { ok: true, noChanges: true, candidate, completed, pending: [] };
356
+ if (!candidate.commit) {
357
+ const manifestFile = path.join(candidate.root, "agentscli-hub.yml");
358
+ if (fs.readFileSync(manifestFile, "utf8") !== candidate.manifestText) {
359
+ const temporary = path.join(
360
+ candidate.root,
361
+ `.agentscli-hub-${randomUUID()}.tmp`
362
+ );
363
+ try {
364
+ fs.writeFileSync(temporary, candidate.manifestText, { flag: "wx" });
365
+ fs.renameSync(temporary, manifestFile);
366
+ } finally {
367
+ if (fs.existsSync(temporary)) fs.unlinkSync(temporary);
368
+ }
369
+ }
370
+ completed.push("manifest");
371
+ inspect(candidate.root, { fs });
372
+ git(["add", "--", ...candidate.paths], { cwd: candidate.root });
373
+ git(
374
+ [
375
+ "commit",
376
+ "--only",
377
+ "-m",
378
+ `Release hub ${candidate.tag}`,
379
+ "--",
380
+ ...candidate.paths
381
+ ],
382
+ { cwd: candidate.root }
383
+ );
384
+ candidate.commit = git(["rev-parse", "--verify", "HEAD"], {
385
+ cwd: candidate.root
386
+ });
387
+ completed.push("commit");
388
+ }
389
+ const committed = git(["show", `${candidate.commit}:agentscli-hub.yml`], {
390
+ cwd: candidate.root
391
+ });
392
+ if (parseManifest(committed).version !== candidate.version)
393
+ fail("manifest-tag", "Candidate commit and manifest disagree.");
394
+ const localTag = optional(
395
+ git,
396
+ ["rev-parse", "--verify", `refs/tags/${candidate.tag}^{commit}`],
397
+ candidate.root
398
+ );
399
+ if (localTag && localTag !== candidate.commit)
400
+ fail("tag-conflict", "Immutable local candidate tag conflicts.");
401
+ if (!localTag) {
402
+ git(["tag", candidate.tag, candidate.commit], { cwd: candidate.root });
403
+ completed.push("tag");
404
+ }
405
+ let status = verifyRelease(candidate, { git });
406
+ if (!status.branch) {
407
+ git(
408
+ [
409
+ "push",
410
+ candidate.remote,
411
+ `${candidate.commit}:${candidate.branchRef}`
412
+ ],
413
+ { cwd: candidate.root }
414
+ );
415
+ completed.push("push-branch");
416
+ }
417
+ if (!status.tag) {
418
+ git(
419
+ [
420
+ "push",
421
+ candidate.remote,
422
+ `refs/tags/${candidate.tag}:refs/tags/${candidate.tag}`
423
+ ],
424
+ { cwd: candidate.root }
425
+ );
426
+ completed.push("push-tag");
427
+ }
428
+ status = verifyRelease(candidate, { git });
429
+ if (!status.ok)
430
+ return {
431
+ ok: false,
432
+ candidate,
433
+ completed,
434
+ pending: [
435
+ !status.branch && "verify-branch",
436
+ !status.tag && "verify-tag"
437
+ ].filter(Boolean),
438
+ message: "Delivery is partial. Retry this exact candidate after inspecting native refs."
439
+ };
440
+ completed.push("verify");
441
+ return { ok: true, candidate, completed, pending: [] };
442
+ } catch (error) {
443
+ if (candidate?.commit) {
444
+ try {
445
+ const status = verifyRelease(candidate, { git });
446
+ if (status.ok)
447
+ return {
448
+ ok: true,
449
+ candidate,
450
+ completed: [...completed, "verify"],
451
+ pending: []
452
+ };
453
+ return {
454
+ ok: false,
455
+ candidate,
456
+ completed,
457
+ pending: [
458
+ !status.branch && "push/verify-branch",
459
+ !status.tag && "push/verify-tag"
460
+ ].filter(Boolean),
461
+ code: error.code ?? "operation",
462
+ message: "Delivery is partial or uncertain. Retry the exact content version and commit after inspecting native refs."
463
+ };
464
+ } catch {
465
+ }
466
+ }
467
+ return {
468
+ ok: false,
469
+ candidate,
470
+ completed,
471
+ pending: candidate ? ["reconcile-same-candidate"] : ["preflight"],
472
+ ...error.file ? { file: error.file } : {},
473
+ code: error.code ?? "operation",
474
+ message: error.code ? error.message : "Hub release stopped. Reconcile native Git state and retry the same candidate."
475
+ };
476
+ }
477
+ }
478
+ function parseArgs(args) {
479
+ const mode = args[0];
480
+ if (!["plan", "publish", "verify"].includes(mode))
481
+ fail(
482
+ "arguments",
483
+ "Use plan, publish, or verify with --repo-root and agent-assessed --bump."
484
+ );
485
+ const result = { mode, paths: [] };
486
+ for (let index = 1; index < args.length; index += 2) {
487
+ const flag = args[index], value = args[index + 1];
488
+ const fields = {
489
+ "--repo-root": "root",
490
+ "--bump": "bump",
491
+ "--version": "version",
492
+ "--remote": "remote",
493
+ "--branch": "branch"
494
+ };
495
+ if (!value || value.startsWith("--") || !fields[flag] && flag !== "--path")
496
+ fail("arguments", "Invalid release helper argument.");
497
+ if (flag === "--path") result.paths.push(value);
498
+ else {
499
+ if (result[fields[flag]])
500
+ fail("arguments", "Repeated release helper argument.");
501
+ result[fields[flag]] = value;
502
+ }
503
+ }
504
+ if (!result.root || !result.version && !["patch", "minor", "major"].includes(result.bump))
505
+ fail(
506
+ "arguments",
507
+ "Supply --repo-root and an assessed --bump (or explicit user --version)."
508
+ );
509
+ return result;
510
+ }
511
+ function main(args, { log = console.log, error = console.error, ...adapters } = {}) {
512
+ try {
513
+ const options = parseArgs(args);
514
+ if (options.mode === "verify") {
515
+ const candidate = prepareRelease(options, adapters);
516
+ const status = verifyRelease(candidate, adapters);
517
+ log(JSON.stringify({ ...status, candidate }));
518
+ return status.ok ? 0 : 3;
519
+ }
520
+ const result = publishRelease(
521
+ { ...options, preview: options.mode === "plan" },
522
+ adapters
523
+ );
524
+ log(JSON.stringify(result));
525
+ return result.ok ? 0 : result.candidate ? 3 : 2;
526
+ } catch (cause) {
527
+ error(
528
+ JSON.stringify({
529
+ ok: false,
530
+ code: cause.code ?? "operation",
531
+ message: cause.code ? cause.message : "Release helper failed."
532
+ })
533
+ );
534
+ return cause.code ? 2 : 3;
535
+ }
536
+ }
537
+ if (process.argv[1] && import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href)
538
+ process.exitCode = main(process.argv.slice(2));
539
+ export {
540
+ bumpVersion,
541
+ compareVersions,
542
+ main,
543
+ nativeGit,
544
+ parseArgs,
545
+ parseRefs,
546
+ parseStatus,
547
+ prepareRelease,
548
+ publishRelease,
549
+ selectVersion,
550
+ verifyRelease
551
+ };