openbroker 1.9.4 → 1.9.6

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 (43) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/README.md +21 -4
  3. package/SKILL.md +3 -3
  4. package/bin/cli.ts +4 -2
  5. package/dist/core/client.d.ts +6 -0
  6. package/dist/core/client.d.ts.map +1 -1
  7. package/dist/core/client.js +71 -0
  8. package/dist/lib.d.ts +2 -0
  9. package/dist/lib.d.ts.map +1 -1
  10. package/dist/lib.js +1 -0
  11. package/dist/operations/advanced-orders.test.d.ts +2 -0
  12. package/dist/operations/advanced-orders.test.d.ts.map +1 -0
  13. package/dist/operations/advanced-orders.test.js +189 -0
  14. package/dist/operations/bracket.d.ts +22 -0
  15. package/dist/operations/bracket.d.ts.map +1 -1
  16. package/dist/operations/bracket.js +106 -73
  17. package/dist/operations/chase.d.ts +19 -0
  18. package/dist/operations/chase.d.ts.map +1 -1
  19. package/dist/operations/chase.js +125 -58
  20. package/dist/operations/execution.d.ts +53 -0
  21. package/dist/operations/execution.d.ts.map +1 -0
  22. package/dist/operations/execution.js +106 -0
  23. package/dist/operations/scale.d.ts +50 -1
  24. package/dist/operations/scale.d.ts.map +1 -1
  25. package/dist/operations/scale.js +143 -105
  26. package/dist/setup/install.js +100 -3
  27. package/dist/setup/package-catalog.d.ts +12 -0
  28. package/dist/setup/package-catalog.d.ts.map +1 -0
  29. package/dist/setup/package-catalog.js +36 -0
  30. package/dist/setup/package-catalog.test.d.ts +2 -0
  31. package/dist/setup/package-catalog.test.d.ts.map +1 -0
  32. package/dist/setup/package-catalog.test.js +31 -0
  33. package/package.json +5 -3
  34. package/scripts/core/client.ts +91 -0
  35. package/scripts/lib.ts +3 -0
  36. package/scripts/operations/advanced-orders.test.ts +209 -0
  37. package/scripts/operations/bracket.ts +128 -72
  38. package/scripts/operations/chase.ts +138 -61
  39. package/scripts/operations/execution.ts +138 -0
  40. package/scripts/operations/scale.ts +186 -131
  41. package/scripts/setup/install.ts +110 -3
  42. package/scripts/setup/package-catalog.test.ts +50 -0
  43. package/scripts/setup/package-catalog.ts +49 -0
@@ -1,8 +1,10 @@
1
1
  #!/usr/bin/env npx tsx
2
2
  // Scale In/Out - Place a grid of limit orders
3
3
 
4
+ import { fileURLToPath } from 'url';
4
5
  import { getClient } from '../core/client.js';
5
- import { formatUsd, parseArgs, sleep } from '../core/utils.js';
6
+ import type { CancelResponse, OrderResponse } from '../core/types.js';
7
+ import { formatUsd, parseArgs } from '../core/utils.js';
6
8
 
7
9
  function printUsage() {
8
10
  console.log(`
@@ -42,14 +44,49 @@ Examples:
42
44
  `);
43
45
  }
44
46
 
45
- interface OrderLevel {
47
+ export interface OrderLevel {
46
48
  level: number;
47
49
  price: number;
48
50
  size: number;
49
51
  distanceFromMid: number;
50
52
  }
51
53
 
52
- function calculateLevels(
54
+ export interface ScaleClient {
55
+ verbose: boolean;
56
+ getAllMids(): Promise<Record<string, string>>;
57
+ bulkOrder(
58
+ orders: Array<{ coin: string; isBuy: boolean; size: number; price: number; tif?: 'Gtc' | 'Alo'; reduceOnly?: boolean; leverage?: number }>
59
+ ): Promise<OrderResponse>;
60
+ bulkCancel(cancels: Array<{ coin: string; oid: number }>): Promise<CancelResponse>;
61
+ }
62
+
63
+ export interface ScaleOptions {
64
+ coin: string;
65
+ side: 'buy' | 'sell';
66
+ size: number;
67
+ levels: number;
68
+ rangePct: number;
69
+ distribution?: 'linear' | 'exponential' | 'flat';
70
+ leverage?: number;
71
+ reduceOnly?: boolean;
72
+ tif?: 'Gtc' | 'Alo';
73
+ dryRun?: boolean;
74
+ verbose?: boolean;
75
+ rollbackOnPartial?: boolean;
76
+ client?: ScaleClient;
77
+ output?: (line: string) => void;
78
+ }
79
+
80
+ export interface ScaleResult {
81
+ status: 'dry' | 'complete' | 'partial' | 'failed';
82
+ levels: OrderLevel[];
83
+ restingOids: number[];
84
+ filledOids: number[];
85
+ errors: string[];
86
+ rolledBack: boolean;
87
+ }
88
+
89
+ export function calculateLevels(
53
90
  midPrice: number,
54
91
  isBuy: boolean,
55
92
  totalSize: number,
@@ -100,6 +137,133 @@ function calculateLevels(
100
137
  return levels;
101
138
  }
102
139
 
140
+ export async function runScale(opts: ScaleOptions): Promise<ScaleResult> {
141
+ const out = opts.output ?? ((line: string) => console.log(line));
142
+ const distribution = opts.distribution ?? 'linear';
143
+ const reduceOnly = opts.reduceOnly ?? false;
144
+ const tif = opts.tif ?? 'Gtc';
145
+ const rollbackOnPartial = opts.rollbackOnPartial ?? true;
146
+ const isBuy = opts.side === 'buy';
147
+
148
+ if (!opts.coin) throw new Error('coin is required');
149
+ if (opts.side !== 'buy' && opts.side !== 'sell') throw new Error('side must be buy or sell');
150
+ if (!Number.isFinite(opts.size) || opts.size <= 0) throw new Error('size must be positive');
151
+ if (!Number.isInteger(opts.levels) || opts.levels <= 0) throw new Error('levels must be a positive integer');
152
+ if (!Number.isFinite(opts.rangePct) || opts.rangePct <= 0) throw new Error('rangePct must be positive');
153
+ if (!['linear', 'exponential', 'flat'].includes(distribution)) throw new Error('distribution must be linear, exponential, or flat');
154
+
155
+ const client = opts.client ?? getClient();
156
+ if (opts.verbose) client.verbose = true;
157
+
158
+ out('Open Broker - Scale In/Out');
159
+ out('==========================\n');
160
+
161
+ const mids = await client.getAllMids();
162
+ const midPrice = parseFloat(mids[opts.coin]);
163
+ if (!midPrice) throw new Error(`No market data for ${opts.coin}`);
164
+
165
+ const levels = calculateLevels(midPrice, isBuy, opts.size, opts.levels, opts.rangePct, distribution);
166
+ const notional = levels.reduce((sum, l) => sum + l.price * l.size, 0);
167
+ const avgPrice = notional / opts.size;
168
+
169
+ out('Order Plan');
170
+ out('----------');
171
+ out(`Coin: ${opts.coin}`);
172
+ out(`Side: ${isBuy ? 'BUY' : 'SELL'}`);
173
+ out(`Total Size: ${opts.size}`);
174
+ out(`Current Mid: ${formatUsd(midPrice)}`);
175
+ out(`Levels: ${opts.levels}`);
176
+ out(`Range: ${opts.rangePct}% ${isBuy ? 'below' : 'above'} mid`);
177
+ out(`Distribution: ${distribution}`);
178
+ out(`Time in Force: ${tif}`);
179
+ out(`Reduce Only: ${reduceOnly ? 'Yes' : 'No'}`);
180
+ out(`Est. Notional: ${formatUsd(notional)}`);
181
+ out(`Avg Price: ${formatUsd(avgPrice)}`);
182
+
183
+ out('\nOrder Grid');
184
+ out('----------');
185
+ out('Level | Price | Size | Distance');
186
+ out('------|--------------|------------|----------');
187
+
188
+ for (const level of levels) {
189
+ out(
190
+ ` ${level.level.toString().padStart(2)} | ` +
191
+ `${formatUsd(level.price).padStart(12)} | ` +
192
+ `${level.size.toFixed(6).padStart(10)} | ` +
193
+ `${level.distanceFromMid.toFixed(2)}%`
194
+ );
195
+ }
196
+
197
+ if (opts.dryRun) {
198
+ out('\n🔍 Dry run - orders not placed');
199
+ return { status: 'dry', levels, restingOids: [], filledOids: [], errors: [], rolledBack: false };
200
+ }
201
+
202
+ out('\nPlacing ladder as a bulk order...\n');
203
+
204
+ const response = await client.bulkOrder(
205
+ levels.map((level) => ({
206
+ coin: opts.coin,
207
+ isBuy,
208
+ size: level.size,
209
+ price: level.price,
210
+ tif,
211
+ reduceOnly,
212
+ leverage: opts.leverage,
213
+ }))
214
+ );
215
+
216
+ const restingOids: number[] = [];
217
+ const filledOids: number[] = [];
218
+ const errors: string[] = [];
219
+
220
+ if (response.status === 'ok' && response.response && typeof response.response === 'object') {
221
+ response.response.data.statuses.forEach((status, index) => {
222
+ const level = levels[index];
223
+ if (status?.resting) {
224
+ restingOids.push(status.resting.oid);
225
+ out(`Level ${level.level}: ✅ OID ${status.resting.oid}`);
226
+ } else if (status?.filled) {
227
+ filledOids.push(status.filled.oid);
228
+ out(`Level ${level.level}: ✅ Filled ${status.filled.totalSz} @ ${formatUsd(parseFloat(status.filled.avgPx))}`);
229
+ } else if (status?.error) {
230
+ errors.push(`Level ${level.level}: ${status.error}`);
231
+ out(`Level ${level.level}: ❌ ${status.error}`);
232
+ } else {
233
+ errors.push(`Level ${level.level}: Unknown status`);
234
+ out(`Level ${level.level}: ⚠️ Unknown status`);
235
+ }
236
+ });
237
+ } else {
238
+ const reason = typeof response.response === 'string' ? response.response : 'Bulk order failed';
239
+ errors.push(reason);
240
+ out(`❌ ${reason}`);
241
+ }
242
+
243
+ let rolledBack = false;
244
+ if (errors.length > 0 && rollbackOnPartial && restingOids.length > 0) {
245
+ out('\nPartial ladder placement detected; cancelling resting ladder orders...');
246
+ await client.bulkCancel(restingOids.map((oid) => ({ coin: opts.coin, oid })));
247
+ rolledBack = true;
248
+ out(`Cancelled ${restingOids.length} resting order(s).`);
249
+ }
250
+
251
+ out('\n========== Summary ==========');
252
+ out(`Orders Placed: ${restingOids.length + filledOids.length}/${opts.levels}`);
253
+ if (errors.length > 0) out(`Failed: ${errors.length}`);
254
+ if (restingOids.length > 0) out(`Resting OIDs: ${restingOids.join(', ')}`);
255
+ if (filledOids.length > 0) out(`Filled OIDs: ${filledOids.join(', ')}`);
256
+ if (rolledBack) out('Rollback: Resting orders cancelled');
257
+
258
+ const status = errors.length === 0
259
+ ? 'complete'
260
+ : restingOids.length + filledOids.length > 0
261
+ ? 'partial'
262
+ : 'failed';
263
+
264
+ return { status, levels, restingOids, filledOids, errors, rolledBack };
265
+ }
266
+
103
267
  async function main() {
104
268
  const args = parseArgs(process.argv.slice(2));
105
269
 
@@ -119,17 +283,6 @@ async function main() {
119
283
  process.exit(1);
120
284
  }
121
285
 
122
- if (side !== 'buy' && side !== 'sell') {
123
- console.error('Error: --side must be "buy" or "sell"');
124
- process.exit(1);
125
- }
126
-
127
- if (!['linear', 'exponential', 'flat'].includes(distribution)) {
128
- console.error('Error: --distribution must be linear, exponential, or flat');
129
- process.exit(1);
130
- }
131
-
132
- // Map uppercase CLI input to Pascal case for SDK
133
286
  const tifMap: Record<string, 'Gtc' | 'Alo'> = {
134
287
  'GTC': 'Gtc',
135
288
  'ALO': 'Alo'
@@ -141,126 +294,28 @@ async function main() {
141
294
  process.exit(1);
142
295
  }
143
296
 
144
- const isBuy = side === 'buy';
145
- const client = getClient();
146
-
147
- if (args.verbose) {
148
- client.verbose = true;
149
- }
150
-
151
- console.log('Open Broker - Scale In/Out');
152
- console.log('==========================\n');
153
-
154
297
  try {
155
- const mids = await client.getAllMids();
156
- const midPrice = parseFloat(mids[coin]);
157
- if (!midPrice) {
158
- console.error(`Error: No market data for ${coin}`);
159
- process.exit(1);
160
- }
161
-
162
- const levels = calculateLevels(midPrice, isBuy, totalSize, numLevels, rangePct, distribution);
163
- const notional = levels.reduce((sum, l) => sum + l.price * l.size, 0);
164
- const avgPrice = notional / totalSize;
165
-
166
- console.log('Order Plan');
167
- console.log('----------');
168
- console.log(`Coin: ${coin}`);
169
- console.log(`Side: ${isBuy ? 'BUY' : 'SELL'}`);
170
- console.log(`Total Size: ${totalSize}`);
171
- console.log(`Current Mid: ${formatUsd(midPrice)}`);
172
- console.log(`Levels: ${numLevels}`);
173
- console.log(`Range: ${rangePct}% ${isBuy ? 'below' : 'above'} mid`);
174
- console.log(`Distribution: ${distribution}`);
175
- console.log(`Time in Force: ${tif}`);
176
- console.log(`Reduce Only: ${reduceOnly ? 'Yes' : 'No'}`);
177
- console.log(`Est. Notional: ${formatUsd(notional)}`);
178
- console.log(`Avg Price: ${formatUsd(avgPrice)}`);
179
-
180
- console.log('\nOrder Grid');
181
- console.log('----------');
182
- console.log('Level | Price | Size | Distance');
183
- console.log('------|--------------|------------|----------');
184
-
185
- for (const level of levels) {
186
- console.log(
187
- ` ${level.level.toString().padStart(2)} | ` +
188
- `${formatUsd(level.price).padStart(12)} | ` +
189
- `${level.size.toFixed(6).padStart(10)} | ` +
190
- `${level.distanceFromMid.toFixed(2)}%`
191
- );
192
- }
193
-
194
- if (dryRun) {
195
- console.log('\n🔍 Dry run - orders not placed');
196
- return;
197
- }
198
-
199
- console.log('\nPlacing orders...\n');
200
-
201
- const results: { level: number; oid?: number; error?: string }[] = [];
202
-
203
- for (const level of levels) {
204
- process.stdout.write(`Level ${level.level}: ${formatUsd(level.price)} x ${level.size.toFixed(6)}... `);
205
-
206
- try {
207
- const response = await client.limitOrder(
208
- coin,
209
- isBuy,
210
- level.size,
211
- level.price,
212
- tif,
213
- reduceOnly,
214
- leverage
215
- );
216
-
217
- if (response.status === 'ok' && response.response && typeof response.response === 'object') {
218
- const status = response.response.data.statuses[0];
219
- if (status?.resting) {
220
- console.log(`✅ OID: ${status.resting.oid}`);
221
- results.push({ level: level.level, oid: status.resting.oid });
222
- } else if (status?.filled) {
223
- console.log(`✅ Filled immediately @ ${formatUsd(parseFloat(status.filled.avgPx))}`);
224
- results.push({ level: level.level, oid: status.filled.oid });
225
- } else if (status?.error) {
226
- console.log(`❌ ${status.error}`);
227
- results.push({ level: level.level, error: status.error });
228
- } else {
229
- console.log(`⚠️ Unknown status`);
230
- results.push({ level: level.level, error: 'Unknown status' });
231
- }
232
- } else {
233
- const error = typeof response.response === 'string' ? response.response : 'Failed';
234
- console.log(`❌ ${error}`);
235
- results.push({ level: level.level, error });
236
- }
237
- } catch (err) {
238
- const error = err instanceof Error ? err.message : String(err);
239
- console.log(`❌ ${error}`);
240
- results.push({ level: level.level, error });
241
- }
242
-
243
- // Small delay between orders
244
- await sleep(100);
245
- }
246
-
247
- // Summary
248
- const successful = results.filter(r => r.oid).length;
249
- const failed = results.filter(r => r.error).length;
250
-
251
- console.log('\n========== Summary ==========');
252
- console.log(`Orders Placed: ${successful}/${numLevels}`);
253
- if (failed > 0) {
254
- console.log(`Failed: ${failed}`);
255
- }
256
- if (successful > 0) {
257
- console.log(`Order IDs: ${results.filter(r => r.oid).map(r => r.oid).join(', ')}`);
258
- }
259
-
298
+ const result = await runScale({
299
+ coin,
300
+ side: side as 'buy' | 'sell',
301
+ size: totalSize,
302
+ levels: numLevels,
303
+ rangePct,
304
+ distribution,
305
+ leverage,
306
+ reduceOnly,
307
+ tif,
308
+ dryRun,
309
+ verbose: args.verbose as boolean,
310
+ });
311
+ if (result.status === 'failed') process.exit(1);
260
312
  } catch (error) {
261
- console.error('Error:', error);
313
+ console.error('Error:', error instanceof Error ? error.message : error);
262
314
  process.exit(1);
263
315
  }
264
316
  }
265
317
 
266
- main();
318
+ // Only run when invoked as a script — not when imported as a module.
319
+ if (process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1]) {
320
+ main();
321
+ }
@@ -6,21 +6,59 @@ import * as path from 'path';
6
6
  import { homedir } from 'os';
7
7
  import { fileURLToPath } from 'url';
8
8
  import { spawnSync } from 'child_process';
9
+ import {
10
+ INSTALLABLE_PACKAGES,
11
+ packageSpec,
12
+ resolveInstallablePackage,
13
+ } from './package-catalog.js';
9
14
 
10
15
  const __filename = fileURLToPath(import.meta.url);
11
16
  const __dirname = path.dirname(__filename);
12
17
  const packageRoot = path.resolve(__dirname, '../..');
13
- const args = new Set(process.argv.slice(2));
18
+ const rawArgs = process.argv.slice(2);
19
+ const args = new Set(rawArgs);
20
+
21
+ function positionalArgs(): string[] {
22
+ const positionals: string[] = [];
23
+ for (let index = 0; index < rawArgs.length; index++) {
24
+ const arg = rawArgs[index];
25
+ if (arg === '--tag') {
26
+ index++;
27
+ continue;
28
+ }
29
+ if (!arg.startsWith('-')) positionals.push(arg);
30
+ }
31
+ return positionals;
32
+ }
33
+
34
+ function optionValue(flag: string): string | null {
35
+ const index = rawArgs.indexOf(flag);
36
+ if (index < 0) return null;
37
+ const value = rawArgs[index + 1];
38
+ if (!value || value.startsWith('-')) fail(`${flag} requires a value`);
39
+ return value;
40
+ }
14
41
 
15
42
  function printUsage(): void {
16
43
  console.log(`
17
- OpenBroker Harness Installer
18
- ============================
44
+ OpenBroker Installer
45
+ ====================
19
46
 
20
47
  Usage:
48
+ openbroker install <package> [--tag <version>] [--dry]
49
+ openbroker install --list
21
50
  openbroker install --codex [options]
22
51
  npx openbroker@latest install --codex [options]
23
52
 
53
+ Companion packages:
54
+ monitoring Install the local automation dashboard
55
+ extended Install the Extended Exchange CLI
56
+
57
+ Package options:
58
+ --tag <tag> Install a release tag or exact version (default: latest)
59
+ --dry Print the npm command without installing
60
+ --list List supported companion packages
61
+
24
62
  Harnesses:
25
63
  --codex Install the OpenBroker skill for Codex
26
64
 
@@ -93,6 +131,62 @@ function installGlobalCli(): void {
93
131
  }
94
132
  }
95
133
 
134
+ function printInstallablePackages(): void {
135
+ console.log('Installable OpenBroker packages:\n');
136
+ for (const entry of INSTALLABLE_PACKAGES) {
137
+ console.log(` ${entry.key.padEnd(12)} ${entry.packageName.padEnd(26)} ${entry.description}`);
138
+ }
139
+ console.log('\nInstall or upgrade with: openbroker install <package>');
140
+ }
141
+
142
+ function installCompanionPackage(target: string): void {
143
+ const entry = resolveInstallablePackage(target);
144
+ if (!entry) {
145
+ printInstallablePackages();
146
+ fail(`unknown installable package: ${target}`);
147
+ }
148
+
149
+ const allowedFlags = new Set(['--tag', '--dry']);
150
+ const unsupported = rawArgs.filter((arg, index) => (
151
+ arg.startsWith('-')
152
+ && !allowedFlags.has(arg)
153
+ && rawArgs[index - 1] !== '--tag'
154
+ ));
155
+ if (unsupported.length > 0) fail(`unsupported package option: ${unsupported[0]}`);
156
+
157
+ const tag = optionValue('--tag') ?? 'latest';
158
+ let spec: string;
159
+ try {
160
+ spec = packageSpec(entry, tag);
161
+ } catch (error) {
162
+ fail(error instanceof Error ? error.message : String(error));
163
+ }
164
+
165
+ const npmCommand = process.platform === 'win32' ? 'npm.cmd' : 'npm';
166
+ const npmArgs = ['install', '--global', spec];
167
+
168
+ console.log(`OpenBroker — Install ${entry.key}`);
169
+ console.log('================================\n');
170
+ console.log(`Package: ${spec}`);
171
+ console.log(`Command: ${npmCommand} ${npmArgs.join(' ')}`);
172
+
173
+ if (args.has('--dry')) {
174
+ console.log('\nDry run only; nothing was installed.');
175
+ return;
176
+ }
177
+
178
+ const result = spawnSync(npmCommand, npmArgs, { stdio: 'inherit' });
179
+ if (result.error) fail(`could not start npm: ${result.error.message}`);
180
+ if (result.status !== 0) {
181
+ fail(`installation failed for ${entry.packageName}; resolve the npm error and retry`);
182
+ }
183
+
184
+ console.log(`\n✅ ${entry.packageName} installed successfully.`);
185
+ console.log(`Available command: ${entry.command}`);
186
+ console.log('\nNext steps:');
187
+ for (const step of entry.nextSteps) console.log(` ${step}`);
188
+ }
189
+
96
190
  function runApiWalletSetup(): void {
97
191
  const onboardPath = path.join(packageRoot, 'scripts', 'setup', 'onboard.ts');
98
192
 
@@ -121,6 +215,19 @@ function main(): void {
121
215
  return;
122
216
  }
123
217
 
218
+ if (args.has('--list')) {
219
+ printInstallablePackages();
220
+ return;
221
+ }
222
+
223
+ const positionals = positionalArgs();
224
+ if (positionals.length > 0) {
225
+ if (positionals.length > 1) fail(`expected one package name, received: ${positionals.join(' ')}`);
226
+ if (args.has('--codex')) fail('choose either a companion package or the --codex harness installer');
227
+ installCompanionPackage(positionals[0]);
228
+ return;
229
+ }
230
+
124
231
  if (!args.has('--codex')) {
125
232
  printUsage();
126
233
  fail('choose a supported harness flag such as --codex');
@@ -0,0 +1,50 @@
1
+ import test from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { spawnSync } from 'node:child_process';
4
+ import { fileURLToPath } from 'node:url';
5
+ import {
6
+ INSTALLABLE_PACKAGES,
7
+ packageSpec,
8
+ resolveInstallablePackage,
9
+ } from './package-catalog.js';
10
+
11
+ const installScript = fileURLToPath(new URL('./install.ts', import.meta.url));
12
+
13
+ test('resolves companion packages by short name and npm package name', () => {
14
+ assert.equal(resolveInstallablePackage('monitoring')?.packageName, 'openbroker-monitoring');
15
+ assert.equal(resolveInstallablePackage('openbroker-monitoring')?.key, 'monitoring');
16
+ assert.equal(resolveInstallablePackage('EXTENDED')?.command, 'openbroker-ex');
17
+ assert.equal(resolveInstallablePackage('unknown'), null);
18
+ });
19
+
20
+ test('builds pinned or latest npm package specs without accepting arbitrary specs', () => {
21
+ const monitoring = INSTALLABLE_PACKAGES.find((entry) => entry.key === 'monitoring');
22
+ assert.ok(monitoring);
23
+ assert.equal(packageSpec(monitoring), 'openbroker-monitoring@latest');
24
+ assert.equal(packageSpec(monitoring, '1.4.2'), 'openbroker-monitoring@1.4.2');
25
+ assert.throws(() => packageSpec(monitoring, 'npm:unrelated-package'));
26
+ assert.throws(() => packageSpec(monitoring, '../local-package'));
27
+ });
28
+
29
+ test('installer dry run prints the global npm operation without writing', () => {
30
+ const result = spawnSync(
31
+ process.execPath,
32
+ ['--import', 'tsx', installScript, 'monitoring', '--tag', '1.4.2', '--dry'],
33
+ { encoding: 'utf8' },
34
+ );
35
+
36
+ assert.equal(result.status, 0, result.stderr);
37
+ assert.match(result.stdout, /npm install --global openbroker-monitoring@1\.4\.2/);
38
+ assert.match(result.stdout, /nothing was installed/i);
39
+ });
40
+
41
+ test('installer rejects packages outside the catalog', () => {
42
+ const result = spawnSync(
43
+ process.execPath,
44
+ ['--import', 'tsx', installScript, 'unrelated-package', '--dry'],
45
+ { encoding: 'utf8' },
46
+ );
47
+
48
+ assert.equal(result.status, 1);
49
+ assert.match(result.stderr, /unknown installable package/i);
50
+ });
@@ -0,0 +1,49 @@
1
+ export interface InstallablePackage {
2
+ key: string;
3
+ aliases: string[];
4
+ packageName: string;
5
+ command: string;
6
+ description: string;
7
+ nextSteps: string[];
8
+ }
9
+
10
+ export const INSTALLABLE_PACKAGES: InstallablePackage[] = [
11
+ {
12
+ key: 'monitoring',
13
+ aliases: ['openbroker-monitoring'],
14
+ packageName: 'openbroker-monitoring',
15
+ command: 'openbroker-monitoring',
16
+ description: 'Local automation dashboard and optional audit observer',
17
+ nextSteps: [
18
+ 'openbroker-monitoring serve --host 127.0.0.1 --port 3001',
19
+ 'Open http://127.0.0.1:3001',
20
+ ],
21
+ },
22
+ {
23
+ key: 'extended',
24
+ aliases: ['openbroker-extended'],
25
+ packageName: 'openbroker-extended',
26
+ command: 'openbroker-ex',
27
+ description: 'Extended Exchange trading CLI and library',
28
+ nextSteps: [
29
+ 'openbroker-ex --help',
30
+ 'openbroker-ex setup',
31
+ ],
32
+ },
33
+ ];
34
+
35
+ export function resolveInstallablePackage(input: string): InstallablePackage | null {
36
+ const normalized = input.trim().toLowerCase();
37
+ return INSTALLABLE_PACKAGES.find((entry) => (
38
+ entry.key === normalized
39
+ || entry.packageName === normalized
40
+ || entry.aliases.includes(normalized)
41
+ )) ?? null;
42
+ }
43
+
44
+ export function packageSpec(entry: InstallablePackage, tag = 'latest'): string {
45
+ if (!/^[a-z0-9][a-z0-9._-]*$/i.test(tag)) {
46
+ throw new Error(`invalid package tag or version: ${tag}`);
47
+ }
48
+ return `${entry.packageName}@${tag}`;
49
+ }