create-atm 0.1.0-beta.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 (3) hide show
  1. package/README.md +17 -0
  2. package/dist/index.js +188 -0
  3. package/package.json +35 -0
package/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # create-atm
2
+
3
+ `create-atm` creates an ATM governance framework starter project. ATM is a governance framework for AI-assisted engineering: it scopes work, locks edits, renders rule context, validates deterministic gates, and records evidence.
4
+
5
+ ## Usage
6
+
7
+ ```bash
8
+ npx create-atm test-app --agent claude-code
9
+ ```
10
+
11
+ The command creates `test-app`, runs `atm bootstrap`, renders `.atm/memory/atm-chart.md`, and installs the requested agent pack. Agent packs are opt-in; running without `--agent` initializes the ATM project and rule chart only.
12
+
13
+ ```bash
14
+ npx create-atm test-app
15
+ ```
16
+
17
+ This package is intentionally a thin onboarding wrapper around the official ATM CLI. It does not replace root-drop, onefile, or source-tree ATM routing.
package/dist/index.js ADDED
@@ -0,0 +1,188 @@
1
+ #!/usr/bin/env node
2
+ import { spawnSync } from 'node:child_process';
3
+ import { createRequire } from 'node:module';
4
+ import { existsSync, mkdirSync, readdirSync, writeFileSync } from 'node:fs';
5
+ import path from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
7
+ export const createAtmPackage = {
8
+ packageName: 'create-atm',
9
+ packageRole: 'npm-create-governance-onboarding',
10
+ packageVersion: '0.0.0'
11
+ };
12
+ export function runCreateAtm(argv = process.argv.slice(2)) {
13
+ const startedAt = Date.now();
14
+ if (argv.includes('--help') || argv.includes('-h')) {
15
+ process.stdout.write('Usage: create-atm <project-name> [--agent <pack-id>] [--cwd <dir>] [--json]\n');
16
+ return 0;
17
+ }
18
+ const options = parseArgs(argv);
19
+ const targetRoot = path.resolve(options.cwd, options.projectName);
20
+ ensureCreatableTarget(targetRoot);
21
+ mkdirSync(targetRoot, { recursive: true });
22
+ const distTag = resolveCreateAtmDistTag(options.tag);
23
+ writeDistTagSelection(targetRoot, distTag);
24
+ const atmExecution = resolveAtmExecutionPlan(distTag.requestedTag);
25
+ const steps = [];
26
+ steps.push(runAtmStep('bootstrap', atmExecution, ['bootstrap', '--cwd', targetRoot, '--json']));
27
+ steps.push(runAtmStep('atm-chart render', atmExecution, ['atm-chart', 'render', '--cwd', targetRoot, '--json']));
28
+ if (options.agent) {
29
+ steps.push(runAtmStep(`agent-pack install ${options.agent}`, atmExecution, ['agent-pack', 'install', '--id', options.agent, '--cwd', targetRoot, '--json']));
30
+ }
31
+ const failedStep = steps.find((step) => step.exitCode !== 0);
32
+ const payload = {
33
+ ok: failedStep === undefined,
34
+ command: 'create-atm',
35
+ cwd: options.cwd,
36
+ messages: [
37
+ failedStep
38
+ ? { level: 'error', code: 'ATM_CREATE_FAILED', text: `create-atm failed at step: ${failedStep.name}` }
39
+ : { level: 'info', code: 'ATM_CREATE_READY', text: `ATM governance project created at ${targetRoot}` }
40
+ ],
41
+ evidence: {
42
+ projectRoot: targetRoot,
43
+ agent: options.agent ?? null,
44
+ atmEntrypoint: atmExecution.display,
45
+ atmEntrypointSource: atmExecution.source,
46
+ distTag,
47
+ durationMs: Date.now() - startedAt,
48
+ steps: steps.map((step) => ({
49
+ name: step.name,
50
+ exitCode: step.exitCode,
51
+ durationMs: step.durationMs
52
+ }))
53
+ }
54
+ };
55
+ writePayload(payload, options.json);
56
+ return failedStep ? failedStep.exitCode : 0;
57
+ }
58
+ function parseArgs(argv) {
59
+ const args = [...argv];
60
+ const projectName = args.find((arg) => !arg.startsWith('-'));
61
+ if (!projectName) {
62
+ throwUsage('Usage: create-atm <project-name> [--agent <pack-id>] [--cwd <dir>] [--json]');
63
+ }
64
+ return {
65
+ projectName,
66
+ cwd: path.resolve(readOption(args, '--cwd') ?? process.cwd()),
67
+ agent: readOption(args, '--agent'),
68
+ tag: parseDistTag(readOption(args, '--tag') ?? 'latest'),
69
+ json: args.includes('--json') || !process.stdout.isTTY
70
+ };
71
+ }
72
+ function readOption(args, name) {
73
+ const index = args.indexOf(name);
74
+ if (index < 0)
75
+ return undefined;
76
+ const value = args[index + 1];
77
+ if (!value || value.startsWith('-')) {
78
+ throwUsage(`${name} requires a value.`);
79
+ }
80
+ return value;
81
+ }
82
+ function parseDistTag(value) {
83
+ if (value === 'latest' || value === 'next' || value === 'beta' || value === 'lts') {
84
+ return value;
85
+ }
86
+ throwUsage(`--tag must be one of: latest, next, beta, lts. Got: ${value}`);
87
+ }
88
+ function throwUsage(message) {
89
+ process.stderr.write(`[create-atm] ${message}\n`);
90
+ process.exit(2);
91
+ }
92
+ function ensureCreatableTarget(targetRoot) {
93
+ if (!existsSync(targetRoot))
94
+ return;
95
+ const entries = readdirSync(targetRoot);
96
+ if (entries.length > 0) {
97
+ process.stderr.write(`[create-atm] target directory is not empty: ${targetRoot}\n`);
98
+ process.exit(2);
99
+ }
100
+ }
101
+ function resolveCreateAtmDistTag(tag) {
102
+ const table = {
103
+ latest: { tier: 'stable', expectedCliPrerelease: null },
104
+ next: { tier: 'beta', expectedCliPrerelease: 'beta' },
105
+ beta: { tier: 'experimental', expectedCliPrerelease: 'alpha' },
106
+ lts: { tier: 'lts', expectedCliPrerelease: null }
107
+ };
108
+ return {
109
+ schemaVersion: 'atm.distTagSelection.v0.1',
110
+ requestedTag: tag,
111
+ ...table[tag],
112
+ npmPackageSpec: `@ai-atomic-framework/cli@${tag}`,
113
+ source: 'create-atm'
114
+ };
115
+ }
116
+ function writeDistTagSelection(targetRoot, selection) {
117
+ const selectionPath = path.join(targetRoot, '.atm', 'runtime', 'dist-tag.json');
118
+ mkdirSync(path.dirname(selectionPath), { recursive: true });
119
+ writeFileSync(selectionPath, `${JSON.stringify(selection, null, 2)}\n`, 'utf8');
120
+ }
121
+ function resolveAtmExecutionPlan(tag) {
122
+ const require = createRequire(import.meta.url);
123
+ try {
124
+ const cliIndexPath = require.resolve('@ai-atomic-framework/cli');
125
+ const packageRoot = path.resolve(path.dirname(cliIndexPath), '..');
126
+ const packagedEntrypoint = path.join(packageRoot, 'dist', 'atm.mjs');
127
+ if (existsSync(packagedEntrypoint) && tag === 'latest') {
128
+ return {
129
+ command: process.execPath,
130
+ argsPrefix: [packagedEntrypoint],
131
+ display: packagedEntrypoint,
132
+ source: 'packaged-dependency'
133
+ };
134
+ }
135
+ }
136
+ catch {
137
+ // Fall through to source-tree lookup.
138
+ }
139
+ const sourceTreeRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..', '..');
140
+ const sourceEntrypoint = path.join(sourceTreeRoot, 'atm.mjs');
141
+ if (existsSync(sourceEntrypoint)) {
142
+ return {
143
+ command: process.execPath,
144
+ argsPrefix: [sourceEntrypoint],
145
+ display: sourceEntrypoint,
146
+ source: 'source-tree'
147
+ };
148
+ }
149
+ if (tag !== 'latest') {
150
+ const npxCommand = process.platform === 'win32' ? 'npx.cmd' : 'npx';
151
+ return {
152
+ command: npxCommand,
153
+ argsPrefix: ['--yes', `@ai-atomic-framework/cli@${tag}`, 'atm'],
154
+ display: `${npxCommand} --yes @ai-atomic-framework/cli@${tag} atm`,
155
+ source: 'npm-dist-tag'
156
+ };
157
+ }
158
+ process.stderr.write('[create-atm] unable to locate ATM CLI entrypoint.\n');
159
+ process.exit(1);
160
+ }
161
+ function runAtmStep(name, atmExecution, args) {
162
+ const startedAt = Date.now();
163
+ const child = spawnSync(atmExecution.command, [...atmExecution.argsPrefix, ...args], {
164
+ encoding: 'utf8',
165
+ windowsHide: true
166
+ });
167
+ return {
168
+ name,
169
+ exitCode: child.status ?? 1,
170
+ stdout: child.stdout ?? '',
171
+ stderr: child.stderr ?? '',
172
+ durationMs: Date.now() - startedAt
173
+ };
174
+ }
175
+ function writePayload(payload, json) {
176
+ if (json) {
177
+ process.stdout.write(`${JSON.stringify(payload, null, 2)}\n`);
178
+ return;
179
+ }
180
+ const message = payload.messages?.[0]?.text ?? 'create-atm complete.';
181
+ process.stdout.write(`[create-atm] ${message}\n`);
182
+ }
183
+ const isDirectRun = process.argv[1]
184
+ ? path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)
185
+ : false;
186
+ if (isDirectRun) {
187
+ process.exitCode = runCreateAtm();
188
+ }
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "create-atm",
3
+ "version": "0.1.0-beta.0",
4
+ "private": false,
5
+ "description": "Create an ATM governance framework starter project with optional agent pack onboarding.",
6
+ "license": "Apache-2.0",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/eaglhuang/AI-Atomic-Framework.git"
10
+ },
11
+ "type": "module",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.js"
16
+ }
17
+ },
18
+ "bin": {
19
+ "create-atm": "dist/index.js"
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "README.md"
24
+ ],
25
+ "scripts": {
26
+ "build": "node --strip-types ../../scripts/build-package-dist.ts --package packages/create-atm",
27
+ "test": "node --strip-types ../../scripts/validate-package-skeleton.ts --mode test",
28
+ "typecheck": "tsc -p ../../tsconfig.json --noEmit",
29
+ "lint": "eslint ."
30
+ },
31
+ "dependencies": {
32
+ "@ai-atomic-framework/cli": "0.1.0"
33
+ },
34
+ "types": "./dist/index.d.ts"
35
+ }