create-atm 0.1.16 → 0.1.17
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.
- package/dist/build-identity.json +18 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +71 -8
- package/package.json +2 -2
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaId": "atm.runtimeBuildIdentity.v1",
|
|
3
|
+
"sourceCommit": "e4202216428f801ad58618de853a3989d601f931",
|
|
4
|
+
"sourceDigest": "ba283c15402c904a00d6823d199399587f53fbb2be00ce86a82be1afc56ca9d0",
|
|
5
|
+
"packageName": "create-atm",
|
|
6
|
+
"version": "0.1.17",
|
|
7
|
+
"files": [
|
|
8
|
+
{
|
|
9
|
+
"path": "index.d.ts",
|
|
10
|
+
"sha256": "336cb2da4ce17400f99e6d3b275f2af5bc895d34ee8466a5d5b91dafe97b473e"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"path": "index.js",
|
|
14
|
+
"sha256": "b0634ece9b92387781954bcadf837cc068ce894ce0bc3d84a03cd180ed326615"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"buildId": "9a494660d24a845ecdeb901e4c8b0d2627406da88db23f0d2c2265b1d8b211a4"
|
|
18
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,4 +4,7 @@ export declare const createAtmPackage: {
|
|
|
4
4
|
readonly packageRole: "npm-create-governance-onboarding";
|
|
5
5
|
readonly packageVersion: "0.0.0";
|
|
6
6
|
};
|
|
7
|
+
type CreateAtmDistTag = 'latest' | 'next' | 'beta' | 'lts';
|
|
7
8
|
export declare function runCreateAtm(argv?: string[]): number;
|
|
9
|
+
export declare function parseExactCliVersion(value: string, tag: CreateAtmDistTag): string;
|
|
10
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -11,18 +11,18 @@ export const createAtmPackage = {
|
|
|
11
11
|
export function runCreateAtm(argv = process.argv.slice(2)) {
|
|
12
12
|
const startedAt = Date.now();
|
|
13
13
|
if (argv.includes('--help') || argv.includes('-h')) {
|
|
14
|
-
process.stdout.write('Usage: create-atm <project-name> [--agent <pack-id>] [--cwd <dir>] [--json]\n');
|
|
14
|
+
process.stdout.write('Usage: create-atm <project-name> [--agent <pack-id>] [--cwd <dir>] [--tag latest|next|beta|lts] [--cli-version <exact-semver>] [--json]\n');
|
|
15
15
|
return 0;
|
|
16
16
|
}
|
|
17
17
|
const options = parseArgs(argv);
|
|
18
|
+
const distTag = resolveCreateAtmDistTag(options.tag, argv.includes('--tag'), options.cliVersion);
|
|
18
19
|
const targetRoot = path.resolve(options.cwd, options.projectName);
|
|
19
20
|
ensureCreatableTarget(targetRoot);
|
|
20
21
|
mkdirSync(targetRoot, { recursive: true });
|
|
21
|
-
const distTag = resolveCreateAtmDistTag(options.tag);
|
|
22
22
|
writeDistTagSelection(targetRoot, distTag);
|
|
23
23
|
let atmExecution = resolveAtmExecutionPlan(distTag.requestedTag);
|
|
24
24
|
const steps = [];
|
|
25
|
-
if (atmExecution.source !== 'source-tree') {
|
|
25
|
+
if (options.cliVersion || atmExecution.source !== 'source-tree') {
|
|
26
26
|
const runtime = installTargetRuntime(targetRoot, distTag.npmPackageSpec);
|
|
27
27
|
steps.push(runtime.step);
|
|
28
28
|
if (runtime.execution)
|
|
@@ -47,6 +47,8 @@ export function runCreateAtm(argv = process.argv.slice(2)) {
|
|
|
47
47
|
if (result.exitCode !== 0)
|
|
48
48
|
break;
|
|
49
49
|
}
|
|
50
|
+
if (steps.every((step) => step.exitCode === 0))
|
|
51
|
+
steps.push(createInitialCommit(targetRoot));
|
|
50
52
|
const failedStep = steps.find((step) => step.exitCode !== 0);
|
|
51
53
|
const payload = {
|
|
52
54
|
ok: failedStep === undefined,
|
|
@@ -54,7 +56,7 @@ export function runCreateAtm(argv = process.argv.slice(2)) {
|
|
|
54
56
|
cwd: options.cwd,
|
|
55
57
|
messages: [
|
|
56
58
|
failedStep
|
|
57
|
-
? { level: 'error', code: 'ATM_CREATE_FAILED', text: `create-atm failed at step: ${failedStep.name}` }
|
|
59
|
+
? { level: 'error', code: 'ATM_CREATE_FAILED', text: `create-atm failed at step: ${failedStep.name}${failedStep.name === 'initial commit' ? `. ${failedStep.stderr.trim()}` : ''}` }
|
|
58
60
|
: { level: 'info', code: 'ATM_CREATE_READY', text: `ATM governance project created at ${targetRoot}` }
|
|
59
61
|
],
|
|
60
62
|
evidence: {
|
|
@@ -75,6 +77,33 @@ export function runCreateAtm(argv = process.argv.slice(2)) {
|
|
|
75
77
|
writePayload(payload, options.json);
|
|
76
78
|
return failedStep ? failedStep.exitCode : 0;
|
|
77
79
|
}
|
|
80
|
+
function createInitialCommit(targetRoot) {
|
|
81
|
+
const startedAt = Date.now();
|
|
82
|
+
const env = { ...process.env };
|
|
83
|
+
for (const key of ['GIT_DIR', 'GIT_WORK_TREE', 'GIT_INDEX_FILE', 'GIT_COMMON_DIR', 'GIT_OBJECT_DIRECTORY', 'GIT_ALTERNATE_OBJECT_DIRECTORIES'])
|
|
84
|
+
delete env[key];
|
|
85
|
+
const run = (...args) => spawnSync('git', ['-C', targetRoot, ...args], { encoding: 'utf8', env, windowsHide: true, timeout: 30_000 });
|
|
86
|
+
const result = (exitCode, stderr, stdout = '') => ({ name: 'initial commit', exitCode, stderr, stdout, durationMs: Date.now() - startedAt });
|
|
87
|
+
const init = run('init', '--quiet');
|
|
88
|
+
if (init.status !== 0)
|
|
89
|
+
return result(init.status ?? 1, init.stderr || init.error?.message || 'Git initialization failed.');
|
|
90
|
+
const top = run('rev-parse', '--show-toplevel');
|
|
91
|
+
if (top.status !== 0 || realpathSync(top.stdout.trim()) !== realpathSync(targetRoot))
|
|
92
|
+
return result(1, 'Git root does not match the new project; no files were staged.');
|
|
93
|
+
const name = run('config', 'user.name').stdout.trim();
|
|
94
|
+
const email = run('config', 'user.email').stdout.trim();
|
|
95
|
+
if ((!name && (!env.GIT_AUTHOR_NAME || !env.GIT_COMMITTER_NAME)) || (!email && (!env.GIT_AUTHOR_EMAIL || !env.GIT_COMMITTER_EMAIL))) {
|
|
96
|
+
return result(1, 'Configure Git user.name and user.email, then create the initial commit in the generated project. Generated files are preserved.');
|
|
97
|
+
}
|
|
98
|
+
if (existsSync(path.join(targetRoot, 'node_modules')) && run('check-ignore', '--quiet', 'node_modules').status !== 0) {
|
|
99
|
+
return result(1, 'Project dependencies are not ignored; no files were staged.');
|
|
100
|
+
}
|
|
101
|
+
const add = run('add', '--all', '--', '.');
|
|
102
|
+
if (add.status !== 0)
|
|
103
|
+
return result(add.status ?? 1, add.stderr || 'Initial staging failed.');
|
|
104
|
+
const commit = run('commit', '-m', 'chore: initialize ATM project');
|
|
105
|
+
return result(commit.status ?? 1, commit.stderr || commit.error?.message || '', commit.stdout);
|
|
106
|
+
}
|
|
78
107
|
function installTargetRuntime(targetRoot, packageSpec) {
|
|
79
108
|
writeFileSync(path.join(targetRoot, 'package.json'), `${JSON.stringify({ private: true, type: 'module' }, null, 2)}\n`);
|
|
80
109
|
const npmCli = process.env.npm_execpath?.endsWith('npm-cli.js')
|
|
@@ -91,6 +120,10 @@ function installTargetRuntime(targetRoot, packageSpec) {
|
|
|
91
120
|
const installed = JSON.parse(readFileSync(path.join(packageRoot, 'package.json'), 'utf8'));
|
|
92
121
|
const manifest = JSON.parse(readFileSync(path.join(targetRoot, 'package.json'), 'utf8'));
|
|
93
122
|
const lock = JSON.parse(readFileSync(path.join(targetRoot, 'package-lock.json'), 'utf8'));
|
|
123
|
+
const requestedVersion = packageSpec.slice(packageSpec.lastIndexOf('@') + 1);
|
|
124
|
+
if (!['latest', 'next', 'beta', 'lts'].includes(requestedVersion) && installed.version !== requestedVersion) {
|
|
125
|
+
throw new Error('Installed CLI version does not match the starter dependency.');
|
|
126
|
+
}
|
|
94
127
|
if (installed.name !== '@ai-atomic-framework/cli' || typeof installed.version !== 'string'
|
|
95
128
|
|| manifest.dependencies?.[installed.name] !== installed.version
|
|
96
129
|
|| lock.packages?.['node_modules/@ai-atomic-framework/cli']?.version !== installed.version
|
|
@@ -115,15 +148,23 @@ function installTargetRuntime(targetRoot, packageSpec) {
|
|
|
115
148
|
}
|
|
116
149
|
function parseArgs(argv) {
|
|
117
150
|
const args = [...argv];
|
|
151
|
+
if (args.some(arg => arg.startsWith('--cli-version=')))
|
|
152
|
+
throwUsage('Use --cli-version <exact-semver>; inline values are not supported.');
|
|
118
153
|
const projectName = args.find((arg) => !arg.startsWith('-'));
|
|
119
154
|
if (!projectName) {
|
|
120
|
-
throwUsage('Usage: create-atm <project-name> [--agent <pack-id>] [--cwd <dir>] [--json]');
|
|
155
|
+
throwUsage('Usage: create-atm <project-name> [--agent <pack-id>] [--cwd <dir>] [--tag latest|next|beta|lts] [--cli-version <exact-semver>] [--json]');
|
|
121
156
|
}
|
|
157
|
+
const tag = parseDistTag(readOption(args, '--tag') ?? 'latest');
|
|
158
|
+
const versionArg = readOption(args, '--cli-version');
|
|
159
|
+
if (args.filter(arg => arg === '--cli-version').length > 1)
|
|
160
|
+
throwUsage('--cli-version may only be provided once.');
|
|
161
|
+
const cliVersion = versionArg === undefined ? undefined : parseExactCliVersion(versionArg, tag);
|
|
122
162
|
return {
|
|
123
163
|
projectName,
|
|
124
164
|
cwd: path.resolve(readOption(args, '--cwd') ?? process.cwd()),
|
|
125
165
|
agent: readOption(args, '--agent'),
|
|
126
|
-
tag
|
|
166
|
+
tag,
|
|
167
|
+
cliVersion,
|
|
127
168
|
json: args.includes('--json') || !process.stdout.isTTY
|
|
128
169
|
};
|
|
129
170
|
}
|
|
@@ -137,6 +178,19 @@ function readOption(args, name) {
|
|
|
137
178
|
}
|
|
138
179
|
return value;
|
|
139
180
|
}
|
|
181
|
+
export function parseExactCliVersion(value, tag) {
|
|
182
|
+
const match = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/.exec(value);
|
|
183
|
+
const prerelease = match?.[4]?.split('.') ?? [];
|
|
184
|
+
if (!match || prerelease.some(part => /^\d+$/.test(part) && !/^(0|[1-9]\d*)$/.test(part)))
|
|
185
|
+
throwUsage('--cli-version requires one exact semver, not a tag, range, package, path or URL.');
|
|
186
|
+
const allowed = tag === 'latest' ? prerelease.length === 0
|
|
187
|
+
: tag === 'next' ? prerelease[0] === 'beta'
|
|
188
|
+
: tag === 'beta' ? prerelease[0] === 'alpha'
|
|
189
|
+
: prerelease.length === 0 || prerelease[0] === 'lts';
|
|
190
|
+
if (!allowed)
|
|
191
|
+
throwUsage(`--cli-version prerelease does not match the ${tag} release channel.`);
|
|
192
|
+
return value;
|
|
193
|
+
}
|
|
140
194
|
function parseDistTag(value) {
|
|
141
195
|
if (value === 'latest' || value === 'next' || value === 'beta' || value === 'lts') {
|
|
142
196
|
return value;
|
|
@@ -156,18 +210,27 @@ function ensureCreatableTarget(targetRoot) {
|
|
|
156
210
|
process.exit(2);
|
|
157
211
|
}
|
|
158
212
|
}
|
|
159
|
-
function resolveCreateAtmDistTag(tag) {
|
|
213
|
+
function resolveCreateAtmDistTag(tag, explicitTag, cliVersion) {
|
|
160
214
|
const table = {
|
|
161
215
|
latest: { tier: 'stable', expectedCliPrerelease: null },
|
|
162
216
|
next: { tier: 'beta', expectedCliPrerelease: 'beta' },
|
|
163
217
|
beta: { tier: 'experimental', expectedCliPrerelease: 'alpha' },
|
|
164
218
|
lts: { tier: 'lts', expectedCliPrerelease: null }
|
|
165
219
|
};
|
|
220
|
+
let packageVersion = cliVersion ?? tag;
|
|
221
|
+
if (!explicitTag && cliVersion === undefined) {
|
|
222
|
+
const manifest = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
223
|
+
const declared = manifest.dependencies?.['@ai-atomic-framework/cli'];
|
|
224
|
+
if (typeof declared !== 'string' || !/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/.test(declared)) {
|
|
225
|
+
throwUsage('create-atm must declare an exact CLI dependency; use --tag explicitly to select a release channel.');
|
|
226
|
+
}
|
|
227
|
+
packageVersion = declared;
|
|
228
|
+
}
|
|
166
229
|
return {
|
|
167
230
|
schemaVersion: 'atm.distTagSelection.v0.1',
|
|
168
231
|
requestedTag: tag,
|
|
169
232
|
...table[tag],
|
|
170
|
-
npmPackageSpec: `@ai-atomic-framework/cli@${
|
|
233
|
+
npmPackageSpec: `@ai-atomic-framework/cli@${packageVersion}`,
|
|
171
234
|
source: 'create-atm'
|
|
172
235
|
};
|
|
173
236
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-atm",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Create an ATM governance framework starter project with optional agent pack onboarding.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"lint": "eslint ."
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@ai-atomic-framework/cli": "0.1.
|
|
32
|
+
"@ai-atomic-framework/cli": "0.1.17"
|
|
33
33
|
},
|
|
34
34
|
"types": "./dist/index.d.ts"
|
|
35
35
|
}
|