Skip to content

Commit 6b613fd

Browse files
committed
hot fix for agent command without params (should show help)
Optimized CLI bundle size
1 parent 558743e commit 6b613fd

File tree

7 files changed

+5091
-91
lines changed

7 files changed

+5091
-91
lines changed

packages/cli/bundle-stats.html

Lines changed: 4949 additions & 0 deletions
Large diffs are not rendered by default.

packages/cli/package.json

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,42 +77,43 @@
7777
}
7878
}
7979
},
80-
"dependencies": {},
8180
"devDependencies": {
8281
"@modelcontextprotocol/sdk": "^1.14.0",
8382
"@oclif/core": "^4.3.3",
84-
"@smythos/sdk": "workspace:*",
85-
"@smythos/sre": "workspace:*",
86-
"boxen": "^7.1.1",
87-
"chalk": "^5.3.0",
88-
"dotenv": "^16.5.0",
89-
"express": "^4.21.2",
90-
"extract-zip": "^2.0.1",
91-
"inquirer": "^9.2.15",
92-
"log-update": "^6.1.0",
93-
"ora": "^8.2.0",
94-
"update-notifier": "^7.0.0",
9583
"@oclif/plugin-help": "^6.2.21",
9684
"@oclif/test": "^3.1.9",
9785
"@rollup/plugin-commonjs": "^28.0.3",
9886
"@rollup/plugin-json": "^6.1.0",
9987
"@rollup/plugin-node-resolve": "^15.3.1",
10088
"@rollup/pluginutils": "^5.1.0",
89+
"@smythos/sdk": "workspace:*",
90+
"@smythos/sre": "workspace:*",
10191
"@types/extract-zip": "^2.0.3",
10292
"@types/inquirer": "^9.0.7",
10393
"@types/node": "^20.19.0",
10494
"@types/update-notifier": "^6.0.8",
95+
"boxen": "^7.1.1",
96+
"chalk": "^5.3.0",
10597
"cross-env": "^7.0.3",
98+
"dotenv": "^16.5.0",
10699
"esbuild": "^0.25.0",
100+
"express": "^4.21.2",
101+
"extract-zip": "^2.0.1",
107102
"glob": "^11.0.3",
103+
"inquirer": "^9.2.15",
108104
"knip": "^5.61.1",
105+
"log-update": "^6.1.0",
109106
"oclif": "^4.19.0",
107+
"ora": "^8.2.0",
110108
"rollup-plugin-esbuild": "^6.1.1",
111109
"rollup-plugin-sourcemaps": "^0.6.3",
112110
"rollup-plugin-terser": "^7.0.2",
113111
"rollup-plugin-typescript-paths": "^1.5.0",
112+
"rollup-plugin-visualizer": "^6.0.4",
113+
"tokenloom": "^1.0.7",
114114
"ts-node": "^10.9.2",
115115
"typedoc": "^0.28.5",
116-
"typescript": "^5.4.5"
116+
"typescript": "^5.4.5",
117+
"update-notifier": "^7.0.0"
117118
}
118119
}

packages/cli/rollup.config.js

Lines changed: 100 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import esbuild from 'rollup-plugin-esbuild';
44
import sourcemaps from 'rollup-plugin-sourcemaps';
55
import { terser } from 'rollup-plugin-terser';
66
import { typescriptPaths } from 'rollup-plugin-typescript-paths';
7+
import { visualizer } from 'rollup-plugin-visualizer';
78

89
import commonjs from '@rollup/plugin-commonjs';
910
import resolve from '@rollup/plugin-node-resolve';
@@ -78,47 +79,96 @@ const zeroDepConfig = {
7879
// }
7980
// },
8081
},
81-
// Only keep essential Node.js built-ins external
82-
external: [
83-
'fs',
84-
'fs/promises',
85-
'path',
86-
'path/posix',
87-
'path/win32',
88-
'os',
89-
'util',
90-
'crypto',
91-
'events',
92-
'stream',
93-
'url',
94-
'querystring',
95-
'http',
96-
'https',
97-
'net',
98-
'tls',
99-
'zlib',
100-
'buffer',
101-
'child_process',
102-
'cluster',
103-
'dgram',
104-
'dns',
105-
'domain',
106-
'module',
107-
'readline',
108-
'repl',
109-
'string_decoder',
110-
'timers',
111-
'tty',
112-
'vm',
113-
'worker_threads',
114-
'perf_hooks',
115-
'async_hooks',
116-
'inspector',
117-
'v8',
118-
'constants',
119-
'assert',
120-
'process',
121-
],
82+
// External function to exclude Node.js built-ins and dev-only packages
83+
external: (id) => {
84+
const builtins = [
85+
'fs',
86+
'fs/promises',
87+
'path',
88+
'path/posix',
89+
'path/win32',
90+
'os',
91+
'util',
92+
'crypto',
93+
'events',
94+
'stream',
95+
'url',
96+
'querystring',
97+
'http',
98+
'https',
99+
'net',
100+
'tls',
101+
'zlib',
102+
'buffer',
103+
'child_process',
104+
'cluster',
105+
'dgram',
106+
'dns',
107+
'domain',
108+
'module',
109+
'readline',
110+
'repl',
111+
'string_decoder',
112+
'timers',
113+
'tty',
114+
'vm',
115+
'worker_threads',
116+
'perf_hooks',
117+
'async_hooks',
118+
'inspector',
119+
'v8',
120+
'constants',
121+
'assert',
122+
'process',
123+
];
124+
125+
// Common dev-only packages that should never be bundled
126+
const devOnlyPackages = [
127+
'typescript',
128+
'esbuild',
129+
'rollup',
130+
'webpack',
131+
'vite',
132+
'vitest',
133+
'jest',
134+
'@types/',
135+
'eslint',
136+
'prettier',
137+
'ts-node',
138+
'nodemon',
139+
'@rollup/',
140+
'@vitejs/',
141+
'@jest/',
142+
'babel',
143+
'typedoc',
144+
'tslint',
145+
'mocha',
146+
'nyc',
147+
'husky',
148+
'lint-staged',
149+
'commitlint',
150+
];
151+
152+
// Exclude Node.js built-ins
153+
if (builtins.includes(id)) return true;
154+
155+
// Exclude dev-only packages (match package name boundaries)
156+
const normalizedId = id.replace(/\\/g, '/'); // Normalize Windows paths
157+
for (const pkg of devOnlyPackages) {
158+
// Match at package name boundaries to avoid false positives
159+
// e.g., "chai" shouldn't match "chain" in a path
160+
if (
161+
normalizedId.includes(`node_modules/${pkg}`) ||
162+
normalizedId.includes(`/${pkg}/`) ||
163+
normalizedId.endsWith(`/${pkg}`) ||
164+
normalizedId === pkg
165+
) {
166+
return true;
167+
}
168+
}
169+
170+
return false;
171+
},
122172
plugins: [
123173
deleteFolder('dist'),
124174
colorfulLogs('CLI Zero-Dep Builder'),
@@ -155,6 +205,15 @@ const zeroDepConfig = {
155205
},
156206
keepNames: true, // Keep all names
157207
}),
208+
// Bundle size visualization
209+
visualizer({
210+
filename: './bundle-stats.html',
211+
open: true, // automatically opens in browser
212+
gzipSize: true,
213+
brotliSize: true,
214+
template: 'treemap', // treemap, sunburst, or network
215+
title: 'CLI Bundle Size Report',
216+
}),
158217
// No terser plugin - no compression at all
159218
],
160219
};

packages/cli/src/commands/agent/agent.index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export default class AgentCmd extends Command {
9999
const { args, flags } = await this.parse(AgentCmd);
100100

101101
// If no arguments and no flags are provided, show help
102-
if (!args.path && Object.keys(flags).length === 0) {
102+
if (!args.path) {
103103
this.log('No agent path provided, showing help...');
104104
const help = new Help(this.config);
105105
await help.showHelp(['agent']);

packages/core/src/helpers/Sysconfig.helper.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,18 @@ export function findSmythPath(_path: string = '', callback?: (smythDir: string,
8080
return homeDir;
8181
}
8282

83+
export function findValidResourcePath(listOfLocations: string[], callback?: (dir: string, success?: boolean, nextDir?: string) => void) {
84+
let found = '';
85+
for (let location of listOfLocations) {
86+
found = findSmythPath(location, (dir, success, nextDir) => {
87+
callback?.(dir, success, nextDir);
88+
if (success) {
89+
found = dir;
90+
}
91+
});
92+
}
93+
return found;
94+
}
8395
function findPackageRoot(startDir = process.cwd()) {
8496
let currentDir = startDir;
8597

packages/core/src/helpers/TemplateString.helper.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,12 @@ export class TemplateStringHelper {
105105
public parse(data: Record<string, string>, regex: TemplateStringMatch = Match.default) {
106106
if (typeof this._current !== 'string' || typeof data !== 'object') return this;
107107
this._current = this._current.replace(regex, (match, token) => {
108-
const val = data?.[token] ?? match; // Use nullish coalescing to preserve falsy values (0, '', false)
108+
let val = data?.[token] ?? match; // Use nullish coalescing to preserve falsy values (0, '', false)
109+
110+
//if no exact match, try to parse the token as a JSON expression
111+
if (!data?.[token]) {
112+
val = JSONExpression(data, token) || `{{${token}}}`; //if no match, use the token as is
113+
}
109114

110115
return typeof val === 'object' ? JSON.stringify(val) : escapeJsonField(val);
111116
});

packages/core/src/subsystems/Security/Vault.service/connectors/JSONFileVault.class.ts

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
import { ConnectorService } from '@sre/Core/ConnectorsService';
22
import { Logger } from '@sre/helpers/Log.helper';
3-
import { SmythRuntime } from '@sre/Core/SmythRuntime.class';
4-
import { AccessCandidate } from '@sre/Security/AccessControl/AccessCandidate.class';
3+
import { findValidResourcePath } from '@sre/helpers/Sysconfig.helper';
54
import { AccessRequest } from '@sre/Security/AccessControl/AccessRequest.class';
65
import { ACL } from '@sre/Security/AccessControl/ACL.class';
76
import { SecureConnector } from '@sre/Security/SecureConnector.class';
87
import { IAccessCandidate, TAccessLevel, TAccessRole } from '@sre/types/ACL.types';
9-
import { EncryptionSettings } from '@sre/types/Security.types';
10-
import { IVaultRequest, VaultConnector } from '../VaultConnector';
11-
import os from 'os';
8+
import * as chokidar from 'chokidar';
129
import crypto from 'crypto';
1310
import fs from 'fs';
1411
import * as readlineSync from 'readline-sync';
15-
import path from 'path';
16-
import * as chokidar from 'chokidar';
17-
import { findSmythPath } from '../../../../helpers/Sysconfig.helper';
12+
import { VaultConnector } from '../VaultConnector';
1813

1914
const console = Logger('JSONFileVault');
2015

@@ -51,39 +46,18 @@ export class JSONFileVault extends VaultConnector {
5146
}
5247
console.warn('Vault file not found in:', _vaultFile);
5348

54-
//try to find it in .smyth directory
55-
_vaultFile = findSmythPath('vault.json', (dir, success, nextDir) => {
56-
if (!success) {
57-
console.warn('Vault file not found in:', nextDir);
58-
}
59-
});
60-
if (fs.existsSync(_vaultFile)) {
61-
console.warn('Using alternative vault file found in : ', _vaultFile);
62-
return _vaultFile;
63-
}
49+
let found = '';
6450

65-
//try to find it in .smyth directory
66-
_vaultFile = findSmythPath('vault/vault.json', (dir, success, nextDir) => {
67-
if (!success) {
68-
console.warn('Vault file not found in:', nextDir);
69-
}
70-
});
71-
if (fs.existsSync(_vaultFile)) {
72-
console.warn('Using alternative vault file found in : ', _vaultFile);
73-
return _vaultFile;
74-
}
75-
76-
//try to find the .smyth directory and check if it contains a valid vault
77-
78-
_vaultFile = findSmythPath('.sre/vault.json', (dir, success, nextDir) => {
51+
const relativeSearchLocations = ['vault.json', 'vault/vault.json', '.sre/vault.json'];
52+
found = findValidResourcePath(relativeSearchLocations, (dir, success, nextDir) => {
7953
if (!success) {
8054
console.warn('Vault file not found in:', nextDir);
8155
}
8256
});
8357

84-
if (fs.existsSync(_vaultFile)) {
85-
console.warn('Using alternative vault file found in : ', _vaultFile);
86-
return _vaultFile;
58+
if (found) {
59+
console.warn('Using alternative vault file found in : ', found);
60+
return found;
8761
}
8862

8963
console.warn('!!! All attempts to find the vault file failed !!!');

0 commit comments

Comments
 (0)