@agentage/cli 0.71.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
|
|
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
|
|
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
|
-
|
|
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 (
|
|
37
|
-
return
|
|
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
|
|
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 }));
|