@hazeljs/cli 2.0.0 → 2.0.1

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.
@@ -0,0 +1,203 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.registerStoreCommand = registerStoreCommand;
37
+ const fs = __importStar(require("fs"));
38
+ const path = __importStar(require("path"));
39
+ async function resolveRegistry(opts) {
40
+ const { createAgentPackageRegistry } = await Promise.resolve().then(() => __importStar(require('@hazeljs/agent')));
41
+ return createAgentPackageRegistry({
42
+ remote: opts.remote,
43
+ token: opts.token,
44
+ registryRoot: opts.registry,
45
+ });
46
+ }
47
+ function registryOptions(cmd) {
48
+ return cmd
49
+ .option('--registry <dir>', 'Local registry root (default: ~/.hazel/registry)')
50
+ .option('--remote <url>', 'Hosted registry base URL (Cloud Team SKU; env HAZEL_REGISTRY_URL)')
51
+ .option('--token <token>', 'Bearer token for hosted registry (env HAZEL_REGISTRY_TOKEN)');
52
+ }
53
+ async function publishAction(file, opts) {
54
+ const { loadMarketplacePackage } = await Promise.resolve().then(() => __importStar(require('@hazeljs/agent')));
55
+ const pkg = loadMarketplacePackage(path.resolve(process.cwd(), file));
56
+ const registry = await resolveRegistry(opts);
57
+ await registry.publish(pkg);
58
+ // eslint-disable-next-line no-console
59
+ console.log(JSON.stringify({
60
+ ok: true,
61
+ action: 'publish',
62
+ package: pkg.name,
63
+ version: pkg.version,
64
+ registry: registry.location,
65
+ kind: registry.kind,
66
+ }, null, 2));
67
+ }
68
+ async function installAction(spec, opts) {
69
+ const { loadMarketplacePackage, materializeAgentPackage, parsePackageSpec } = await Promise.resolve().then(() => __importStar(require('@hazeljs/agent')));
70
+ const projectRoot = path.resolve(process.cwd(), opts.cwd);
71
+ const resolvedPath = path.resolve(process.cwd(), spec);
72
+ const looksLikeFile = spec.includes(path.sep) ||
73
+ spec.includes('/') ||
74
+ spec.endsWith('.json') ||
75
+ fs.existsSync(resolvedPath);
76
+ let pkg;
77
+ if (looksLikeFile && fs.existsSync(resolvedPath) && fs.statSync(resolvedPath).isFile()) {
78
+ pkg = loadMarketplacePackage(resolvedPath);
79
+ }
80
+ else {
81
+ const { name, version } = parsePackageSpec(spec);
82
+ const registry = await resolveRegistry(opts);
83
+ pkg = await registry.get(name, version);
84
+ }
85
+ const result = materializeAgentPackage(pkg, projectRoot);
86
+ // eslint-disable-next-line no-console
87
+ console.log(JSON.stringify({
88
+ ok: true,
89
+ action: 'install',
90
+ package: result.packageName,
91
+ version: result.version,
92
+ path: result.packagePath,
93
+ lock: result.lockPath,
94
+ note: 'Use hazel agent run with the materialized package DNA, or runtime.installAgentPackage for hot-reload',
95
+ }, null, 2));
96
+ }
97
+ /**
98
+ * `hazel store publish|install|list|remove|doctor` — local or hosted Agent OS package registry.
99
+ * Hosted (Cloud Team SKU): `--remote <url> --token <token>` or HAZEL_REGISTRY_URL / HAZEL_REGISTRY_TOKEN.
100
+ * `hazel install` aliases `hazel store install`.
101
+ */
102
+ function registerStoreCommand(program) {
103
+ const store = program
104
+ .command('store')
105
+ .description('Agent OS package registry — local filesystem or hosted (--remote) Cloud Team registry');
106
+ registryOptions(store
107
+ .command('publish')
108
+ .description('Publish a marketplace / DNA JSON package to the registry')
109
+ .argument('<file>', 'Path to .dna.json or marketplace package JSON')).action(async (file, opts) => {
110
+ try {
111
+ await publishAction(file, opts);
112
+ }
113
+ catch (e) {
114
+ // eslint-disable-next-line no-console
115
+ console.error(e instanceof Error ? e.message : e);
116
+ process.exitCode = 1;
117
+ }
118
+ });
119
+ registryOptions(store
120
+ .command('install')
121
+ .description('Install a package into the project (.hazel/agents). Spec: path, name, or name@version')
122
+ .argument('<spec>', 'File path or package name[@version]')
123
+ .option('--cwd <dir>', 'Project root', '.')).action(async (spec, opts) => {
124
+ try {
125
+ await installAction(spec, opts);
126
+ }
127
+ catch (e) {
128
+ // eslint-disable-next-line no-console
129
+ console.error(e instanceof Error ? e.message : e);
130
+ process.exitCode = 1;
131
+ }
132
+ });
133
+ registryOptions(store
134
+ .command('list')
135
+ .description('List packages in the registry')
136
+ .argument('[query]', 'Optional name/description filter')).action(async (query, opts) => {
137
+ try {
138
+ const registry = await resolveRegistry(opts);
139
+ const packages = await registry.list(query);
140
+ // eslint-disable-next-line no-console
141
+ console.log(JSON.stringify({ ok: true, kind: registry.kind, registry: registry.location, packages }, null, 2));
142
+ }
143
+ catch (e) {
144
+ // eslint-disable-next-line no-console
145
+ console.error(e instanceof Error ? e.message : e);
146
+ process.exitCode = 1;
147
+ }
148
+ });
149
+ registryOptions(store
150
+ .command('remove')
151
+ .description('Remove a package (or one version) from the registry')
152
+ .argument('<spec>', 'name or name@version')).action(async (spec, opts) => {
153
+ try {
154
+ const { parsePackageSpec } = await Promise.resolve().then(() => __importStar(require('@hazeljs/agent')));
155
+ const { name, version } = parsePackageSpec(spec);
156
+ const registry = await resolveRegistry(opts);
157
+ await registry.remove(name, version);
158
+ // eslint-disable-next-line no-console
159
+ console.log(JSON.stringify({
160
+ ok: true,
161
+ action: 'remove',
162
+ name,
163
+ version: version ?? '*',
164
+ kind: registry.kind,
165
+ registry: registry.location,
166
+ }, null, 2));
167
+ }
168
+ catch (e) {
169
+ // eslint-disable-next-line no-console
170
+ console.error(e instanceof Error ? e.message : e);
171
+ process.exitCode = 1;
172
+ }
173
+ });
174
+ registryOptions(store.command('doctor').description('Check registry health (local or remote)')).action(async (opts) => {
175
+ try {
176
+ const registry = await resolveRegistry(opts);
177
+ const report = await registry.doctor();
178
+ // eslint-disable-next-line no-console
179
+ console.log(JSON.stringify({ ...report, kind: registry.kind, registry: registry.location }, null, 2));
180
+ if (!report.ok)
181
+ process.exitCode = 1;
182
+ }
183
+ catch (e) {
184
+ // eslint-disable-next-line no-console
185
+ console.error(e instanceof Error ? e.message : e);
186
+ process.exitCode = 1;
187
+ }
188
+ });
189
+ registryOptions(program
190
+ .command('install')
191
+ .description('Alias for hazel store install')
192
+ .argument('<spec>', 'File path or package name[@version]')
193
+ .option('--cwd <dir>', 'Project root', '.')).action(async (spec, opts) => {
194
+ try {
195
+ await installAction(spec, opts);
196
+ }
197
+ catch (e) {
198
+ // eslint-disable-next-line no-console
199
+ console.error(e instanceof Error ? e.message : e);
200
+ process.exitCode = 1;
201
+ }
202
+ });
203
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const commander_1 = require("commander");
37
+ const fs = __importStar(require("fs"));
38
+ const os = __importStar(require("os"));
39
+ const path = __importStar(require("path"));
40
+ const store_1 = require("./store");
41
+ describe('registerStoreCommand (G2 Package+Store)', () => {
42
+ it('registers store subcommands and install alias', () => {
43
+ const program = new commander_1.Command();
44
+ (0, store_1.registerStoreCommand)(program);
45
+ const store = program.commands.find((c) => c.name() === 'store');
46
+ expect(store).toBeDefined();
47
+ const names = store.commands.map((c) => c.name());
48
+ expect(names).toEqual(expect.arrayContaining(['publish', 'install', 'list', 'remove', 'doctor']));
49
+ expect(program.commands.some((c) => c.name() === 'install')).toBe(true);
50
+ });
51
+ it('publish then install materializes support-desk style package', async () => {
52
+ const { exportAgentDna, toMarketplacePackage, saveMarketplacePackage } = await Promise.resolve().then(() => __importStar(require('@hazeljs/agent')));
53
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'hazel-store-cli-'));
54
+ const registryDir = path.join(tmp, 'registry');
55
+ const projectDir = path.join(tmp, 'project');
56
+ fs.mkdirSync(projectDir);
57
+ const dna = exportAgentDna({
58
+ name: 'support-desk',
59
+ version: '1.0.0',
60
+ tools: [{ name: 'lookupOrder' }],
61
+ });
62
+ const pkg = toMarketplacePackage(dna);
63
+ pkg.name = '@hazeljs/support-desk-agent';
64
+ const pkgFile = path.join(tmp, 'support-desk.marketplace.json');
65
+ saveMarketplacePackage(pkg, pkgFile);
66
+ const program = new commander_1.Command();
67
+ (0, store_1.registerStoreCommand)(program);
68
+ await program.parseAsync(['store', 'publish', pkgFile, '--registry', registryDir], {
69
+ from: 'user',
70
+ });
71
+ expect(process.exitCode ?? 0).toBe(0);
72
+ await program.parseAsync([
73
+ 'store',
74
+ 'install',
75
+ '@hazeljs/support-desk-agent@1.0.0',
76
+ '--cwd',
77
+ projectDir,
78
+ '--registry',
79
+ registryDir,
80
+ ], { from: 'user' });
81
+ expect(process.exitCode ?? 0).toBe(0);
82
+ const lockPath = path.join(projectDir, '.hazel', 'agents', 'lock.json');
83
+ expect(fs.existsSync(lockPath)).toBe(true);
84
+ const lock = JSON.parse(fs.readFileSync(lockPath, 'utf8'));
85
+ expect(lock['@hazeljs/support-desk-agent']?.version).toBe('1.0.0');
86
+ fs.rmSync(tmp, { recursive: true, force: true });
87
+ });
88
+ it('publishes and installs real starter support-desk.marketplace.json', async () => {
89
+ // Fixture is vendored in-package so CI (hazeljs repo only) does not need sibling starters.
90
+ const pkgFile = path.resolve(__dirname, '../../fixtures/support-desk.marketplace.json');
91
+ expect(fs.existsSync(pkgFile)).toBe(true);
92
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'hazel-store-starter-'));
93
+ const registryDir = path.join(tmp, 'registry');
94
+ const projectDir = path.join(tmp, 'project');
95
+ fs.mkdirSync(projectDir);
96
+ const program = new commander_1.Command();
97
+ (0, store_1.registerStoreCommand)(program);
98
+ process.exitCode = 0;
99
+ await program.parseAsync(['store', 'publish', pkgFile, '--registry', registryDir], {
100
+ from: 'user',
101
+ });
102
+ expect(process.exitCode ?? 0).toBe(0);
103
+ await program.parseAsync([
104
+ 'store',
105
+ 'install',
106
+ '@hazeljs/support-desk-agent',
107
+ '--cwd',
108
+ projectDir,
109
+ '--registry',
110
+ registryDir,
111
+ ], { from: 'user' });
112
+ expect(process.exitCode ?? 0).toBe(0);
113
+ const packageJson = path.join(projectDir, '.hazel', 'agents', 'hazeljs__support-desk-agent', 'package.json');
114
+ expect(fs.existsSync(packageJson)).toBe(true);
115
+ const loaded = JSON.parse(fs.readFileSync(packageJson, 'utf8'));
116
+ expect(loaded.name).toBe('@hazeljs/support-desk-agent');
117
+ expect(loaded.dna.name).toBe('support-desk');
118
+ fs.rmSync(tmp, { recursive: true, force: true });
119
+ });
120
+ });
package/dist/index.js CHANGED
@@ -57,6 +57,7 @@ const eval_1 = require("./commands/eval");
57
57
  const benchmark_1 = require("./commands/benchmark");
58
58
  const agent_1 = require("./commands/agent");
59
59
  const skillgate_1 = require("./commands/skillgate");
60
+ const store_1 = require("./commands/store");
60
61
  // Read version from package.json to ensure consistency
61
62
  const packageJson = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../package.json'), 'utf8'));
62
63
  const program = new commander_1.Command();
@@ -73,6 +74,7 @@ program
73
74
  (0, benchmark_1.registerBenchmarkCommand)(program);
74
75
  (0, agent_1.registerAgentCommand)(program);
75
76
  (0, skillgate_1.registerSkillgateCommand)(program);
77
+ (0, store_1.registerStoreCommand)(program);
76
78
  // Generate command group (unified: hazel g <type> <name> [--path] [--dry-run] [--json], or hazel g --list)
77
79
  const generateCommand = program
78
80
  .command('generate')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hazeljs/cli",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Command-line interface for scaffolding and generating HazelJS applications and components",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -31,10 +31,10 @@
31
31
  "mustache": "^4.2.0"
32
32
  },
33
33
  "peerDependencies": {
34
- "@hazeljs/eval": "^2.0.0",
35
- "@hazeljs/benchmark": "^2.0.0",
36
- "@hazeljs/agent": "^2.0.0",
37
- "@hazeljs/skillgate": "^2.0.0"
34
+ "@hazeljs/eval": "^2.0.1",
35
+ "@hazeljs/benchmark": "^2.0.1",
36
+ "@hazeljs/agent": "^2.0.1",
37
+ "@hazeljs/skillgate": "^2.0.1"
38
38
  },
39
39
  "peerDependenciesMeta": {
40
40
  "@hazeljs/eval": {
@@ -51,10 +51,10 @@
51
51
  }
52
52
  },
53
53
  "devDependencies": {
54
- "@hazeljs/eval": "^2.0.0",
55
- "@hazeljs/benchmark": "^2.0.0",
56
- "@hazeljs/agent": "^2.0.0",
57
- "@hazeljs/skillgate": "^2.0.0",
54
+ "@hazeljs/eval": "^2.0.1",
55
+ "@hazeljs/benchmark": "^2.0.1",
56
+ "@hazeljs/agent": "^2.0.1",
57
+ "@hazeljs/skillgate": "^2.0.1",
58
58
  "@types/inquirer": "^8.2.12",
59
59
  "@types/jest": "^29.5.14",
60
60
  "@types/mustache": "^4.2.6",