@agentage/cli 0.70.0 → 0.72.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.
@@ -6,6 +6,7 @@ import { hostClient } from '../../lib/daemon/host-client.js';
6
6
  import { CliError } from '../../lib/json-output.js';
7
7
  import { loadKitTool } from './kit-tool.js';
8
8
  import { confirmed, report, summaryOf, terminalIo } from './lifecycle.js';
9
+ import { OWN_TEMPLATES } from './create-source.js';
9
10
  import { ignoreLocal } from './up-local.js';
10
11
  import { buildPackage, newerKitLine, npmIn } from './package-build.js';
11
12
  export const createInstallDeps = {
@@ -67,10 +68,9 @@ export const installCreated = async (folder, install, deps = createInstallDeps)
67
68
  console.log(url ? ` url ${url}` : ' url none answers yet: agentage extension list');
68
69
  return { installed, url };
69
70
  };
70
- const OWN_TEMPLATE = 'agentage/extension-template';
71
71
  // Another repo, or a branch of ours, is code nobody reviewed for you: its build script runs here.
72
72
  export const trustFrom = async (from, opts, io = terminalIo()) => {
73
- if (from === OWN_TEMPLATE)
73
+ if (OWN_TEMPLATES.includes(from))
74
74
  return;
75
75
  console.error(`template ${from}: code from that repo will be built and run on this machine`);
76
76
  if (opts.yes)
@@ -0,0 +1,10 @@
1
+ export declare const TEMPLATE = "agentage/platform:template";
2
+ export declare const OWN_TEMPLATES: string[];
3
+ export declare const fromRefusal: (from: string) => string;
4
+ export declare const repoRef: (from: string) => {
5
+ repo: string;
6
+ ref?: string;
7
+ folder?: string;
8
+ };
9
+ export declare const removeOwn: (path: string) => void;
10
+ export declare const clone: (url: string, from: string, dir: string) => Promise<void>;
@@ -0,0 +1,76 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { lstatSync, mkdtempSync, readdirSync, renameSync, rmSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ import { promisify } from 'node:util';
5
+ import { holdSignals } from '../../core/loader/dispose.js';
6
+ const run = promisify(execFile);
7
+ // The kit repo holds the template in its folder template/; the old repo held it at its root.
8
+ export const TEMPLATE = 'agentage/platform:template';
9
+ export const OWN_TEMPLATES = [TEMPLATE, 'agentage/extension-template'];
10
+ // owner/repo, then #branch and :folder, each optional: nothing that can pass for a flag or leave the repo.
11
+ const FROM = /^[\w.-]+\/[\w.-]+(?:#\w[\w./-]*)?(?::\w[\w.-]*(?:\/\w[\w.-]*)*)?$/;
12
+ export const fromRefusal = (from) => !FROM.test(from) || from.includes('..')
13
+ ? `--from ${from}: owner/repo, owner/repo#branch, either with :folder`
14
+ : '';
15
+ // --from owner/repo[#branch][:folder], checked by fromRefusal() first; a git ref has no `:`.
16
+ export const repoRef = (from) => {
17
+ const [head = from, folder] = from.split(':');
18
+ const [repo = head, ref] = head.split('#');
19
+ return { repo, ...(ref && { ref }), ...(folder && { folder }) };
20
+ };
21
+ // Bounded; git's own first line says why (no repo, no network, no access).
22
+ const gitClone = (url, from, into) => {
23
+ const { ref } = repoRef(from);
24
+ const branch = ref ? ['--branch', ref] : [];
25
+ const env = { ...process.env, GIT_TERMINAL_PROMPT: '0' };
26
+ return run('git', ['clone', '-q', '--depth', '1', ...branch, url, into], {
27
+ env,
28
+ timeout: 120_000,
29
+ }).catch((err) => {
30
+ const why = (err.stderr?.trim() || err.message).split('\n')[0];
31
+ throw new Error(`cannot clone template ${from}: ${why}`);
32
+ });
33
+ };
34
+ // Real folders on the whole path: a link could point the move and the rewrite outside the repo.
35
+ const takeFolder = (into, folder, from, dir) => {
36
+ const steps = folder.split('/').map((_, at, all) => join(into, ...all.slice(0, at + 1)));
37
+ if (!steps.every((step) => lstatSync(step, { throwIfNoEntry: false })?.isDirectory()))
38
+ throw new Error(`cannot clone template ${from}: no folder ${folder} in the repo`);
39
+ renameSync(join(into, folder), dir);
40
+ };
41
+ // No link at all (the kit's template has none); walked by hand, as a recursive readdir follows links in a loop.
42
+ const refuseLinks = (dir, from) => {
43
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
44
+ const path = join(dir, entry.name);
45
+ if (entry.isSymbolicLink())
46
+ throw new Error(`template ${from}: a symbolic link ${path}`);
47
+ if (entry.isDirectory())
48
+ refuseLinks(path, from);
49
+ }
50
+ };
51
+ // Removes only what this run made; also the Ctrl-C path, so it never throws.
52
+ export const removeOwn = (path) => rmSync(path, { recursive: true, force: true });
53
+ // A fresh name beside the new folder (a rename across disks fails), so no folder of yours is reused.
54
+ const cloneFolder = (dir, folder) => folder ? mkdtempSync(`.${dir}.clone-`) : dir;
55
+ // With :folder only that folder stays; a signal during the clone removes this run's folders, then exits as it would.
56
+ export const clone = async (url, from, dir) => {
57
+ const { folder } = repoRef(from);
58
+ const into = cloneFolder(dir, folder);
59
+ const release = holdSignals(async () => [into, dir].forEach(removeOwn));
60
+ try {
61
+ await gitClone(url, from, into);
62
+ if (folder)
63
+ takeFolder(into, folder, from, dir);
64
+ removeOwn(join(dir, '.git'));
65
+ refuseLinks(dir, from);
66
+ }
67
+ catch (err) {
68
+ removeOwn(dir);
69
+ throw err;
70
+ }
71
+ finally {
72
+ release();
73
+ if (folder)
74
+ removeOwn(into);
75
+ }
76
+ };
@@ -1,7 +1,8 @@
1
1
  import { type Command } from 'commander';
2
2
  import { installCreated } from './create-install.js';
3
+ import { TEMPLATE } from './create-source.js';
3
4
  import { type ConfirmIo } from './lifecycle.js';
4
- export declare const TEMPLATE = "agentage/extension-template";
5
+ export { TEMPLATE };
5
6
  export declare const PARTS: string[];
6
7
  export interface ExtensionCreateOptions {
7
8
  id: string;
@@ -1,20 +1,16 @@
1
- import { execFile } from 'node:child_process';
2
1
  import { existsSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
3
2
  import { join } from 'node:path';
4
- import { promisify } from 'node:util';
5
3
  import {} from 'commander';
6
4
  import { addJson, CliError } from '../../lib/json-output.js';
7
5
  import { installCreated, trustFrom } from './create-install.js';
6
+ import { clone, fromRefusal, repoRef, TEMPLATE } from './create-source.js';
8
7
  import { terminalIo } from './lifecycle.js';
9
- const run = promisify(execFile);
10
- export const TEMPLATE = 'agentage/extension-template';
8
+ export { TEMPLATE };
11
9
  export const PARTS = ['pages', 'ui', 'api', 'mcp', 'worker', 'store', 'cli', 'app'];
12
10
  const ROUTED = ['pages', 'ui', 'api', 'mcp'];
13
11
  // `_` is a separator here, so `template__echo` is the id too.
14
12
  const WORD = /(?<![A-Za-z0-9])template(?![A-Za-z0-9])/g;
15
13
  const LOCK = 'package-lock.json';
16
- // owner/repo, optionally #branch: a git ref that cannot pass for a flag or leave the repo.
17
- const FROM = /^[\w.-]+\/[\w.-]+(?:#\w[\w./-]*)?$/;
18
14
  // What else goes with a dropped part: manifest keys the kit refuses without it, the store's SQL, the contract file of api and mcp.
19
15
  const PRUNE = {
20
16
  cli: { keys: [['agentage', 'commands']] },
@@ -33,8 +29,8 @@ const refusal = ({ id, parts, from = TEMPLATE }, kept) => {
33
29
  return `id ${id} is a part name: pick another id`;
34
30
  if (!kept.some((part) => ROUTED.includes(part)))
35
31
  return `an extension needs at least one of ${ROUTED.join(', ')}`;
36
- if (!FROM.test(from) || from.includes('..'))
37
- return `--from ${from}: owner/repo or owner/repo#branch`;
32
+ if (fromRefusal(from))
33
+ return fromRefusal(from);
38
34
  return existsSync(`extension-${id}`)
39
35
  ? `extension-${id} exists: pick another id or remove it`
40
36
  : '';
@@ -54,6 +50,8 @@ const drop = (dir, kept) => {
54
50
  delete parent[path.at(-1) ?? ''];
55
51
  }
56
52
  }
53
+ // The new repo is the folder itself: a monorepo path of the template would point into nothing.
54
+ delete pkg['repository']?.['directory'];
57
55
  save(join(dir, 'package.json'), pkg);
58
56
  };
59
57
  // Every word `template` in a text file or a file name is the id: package name, host, contract.
@@ -82,26 +80,6 @@ const renameLock = (dir, id) => {
82
80
  Object.assign(at, { name });
83
81
  save(join(dir, LOCK), lock);
84
82
  };
85
- // --from owner/repo[#branch], checked by refusal() first.
86
- const repoRef = (from) => {
87
- const [repo = from, ref] = from.split('#');
88
- return { repo, ...(ref && { ref }) };
89
- };
90
- // Bounded, a partial folder removed; git's own first line says why (no repo, no network, no access).
91
- const clone = async (url, from, dir) => {
92
- const { ref } = repoRef(from);
93
- const branch = ref ? ['--branch', ref] : [];
94
- const env = { ...process.env, GIT_TERMINAL_PROMPT: '0' };
95
- await run('git', ['clone', '-q', '--depth', '1', ...branch, url, dir], {
96
- env,
97
- timeout: 120_000,
98
- }).catch((err) => {
99
- rmSync(dir, { recursive: true, force: true });
100
- const why = (err.stderr?.trim() || err.message).split('\n')[0];
101
- throw new Error(`cannot clone template ${from}: ${why}`);
102
- });
103
- rmSync(join(dir, '.git'), { recursive: true, force: true });
104
- };
105
83
  const CI = join('.github', 'workflows', 'ci.yml');
106
84
  const FLOOR = /MIN_EXECUTED: '\d+'/;
107
85
  const LOWERED = " ci MIN_EXECUTED is 1: after the first green run, set it to the gate's count";
@@ -132,14 +110,14 @@ const shape = (dir, from, id, kept) => {
132
110
  };
133
111
  const printNext = (dir, from, id, kept) => {
134
112
  const kit = String(json(join(dir, 'package.json'))['dependencies']?.['@agentage/extension'] ?? '?');
135
- const { repo, ref } = repoRef(from);
113
+ const { repo, ref, folder } = repoRef(from);
136
114
  const branch = ref ? `branch ${ref}` : 'default branch';
137
- console.log(` template ${repo} (${branch}, kit ${kit.replace(/^[\^~]/, '')})`);
115
+ console.log(` template ${repo}${folder ? `:${folder}` : ''} (${branch}, kit ${kit.replace(/^[\^~]/, '')})`);
138
116
  console.log(` kept ${kept.join(', ')}`);
139
117
  console.log(` id ${id} · host ${id}.next.agentage.io · contract ${id}.mcpc.json`);
140
118
  console.log(` next cd ${dir} && agentage extension up`);
141
119
  };
142
- // Clones the template's default branch (or the #branch of --from) into ./extension-<id> as a new working copy, no history;
120
+ // Clones the template's default branch (or the #branch of --from; only its :folder) into ./extension-<id>, no history;
143
121
  // then installs its dependencies, builds it and (unless --no-install) gives it to the daemon.
144
122
  export const runExtensionCreate = async (opts, url = (from) => `https://github.com/${from}`, after = installCreated, io = terminalIo()) => {
145
123
  const { id, from = TEMPLATE } = opts;
@@ -161,6 +139,6 @@ export const addCreate = (group, create) => addJson(group
161
139
  .description('Create ./extension-<id> from the extension template with the parts named')
162
140
  .argument('<id>', 'the extension id, also its host and contract name')
163
141
  .argument('[parts...]', `parts to keep (default: all eight): ${PARTS.join(', ')}`)
164
- .option('--from <owner/repo[#branch]>', `the template repo (default: ${TEMPLATE})`)
142
+ .option('--from <owner/repo[#branch][:folder]>', `the template repo and folder (default: ${TEMPLATE})`)
165
143
  .option('--no-install', 'build the folder, but do not give it to the daemon')
166
144
  .option('--yes', 'run code from another --from repo or branch without asking')).action((id, parts, o) => create({ id, parts, ...o }));
@@ -0,0 +1,2 @@
1
+ import type { ExtensionReleaseOptions, ReleaseDeps } from './release.js';
2
+ export declare const runChangedRelease: ({ dir, timeout, dryRun: dry }: ExtensionReleaseOptions, deps: ReleaseDeps) => Promise<unknown>;
@@ -0,0 +1,128 @@
1
+ import { join } from 'node:path';
2
+ import { CliError } from '../../lib/json-output.js';
3
+ import { writeCiCopy } from './release-folders.js';
4
+ import { imagesOf, releaseGuard } from './release-guard.js';
5
+ import { fetchTags, git, planRelease } from './release-plan.js';
6
+ import { rowsOf, summary } from './release-summary.js';
7
+ import { attach, buildImages, fail, idChecks, npmVersion, onMaster, publish, PUBLISH_SECONDS, scoped, step, takeSecrets, } from './release-steps.js';
8
+ const inputs = async (run, env) => {
9
+ const repo = env['GITHUB_REPOSITORY'];
10
+ if (!repo)
11
+ return fail('inputs: GITHUB_REPOSITORY is not set; run it in CI on a push to master');
12
+ const sha = env['GITHUB_SHA'] || (await git(run, ['rev-parse', 'HEAD'], 'inputs')).trim();
13
+ return { repo, sha };
14
+ };
15
+ // The build needs a committed tree: only the CI copy files this run wrote may differ.
16
+ const committedBut = (s) => async () => {
17
+ const args = ['status', '--porcelain', '--', '.', ...s.written.map((f) => `:(exclude)${f}`)];
18
+ const dirty = (await git(s.run, args, 'build')).trim();
19
+ if (dirty)
20
+ throw new CliError('uncommitted_changes', `uncommitted changes: ${dirty}: commit first`);
21
+ };
22
+ // Tag first: a failed build still uses up its N, so the next run takes a new version.
23
+ const createTag = async (s, tag) => {
24
+ const ref = ['-f', `ref=refs/tags/${tag}`, '-f', `sha=${s.sha}`];
25
+ const made = await s.run('gh', ['api', `repos/${s.repo}/git/refs`, ...ref]);
26
+ if (made.ok)
27
+ return step(`tag: ${tag} created on ${s.sha}`);
28
+ if (!/Reference already exists/.test(made.err))
29
+ fail(`tag: ${made.err}`);
30
+ const at = await s.run('gh', [
31
+ 'api',
32
+ `repos/${s.repo}/git/ref/tags/${tag}`,
33
+ '--jq',
34
+ '.object.sha',
35
+ ]);
36
+ const on = at.out.trim();
37
+ if (on !== s.sha)
38
+ fail(`tag: ${tag} is on ${on || at.err}, not ${s.sha}: a moved tag is refused`);
39
+ step(`tag: ${tag} is on ${s.sha}`);
40
+ };
41
+ // The date version in package.json, the lock and the committed contracts that carry it.
42
+ const prepare = async (s, p) => {
43
+ const dir = join(s.root, p.rel);
44
+ s.written.push(...(await writeCiCopy(s.root, p, p.version, s.repo)));
45
+ const tool = await s.deps.tool();
46
+ const pkg = await tool.readManifest(dir);
47
+ idChecks(pkg);
48
+ const { parts } = imagesOf(pkg);
49
+ if (parts.includes('api') || parts.includes('mcp')) {
50
+ const files = await tool
51
+ .writeContracts(dir)
52
+ .catch((e) => fail(`contracts: ${e.message}`));
53
+ s.written.push(...files.map((f) => join(p.rel, f)));
54
+ }
55
+ step(`version: ${p.id} is ${p.version} in this CI copy only`);
56
+ return pkg;
57
+ };
58
+ const npmStep = async (s, run, dir, pkg) => {
59
+ if (pkg['private'] === true)
60
+ return step('npm: private package, not published');
61
+ const push = scoped(s.deps.exec(dir, PUBLISH_SECONDS), s.secrets);
62
+ await publish(run, push, pkg, s.secrets['npm']?.['NPM_TOKEN']);
63
+ };
64
+ // A released version is never rebuilt: the guard reuses its record, else it builds the images.
65
+ const imagesStep = async (s, p, run, pkg) => {
66
+ const { parts, oneImage } = imagesOf(pkg);
67
+ const dir = join(s.root, p.rel);
68
+ const g = { dir, tag: p.tag, sha: s.sha, repo: s.repo, id: p.id, version: p.version };
69
+ const decision = await releaseGuard({ ...g, parts, oneImage }, run).catch((e) => fail(`guard: ${e.message}`));
70
+ const built = decision === 'build';
71
+ step(`guard: ${p.tag} ${built ? 'has no record and no image: build' : 'is released: npm only'}`);
72
+ return built ? buildImages(dir, oneImage, s.deps.tool, committedBut(s)) : [];
73
+ };
74
+ // The record is the "released" marker: it goes up only after npm has the version.
75
+ const releaseOne = async (s, p) => {
76
+ const pkg = await prepare(s, p);
77
+ const dir = join(s.root, p.rel);
78
+ const run = scoped(s.deps.exec(dir, s.timeout), s.secrets);
79
+ const isPrivate = pkg['private'] === true;
80
+ if (!isPrivate)
81
+ await npmVersion(run);
82
+ await createTag(s, p.tag);
83
+ const records = await imagesStep(s, p, run, pkg);
84
+ await npmStep(s, run, dir, pkg);
85
+ if (records.length > 0)
86
+ await attach(run, p.tag, s.repo, records, s.sha);
87
+ return {
88
+ id: p.id,
89
+ version: p.version,
90
+ tag: p.tag,
91
+ built: records.length > 0,
92
+ published: !isPrivate,
93
+ };
94
+ };
95
+ // Every changed extension is tried; its folder then no longer counts as a change for the next build.
96
+ const releaseAll = async (s, plan) => {
97
+ const released = [];
98
+ const rows = rowsOf(plan.refused, 'refused');
99
+ for (const p of plan.changed) {
100
+ const row = { id: p.id, version: p.version, result: 'released' };
101
+ await releaseOne(s, p).then((r) => void released.push(r), (err) => Object.assign(row, { result: 'failed', err }));
102
+ s.written.push(p.rel);
103
+ rows.push(row);
104
+ }
105
+ rows.push(...rowsOf(plan.unchanged, 'unchanged'));
106
+ summary(rows);
107
+ return released;
108
+ };
109
+ const dryRun = (plan) => {
110
+ const tags = plan.changed.map((p) => p.tag).join(', ') || 'nothing';
111
+ step(`dry run: would release ${tags}; nothing was written, tagged, pushed or published`);
112
+ summary(rowsOf(plan.refused, 'refused'));
113
+ return { dryRun: true, changed: plan.changed, unchanged: plan.unchanged.map((f) => f.id) };
114
+ };
115
+ // Each extension changed since its last <id>@* tag gets a date version, its tag, images and npm.
116
+ export const runChangedRelease = async ({ dir = '.', timeout = 60, dryRun: dry }, deps) => {
117
+ const secrets = takeSecrets(deps.env);
118
+ const run = scoped(deps.exec(dir, timeout), secrets);
119
+ const { repo, sha } = await inputs(run, deps.env);
120
+ await onMaster(run, sha);
121
+ await fetchTags(run);
122
+ const now = deps.now?.() ?? new Date();
123
+ const plan = await planRelease({ root: dir, run, sha, repo, now });
124
+ if (dry)
125
+ return dryRun(plan);
126
+ const s = { root: dir, run, deps, secrets, sha, repo, timeout, written: [] };
127
+ return { released: await releaseAll(s, plan), unchanged: plan.unchanged.map((f) => f.id) };
128
+ };
@@ -0,0 +1,6 @@
1
+ export declare const tagOf: (id: string, version: string) => string;
2
+ export declare const versionOfTag: (id: string, tag: string) => string | undefined;
3
+ export declare const newestTags: (id: string, tags: string[]) => string[];
4
+ export declare const lastTag: (id: string, tags: string[]) => string | undefined;
5
+ export declare const dayOf: (now: Date) => string;
6
+ export declare const dateVersion: (id: string, tags: string[], now: Date) => string;
@@ -0,0 +1,30 @@
1
+ // The three numbers of a plain version: no prerelease, no leading zero.
2
+ const PLAIN = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/;
3
+ export const tagOf = (id, version) => `${id}@${version}`;
4
+ // The version of `<id>@<x.y.z>`; undefined for another id or another form.
5
+ export const versionOfTag = (id, tag) => {
6
+ const version = tag.startsWith(`${id}@`) ? tag.slice(id.length + 1) : '';
7
+ return PLAIN.test(version) ? version : undefined;
8
+ };
9
+ const numbersOf = (version) => version.split('.').map(Number);
10
+ const compare = (a, b) => a[0] - b[0] || a[1] - b[1] || a[2] - b[2];
11
+ // The `<id>@*` tags newest first by number, never by text: 2027.105.1 is after 2026.1231.9.
12
+ export const newestTags = (id, tags) => {
13
+ const plain = tags.flatMap((tag) => {
14
+ const version = versionOfTag(id, tag);
15
+ return version ? [{ tag, n: numbersOf(version) }] : [];
16
+ });
17
+ return plain.sort((a, b) => compare(b.n, a.n)).map((p) => p.tag);
18
+ };
19
+ export const lastTag = (id, tags) => newestTags(id, tags)[0];
20
+ // YYYY.MDD of a UTC day: month times 100 plus day, so it never has a leading zero.
21
+ export const dayOf = (now) => `${now.getUTCFullYear()}.${(now.getUTCMonth() + 1) * 100 + now.getUTCDate()}`;
22
+ // YYYY.MDD.N: N is one more than the highest N tagged for this id on this UTC day.
23
+ export const dateVersion = (id, tags, now) => {
24
+ const day = dayOf(now);
25
+ const taken = tags
26
+ .map((tag) => versionOfTag(id, tag))
27
+ .filter((v) => v?.startsWith(`${day}.`) === true)
28
+ .map((v) => numbersOf(v)[2]);
29
+ return `${day}.${Math.max(0, ...taken) + 1}`;
30
+ };
@@ -0,0 +1,6 @@
1
+ export type Folder = {
2
+ rel: string;
3
+ id: string;
4
+ };
5
+ export declare const extensionFolders: (root: string) => Promise<Folder[]>;
6
+ export declare const writeCiCopy: (root: string, { rel }: Folder, version: string, repo: string) => Promise<string[]>;
@@ -0,0 +1,53 @@
1
+ import { readdir, readFile, writeFile } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ // A missing file reads as undefined; a file that is not JSON stops the release.
4
+ const readJson = (file) => readFile(file, 'utf8').then((text) => JSON.parse(text), () => undefined);
5
+ const idAt = async (root, rel) => {
6
+ const pkg = await readJson(join(root, rel, 'package.json'));
7
+ const id = pkg?.['agentage']?.['id'];
8
+ return typeof id === 'string' ? id : undefined;
9
+ };
10
+ // Each extensions/<name> with an agentage package; with none, the root package is the one extension.
11
+ export const extensionFolders = async (root) => {
12
+ const entries = await readdir(join(root, 'extensions'), { withFileTypes: true }).catch(() => []);
13
+ const names = entries.filter((e) => e.isDirectory()).map((e) => e.name);
14
+ const folders = [];
15
+ for (const name of names.sort()) {
16
+ const id = await idAt(root, join('extensions', name));
17
+ if (id)
18
+ folders.push({ rel: join('extensions', name), id });
19
+ }
20
+ if (folders.length > 0)
21
+ return folders;
22
+ const id = await idAt(root, '.');
23
+ return id ? [{ rel: '.', id }] : [];
24
+ };
25
+ const writeJson = async (file, value) => writeFile(file, `${JSON.stringify(value, null, 2)}\n`);
26
+ // The image source label and npm provenance both read `repository`: it names the releasing repo.
27
+ const repositoryOf = (repo, rel) => ({
28
+ type: 'git',
29
+ url: `git+https://github.com/${repo}.git`,
30
+ ...(rel === '.' ? {} : { directory: rel }),
31
+ });
32
+ // The lock's root version too, so npm ci in the image reads the same package.
33
+ const writeLock = async (root, rel, version) => {
34
+ const file = join(rel, 'package-lock.json');
35
+ const lock = await readJson(join(root, file));
36
+ if (!lock)
37
+ return [];
38
+ lock['version'] = version;
39
+ const own = lock['packages']?.[''];
40
+ if (own)
41
+ own['version'] = version;
42
+ await writeJson(join(root, file), lock);
43
+ return [file];
44
+ };
45
+ // The CI copy only: never committed. Returns the files it wrote, relative to the root.
46
+ export const writeCiCopy = async (root, { rel }, version, repo) => {
47
+ const file = join(rel, 'package.json');
48
+ const pkg = JSON.parse(await readFile(join(root, file), 'utf8'));
49
+ pkg['version'] = version;
50
+ pkg['repository'] = repositoryOf(repo, rel);
51
+ await writeJson(join(root, file), pkg);
52
+ return [file, ...(await writeLock(root, rel, version))];
53
+ };
@@ -0,0 +1,26 @@
1
+ import { type Folder } from './release-folders.js';
2
+ import { type Exec } from './release-guard.js';
3
+ export type Planned = Folder & {
4
+ version: string;
5
+ tag: string;
6
+ why: string;
7
+ };
8
+ export type Refused = Folder & {
9
+ err: unknown;
10
+ };
11
+ export type Plan = {
12
+ changed: Planned[];
13
+ unchanged: Folder[];
14
+ refused: Refused[];
15
+ };
16
+ export type PlanInput = {
17
+ root: string;
18
+ run: Exec;
19
+ sha: string;
20
+ repo: string;
21
+ now: Date;
22
+ };
23
+ export declare const UNRECORDED_LIMIT = 3;
24
+ export declare const git: (run: Exec, args: string[], what: string) => Promise<string>;
25
+ export declare const fetchTags: (run: Exec) => Promise<void>;
26
+ export declare const planRelease: (c: PlanInput) => Promise<Plan>;
@@ -0,0 +1,102 @@
1
+ import { dateVersion, lastTag, newestTags, tagOf } from './release-date.js';
2
+ import { extensionFolders } from './release-folders.js';
3
+ import { RECORD } from './release-guard.js';
4
+ import { fail, step } from './release-steps.js';
5
+ // A build that always fails stops here: no new tag after this many tags in a row with no record.
6
+ export const UNRECORDED_LIMIT = 3;
7
+ // Fail closed: a git call that cannot answer stops the release, never reads as "no change".
8
+ export const git = async (run, args, what) => {
9
+ const ran = await run('git', args);
10
+ if (!ran.ok)
11
+ fail(`${what}: git ${args[0] ?? ''}: ${ran.err}`);
12
+ return ran.out;
13
+ };
14
+ // A default CI checkout has no tags and one commit: the ancestor check needs both.
15
+ export const fetchTags = async (run) => {
16
+ const shallow = (await git(run, ['rev-parse', '--is-shallow-repository'], 'tags')).trim();
17
+ const deepen = shallow === 'true' ? ['--unshallow'] : [];
18
+ await git(run, ['fetch', '-q', '--tags', ...deepen, 'origin'], 'tags');
19
+ };
20
+ // Only "not found" means "no record"; any other answer stops the release.
21
+ const hasRecord = async (c, tag) => {
22
+ const args = ['release', 'download', tag, '-R', c.repo, '-p', RECORD, '-O', '-'];
23
+ const got = await c.run('gh', args);
24
+ if (got.ok)
25
+ return true;
26
+ if (!/release not found|no assets match|no assets to download/.test(got.err))
27
+ fail(`changed: cannot tell whether ${tag} has its record: ${got.err}`);
28
+ return false;
29
+ };
30
+ // The newest tags with no record, up to the first that has one.
31
+ const unrecorded = async (c, f, tags) => {
32
+ const missing = [];
33
+ for (const tag of newestTags(f.id, tags).slice(0, UNRECORDED_LIMIT)) {
34
+ if (await hasRecord(c, tag))
35
+ break;
36
+ missing.push(tag);
37
+ }
38
+ if (missing.length === UNRECORDED_LIMIT)
39
+ fail(`stuck: ${missing.join(', ')} have no record: fix the release, or remove those tags`);
40
+ return missing;
41
+ };
42
+ // From the last tag, not the push range: a run the concurrency group dropped is caught up here.
43
+ const whyOf = async (c, f, tags, last) => {
44
+ if (!last)
45
+ return `has no ${f.id}@* tag yet`;
46
+ const missing = await unrecorded(c, f, tags);
47
+ const diff = await git(c.run, ['diff', '--name-only', last, c.sha, '--', f.rel], 'changed');
48
+ if (diff.trim())
49
+ return `differs from ${last}`;
50
+ // A release that failed after its tag: the next commit releases it with a new N.
51
+ if (missing[0] === last)
52
+ return `equals ${last}, which has no record`;
53
+ return undefined;
54
+ };
55
+ // A re-run of an old commit must not give older code a higher version than its last tag.
56
+ const inHistory = async (c, last, at) => {
57
+ const ahead = await git(c.run, ['rev-list', '--count', `${c.sha}..${at}`], 'history');
58
+ if (ahead.trim() !== '0')
59
+ fail(`history: ${last} is on ${at}, which is not before ${c.sha}: an older commit is refused`);
60
+ };
61
+ const planned = (f, version, why) => {
62
+ const tag = tagOf(f.id, version);
63
+ step(`changed: ${f.id} (${f.rel}) ${why}: release ${tag}`);
64
+ return { ...f, version, tag, why };
65
+ };
66
+ const planOne = async (c, f) => {
67
+ const tags = (await git(c.run, ['tag', '-l', `${f.id}@*`], 'tags')).split('\n').filter(Boolean);
68
+ const last = lastTag(f.id, tags);
69
+ // A re-run of the commit its last tag is on: resume that version (the guard reuses or builds).
70
+ const at = last ? (await git(c.run, ['rev-list', '-n', '1', last], 'tags')).trim() : '';
71
+ if (last && at === c.sha)
72
+ return planned(f, last.slice(f.id.length + 1), `${last} is on this commit: resume it`);
73
+ if (last)
74
+ await inHistory(c, last, at);
75
+ const why = await whyOf(c, f, tags, last);
76
+ if (why)
77
+ return planned(f, dateVersion(f.id, tags, c.now), why);
78
+ step(`unchanged: ${f.id} (${f.rel}) is the same as ${String(last)}`);
79
+ return undefined;
80
+ };
81
+ // One refused extension never stops the plan of the others.
82
+ const sort = async (c, f, plan) => {
83
+ try {
84
+ const p = await planOne(c, f);
85
+ if (p)
86
+ plan.changed.push(p);
87
+ else
88
+ plan.unchanged.push(f);
89
+ }
90
+ catch (e) {
91
+ plan.refused.push({ ...f, err: e });
92
+ }
93
+ };
94
+ export const planRelease = async (c) => {
95
+ const folders = await extensionFolders(c.root);
96
+ if (folders.length === 0)
97
+ fail('folders: no extension package at the root or in extensions/*');
98
+ const plan = { changed: [], unchanged: [], refused: [] };
99
+ for (const f of folders)
100
+ await sort(c, f, plan);
101
+ return plan;
102
+ };
@@ -0,0 +1,15 @@
1
+ import type { ExtensionPackage } from '@agentage/extension/tool';
2
+ import { type Committed } from './build.js';
3
+ import { type LoadKitTool } from './kit-tool.js';
4
+ import { type Exec } from './release-guard.js';
5
+ export declare const step: (line: string) => void;
6
+ export declare const fail: (line: string) => never;
7
+ export declare const takeSecrets: (env: NodeJS.ProcessEnv) => Record<string, NodeJS.ProcessEnv>;
8
+ export declare const scoped: (exec: Exec, secrets: Record<string, NodeJS.ProcessEnv>) => Exec;
9
+ export declare const attach: (run: Exec, tag: string, repo: string, names: string[], target?: string) => Promise<void>;
10
+ export declare const buildImages: (dir: string, oneImage: boolean, tool: LoadKitTool, committed?: Committed) => Promise<string[]>;
11
+ export declare const PUBLISH_SECONDS = 300;
12
+ export declare const publish: (run: Exec, push: Exec, { name, version }: ExtensionPackage, token?: string) => Promise<void>;
13
+ export declare const npmVersion: (run: Exec) => Promise<void>;
14
+ export declare const idChecks: (pkg: ExtensionPackage) => void;
15
+ export declare const onMaster: (run: Exec, sha: string) => Promise<void>;
@@ -0,0 +1,112 @@
1
+ import { mkdtemp, readFile, writeFile } from 'node:fs/promises';
2
+ import { tmpdir } from 'node:os';
3
+ import { join } from 'node:path';
4
+ import { CliError } from '../../lib/json-output.js';
5
+ import { runImageBuild } from './build.js';
6
+ import {} from './kit-tool.js';
7
+ import { CONTAINER_RECORD, imagesOf, PART_SUFFIX, RECORD } from './release-guard.js';
8
+ export const step = (line) => console.log(`PASS ${line}`);
9
+ export const fail = (line) => {
10
+ throw new CliError('release_refused', `FAIL ${line}`);
11
+ };
12
+ // Tokens leave the environment, so docker build and npm lifecycle scripts never see them.
13
+ export const takeSecrets = (env) => {
14
+ const { GH_TOKEN, GITHUB_TOKEN, NPM_TOKEN } = env;
15
+ for (const name of ['GH_TOKEN', 'GITHUB_TOKEN', 'NPM_TOKEN'])
16
+ delete env[name];
17
+ const gh = GH_TOKEN ?? GITHUB_TOKEN;
18
+ return { gh: gh ? { GH_TOKEN: gh } : {}, npm: NPM_TOKEN ? { NPM_TOKEN } : {} };
19
+ };
20
+ export const scoped = (exec, secrets) => (cmd, args) => exec(cmd, args, secrets[cmd]);
21
+ // Every image is pushed first. The records go up one call each, RECORD last: it is the "done" marker.
22
+ export const attach = async (run, tag, repo, names, target) => {
23
+ const notes = ['--title', tag, '--notes', `Images by digest: ${names.join(', ')}`];
24
+ if (target)
25
+ notes.push('--target', target);
26
+ let exists = (await run('gh', ['release', 'view', tag, '-R', repo])).ok;
27
+ for (const name of names) {
28
+ const file = join('dist', name);
29
+ const args = exists ? ['upload', tag, file] : ['create', tag, file, ...notes];
30
+ const ran = await run('gh', ['release', ...args, '-R', repo]);
31
+ if (!ran.ok)
32
+ fail(`record: ${ran.err}`);
33
+ exists = true;
34
+ }
35
+ step(`record: ${names.join(', ')} attached to release ${tag}`);
36
+ };
37
+ // The part images (v13 rows, the estate) and the one image (app hosts), all pushed by digest.
38
+ export const buildImages = async (dir, oneImage, tool, committed) => {
39
+ await runImageBuild({ push: true, dir }, tool, committed);
40
+ if (!oneImage)
41
+ return [RECORD];
42
+ // The second compile may clean dist/: the part record is kept and written back.
43
+ const record = await readFile(join(dir, 'dist', RECORD));
44
+ // The first build checked this HEAD; its own dist/ output must not read as a change.
45
+ await runImageBuild({ push: true, container: true, dir }, tool, async () => undefined);
46
+ await writeFile(join(dir, 'dist', RECORD), record);
47
+ return [CONTAINER_RECORD, RECORD];
48
+ };
49
+ // Single quotes on purpose: npm expands ${NPM_TOKEN} itself, the token never lands on disk.
50
+ const tokenConfig = async (token) => {
51
+ if (!token)
52
+ return [];
53
+ const file = join(await mkdtemp(join(tmpdir(), 'agentage-npm-')), '.npmrc');
54
+ await writeFile(file, '//registry.npmjs.org/:_authToken=${NPM_TOKEN}\n');
55
+ return ['--userconfig', file];
56
+ };
57
+ // Only E404 means "not on npm"; a registry that cannot answer stops the release, never publishes.
58
+ const onNpm = async (run, args, what) => {
59
+ const viewed = await run('npm', ['view', ...args]);
60
+ if (viewed.ok)
61
+ return viewed.out.trim() !== '';
62
+ if (!/E404/.test(viewed.err))
63
+ fail(`npm: cannot tell whether ${what} is on npm: ${viewed.err}`);
64
+ return false;
65
+ };
66
+ // The upload with provenance signs first: its own bound, longer than the checks.
67
+ export const PUBLISH_SECONDS = 300;
68
+ // A killed publish may have landed: stop, never stage it again; a re-run reads "already on npm".
69
+ const direct = async (push, spec, flags) => {
70
+ const published = await push('npm', ['publish', ...flags]);
71
+ if (/timed out after/.test(published.err))
72
+ fail(`npm: publish of ${spec} ${published.err}; re-run the release: it reads "already on npm" if the upload landed`);
73
+ return published.ok;
74
+ };
75
+ // OIDC trusted publishing; a new name (NPM_TOKEN set) or an unauthorized direct publish is staged.
76
+ export const publish = async (run, push, { name, version }, token) => {
77
+ const cfg = await tokenConfig(token);
78
+ const spec = `${name}@${version}`;
79
+ if (await onNpm(run, [spec, 'version', ...cfg], spec))
80
+ return step(`npm: ${spec} is already on npm`);
81
+ const flags = ['--access', 'public', '--provenance', '--ignore-scripts', ...cfg];
82
+ const fresh = token !== undefined && !(await onNpm(run, [name, 'name', ...cfg], name));
83
+ if (!fresh && (await direct(push, spec, flags)))
84
+ return step(`npm: ${spec} published`);
85
+ const staged = await push('npm', ['stage', 'publish', ...flags]);
86
+ if (!staged.ok)
87
+ fail(`npm: ${staged.err}`);
88
+ const why = fresh
89
+ ? 'a new name has no trusted publisher'
90
+ : 'direct publish not authorized: no validated trusted publisher';
91
+ step(`npm: ${spec} staged for approval (${why})`);
92
+ };
93
+ export const npmVersion = async (run) => {
94
+ const v = (await run('npm', ['--version'])).out.trim();
95
+ const [major = 0, minor = 0, patch = 0] = v.split('.').map(Number);
96
+ if (major * 1e6 + minor * 1e3 + patch < 11_005_001)
97
+ fail(`npm: npm ${v} cannot publish with OIDC: needs npm >= 11.5.1`);
98
+ step(`npm: npm ${v}`);
99
+ };
100
+ export const idChecks = (pkg) => {
101
+ if (pkg.agentage.id === 'template')
102
+ fail('id: this repo is the starting point for extensions: create one, release that');
103
+ step(`id: ${pkg.agentage.id} is not the template`);
104
+ if (imagesOf(pkg).oneImage && PART_SUFFIX.test(pkg.agentage.id))
105
+ fail(`id: ${pkg.agentage.id} ends in a part name: it would name another extension's image`);
106
+ };
107
+ export const onMaster = async (run, sha) => {
108
+ const fetched = await run('git', ['fetch', '-q', 'origin', 'master']);
109
+ if (!fetched.ok || !(await run('git', ['merge-base', '--is-ancestor', sha, 'origin/master'])).ok)
110
+ fail(`master: ${sha} is not on master${fetched.err ? `: ${fetched.err}` : ''}`);
111
+ step(`master: ${sha} is on master`);
112
+ };
@@ -0,0 +1,11 @@
1
+ export type Row = {
2
+ id: string;
3
+ version: string;
4
+ result: string;
5
+ err?: unknown;
6
+ };
7
+ export declare const summary: (rows: Row[]) => void;
8
+ export declare const rowsOf: (folders: {
9
+ id: string;
10
+ err?: unknown;
11
+ }[], result: string) => Row[];
@@ -0,0 +1,23 @@
1
+ const messageOf = (r) => `${r.id}: ${r.err.message}`;
2
+ const table = (rows) => {
3
+ const idWidth = Math.max(2, ...rows.map((r) => r.id.length));
4
+ const versionWidth = Math.max(7, ...rows.map((r) => r.version.length));
5
+ const line = (id, version, result) => `${id.padEnd(idWidth)} ${version.padEnd(versionWidth)} ${result}`;
6
+ return [line('id', 'version', 'result'), ...rows.map((r) => line(r.id, r.version, r.result))];
7
+ };
8
+ // One table of every extension; any failure makes one non-zero exit after all were tried.
9
+ export const summary = (rows) => {
10
+ if (rows.length === 0)
11
+ return;
12
+ for (const line of table(rows))
13
+ console.log(line);
14
+ const failed = rows.filter((r) => r.err !== undefined);
15
+ const first = failed[0]?.err;
16
+ if (!first)
17
+ return;
18
+ // The first error keeps its code; its message names every failed extension.
19
+ first.message = failed.map(messageOf).join('\n');
20
+ throw first;
21
+ };
22
+ // Rows of extensions that get no version this run: refused (with its error) or unchanged.
23
+ export const rowsOf = (folders, result) => folders.map((f) => ({ id: f.id, version: '-', result, err: f.err }));
@@ -5,11 +5,15 @@ export type ExtensionReleaseOptions = {
5
5
  dir?: string;
6
6
  timeout?: number;
7
7
  json?: boolean;
8
+ changed?: boolean;
9
+ dryRun?: boolean;
8
10
  };
9
11
  export interface ReleaseDeps {
10
12
  exec: (cwd: string, seconds?: number) => Exec;
11
13
  tool: LoadKitTool;
12
14
  env: NodeJS.ProcessEnv;
15
+ now?: () => Date;
13
16
  }
14
17
  export declare const runExtensionRelease: ({ dir, timeout }?: ExtensionReleaseOptions, deps?: ReleaseDeps) => Promise<unknown>;
18
+ export declare const runRelease: (opts?: ExtensionReleaseOptions, deps?: ReleaseDeps) => Promise<unknown>;
15
19
  export declare const addRelease: (group: Command, release: (opts: ExtensionReleaseOptions) => Promise<void>) => void;
@@ -1,113 +1,13 @@
1
- import { mkdtemp, readFile, writeFile } from 'node:fs/promises';
2
- import { tmpdir } from 'node:os';
3
- import { join } from 'node:path';
4
1
  import {} from 'commander';
5
2
  import { addJson, CliError } from '../../lib/json-output.js';
6
- import { runImageBuild } from './build.js';
7
3
  import { loadKitTool } from './kit-tool.js';
8
- import { CONTAINER_RECORD, execIn, imagesOf, PART_SUFFIX, RECORD, releaseGuard, } from './release-guard.js';
9
- import {} from './release-guard.js';
4
+ import { runChangedRelease } from './release-changed.js';
5
+ import { execIn, imagesOf, releaseGuard } from './release-guard.js';
6
+ import { attach, buildImages, fail, idChecks, npmVersion, onMaster, publish, PUBLISH_SECONDS, scoped, step, takeSecrets, } from './release-steps.js';
10
7
  const defaultDeps = { exec: execIn, tool: loadKitTool, env: process.env };
11
- const step = (line) => console.log(`PASS ${line}`);
12
- const fail = (line) => {
13
- throw new CliError('release_refused', `FAIL ${line}`);
14
- };
15
- // Tokens leave the environment, so docker build and npm lifecycle scripts never see them.
16
- const takeSecrets = (env) => {
17
- const { GH_TOKEN, GITHUB_TOKEN, NPM_TOKEN } = env;
18
- for (const name of ['GH_TOKEN', 'GITHUB_TOKEN', 'NPM_TOKEN'])
19
- delete env[name];
20
- const gh = GH_TOKEN ?? GITHUB_TOKEN;
21
- return { gh: gh ? { GH_TOKEN: gh } : {}, npm: NPM_TOKEN ? { NPM_TOKEN } : {} };
22
- };
23
- const scoped = (exec, secrets) => (cmd, args) => exec(cmd, args, secrets[cmd]);
24
- // Every image is pushed first. The records go up one call each, RECORD last: it is the "done" marker.
25
- const attach = async (run, tag, repo, names) => {
26
- const notes = ['--title', tag, '--notes', `Images by digest: ${names.join(', ')}`];
27
- let exists = (await run('gh', ['release', 'view', tag, '-R', repo])).ok;
28
- for (const name of names) {
29
- const file = join('dist', name);
30
- const args = exists ? ['upload', tag, file] : ['create', tag, file, ...notes];
31
- const ran = await run('gh', ['release', ...args, '-R', repo]);
32
- if (!ran.ok)
33
- fail(`record: ${ran.err}`);
34
- exists = true;
35
- }
36
- step(`record: ${names.join(', ')} attached to release ${tag}`);
37
- };
38
- // The part images (v13 rows, the estate) and the one image (app hosts), all pushed by digest.
39
- const buildImages = async (dir, oneImage, tool) => {
40
- await runImageBuild({ push: true, dir }, tool);
41
- if (!oneImage)
42
- return [RECORD];
43
- // The second compile may clean dist/: the part record is kept and written back.
44
- const record = await readFile(join(dir, 'dist', RECORD));
45
- // The first build checked this HEAD; its own dist/ output must not read as a change.
46
- await runImageBuild({ push: true, container: true, dir }, tool, async () => undefined);
47
- await writeFile(join(dir, 'dist', RECORD), record);
48
- return [CONTAINER_RECORD, RECORD];
49
- };
50
- // Single quotes on purpose: npm expands ${NPM_TOKEN} itself, the token never lands on disk.
51
- const tokenConfig = async (token) => {
52
- if (!token)
53
- return [];
54
- const file = join(await mkdtemp(join(tmpdir(), 'agentage-npm-')), '.npmrc');
55
- await writeFile(file, '//registry.npmjs.org/:_authToken=${NPM_TOKEN}\n');
56
- return ['--userconfig', file];
57
- };
58
- // Only E404 means "not on npm"; a registry that cannot answer stops the release, never publishes.
59
- const onNpm = async (run, args, what) => {
60
- const viewed = await run('npm', ['view', ...args]);
61
- if (viewed.ok)
62
- return viewed.out.trim() !== '';
63
- if (!/E404/.test(viewed.err))
64
- fail(`npm: cannot tell whether ${what} is on npm: ${viewed.err}`);
65
- return false;
66
- };
67
- // The upload with provenance signs first: its own bound, longer than the checks.
68
- const PUBLISH_SECONDS = 300;
69
- // A killed publish may have landed: stop, never stage it again; a re-run reads "already on npm".
70
- const direct = async (push, spec, flags) => {
71
- const published = await push('npm', ['publish', ...flags]);
72
- if (/timed out after/.test(published.err))
73
- fail(`npm: publish of ${spec} ${published.err}; re-run the release: it reads "already on npm" if the upload landed`);
74
- return published.ok;
75
- };
76
- // OIDC trusted publishing; a new name (NPM_TOKEN set) or an unauthorized direct publish is staged.
77
- const publish = async (run, push, { name, version }, token) => {
78
- const cfg = await tokenConfig(token);
79
- const spec = `${name}@${version}`;
80
- if (await onNpm(run, [spec, 'version', ...cfg], spec))
81
- return step(`npm: ${spec} is already on npm`);
82
- const flags = ['--access', 'public', '--provenance', '--ignore-scripts', ...cfg];
83
- const fresh = token !== undefined && !(await onNpm(run, [name, 'name', ...cfg], name));
84
- if (!fresh && (await direct(push, spec, flags)))
85
- return step(`npm: ${spec} published`);
86
- const staged = await push('npm', ['stage', 'publish', ...flags]);
87
- if (!staged.ok)
88
- fail(`npm: ${staged.err}`);
89
- const why = fresh
90
- ? 'a new name has no trusted publisher'
91
- : 'direct publish not authorized: no validated trusted publisher';
92
- step(`npm: ${spec} staged for approval (${why})`);
93
- };
94
- const npmVersion = async (run) => {
95
- const v = (await run('npm', ['--version'])).out.trim();
96
- const [major = 0, minor = 0, patch = 0] = v.split('.').map(Number);
97
- if (major * 1e6 + minor * 1e3 + patch < 11_005_001)
98
- fail(`npm: npm ${v} cannot publish with OIDC: needs npm >= 11.5.1`);
99
- step(`npm: npm ${v}`);
100
- };
101
8
  const preflight = async (run, pkg, tag, sha, isPrivate) => {
102
- if (pkg.agentage.id === 'template')
103
- fail('id: this repo is the starting point for extensions: create one, release that');
104
- step(`id: ${pkg.agentage.id} is not the template`);
105
- if (imagesOf(pkg).oneImage && PART_SUFFIX.test(pkg.agentage.id))
106
- fail(`id: ${pkg.agentage.id} ends in a part name: it would name another extension's image`);
107
- const fetched = await run('git', ['fetch', '-q', 'origin', 'master']);
108
- if (!fetched.ok || !(await run('git', ['merge-base', '--is-ancestor', sha, 'origin/master'])).ok)
109
- fail(`master: ${sha} is not on master${fetched.err ? `: ${fetched.err}` : ''}`);
110
- step(`master: ${sha} is on master`);
9
+ idChecks(pkg);
10
+ await onMaster(run, sha);
111
11
  const v = `v${pkg.version}`;
112
12
  if (tag !== v)
113
13
  fail(`tag: ${tag} is not ${v}, the package.json version; tag the commit that sets it`);
@@ -141,10 +41,20 @@ export const runExtensionRelease = async ({ dir = '.', timeout = 60 } = {}, deps
141
41
  await publish(run, scoped(deps.exec(dir, PUBLISH_SECONDS), secrets), pkg, secrets['npm']?.['NPM_TOKEN']);
142
42
  return { id, version: pkg.version, tag, built: build, published: !isPrivate };
143
43
  };
44
+ // --changed: each changed extension of the repo; with no flag: the one package of a v* tag.
45
+ export const runRelease = async (opts = {}, deps = defaultDeps) => {
46
+ if (opts.changed)
47
+ return runChangedRelease(opts, deps);
48
+ if (opts.dryRun)
49
+ throw new CliError('invalid_argument', '--dry-run goes with --changed');
50
+ return runExtensionRelease(opts, deps);
51
+ };
144
52
  export const addRelease = (group, release) => {
145
53
  addJson(group
146
54
  .command('release')
147
55
  .description('Release an extension from its v* tag in CI: guard, images, one image, records, npm package')
148
56
  .option('--dir <path>', 'the extension package folder (default: the current folder)')
149
- .option('--timeout <seconds>', 'bound on each git, GitHub and npm check (default: 60; npm publish: 300)', Number)).action(release);
57
+ .option('--timeout <seconds>', 'bound on each git, GitHub and npm check (default: 60; npm publish: 300)', Number)
58
+ .option('--changed', 'each extension (root or extensions/*) whose folder changed since its last <id>@* tag; each keeps its own package-lock.json, shared root files never trigger a release')
59
+ .option('--dry-run', 'with --changed: print what it would release, change nothing')).action(release);
150
60
  };
@@ -13,7 +13,7 @@ import { readHidden, runConfigure, stdinInput } from './commands/extension/confi
13
13
  import { runEnabled, runInstall, runRemove, terminalIo } from './commands/extension/lifecycle.js';
14
14
  import { runList, runUpdate as runExtensionUpdate } from './commands/extension/lifecycle-list.js';
15
15
  import { loadKitTool } from './commands/extension/kit-tool.js';
16
- import { runExtensionRelease } from './commands/extension/release.js';
16
+ import { runRelease } from './commands/extension/release.js';
17
17
  import { runExtensionSetup } from './commands/extension/setup.js';
18
18
  import { runExtensionDown, runExtensionToken, runExtensionUp } from './commands/extension/up.js';
19
19
  import { runStatus, statusDeps } from './commands/status/status.js';
@@ -82,7 +82,7 @@ export const defaultDeps = {
82
82
  extensionCreate: (opts) => runExtensionCreate(opts),
83
83
  extensionCheck: (opts) => runExtensionCheck(opts),
84
84
  extensionBuild: (opts) => runExtensionBuild(opts),
85
- extensionRelease: (opts) => runExtensionRelease(opts),
85
+ extensionRelease: (opts) => runRelease(opts),
86
86
  extensionUp: (opts) => runExtensionUp(opts),
87
87
  extensionDown: (opts) => runExtensionDown(opts),
88
88
  extensionToken: (opts) => runExtensionToken(opts),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentage/cli",
3
- "version": "0.70.0",
3
+ "version": "0.72.0",
4
4
  "description": "The agentage CLI - connect this machine to agentage from the terminal",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",