cli4ai 1.1.4 → 1.2.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cli4ai",
3
- "version": "1.1.4",
3
+ "version": "1.2.0",
4
4
  "description": "The package manager for AI CLI tools - cli4ai.com",
5
5
  "type": "module",
6
6
  "bin": {
package/src/cli.ts CHANGED
@@ -93,6 +93,7 @@ export function createProgram(): Command {
93
93
  .alias('ls')
94
94
  .description('List installed packages')
95
95
  .option('-g, --global', 'List global packages')
96
+ .option('-r, --remote <name>', 'List packages on a remote server')
96
97
  .option('--json', 'Output as JSON')
97
98
  .action(withErrorHandling(listCommand));
98
99
 
@@ -143,12 +144,14 @@ Remote Execution:
143
144
  .command('info <package>')
144
145
  .description('Show package information')
145
146
  .option('--versions', 'Show all available versions')
147
+ .option('-r, --remote <name>', 'Get info from a remote server')
146
148
  .action(withErrorHandling(infoCommand));
147
149
 
148
150
  program
149
151
  .command('search <query>')
150
152
  .description('Search for packages')
151
153
  .option('-l, --limit <n>', 'Max results', '20')
154
+ .option('-r, --remote <name>', 'Search packages on a remote server')
152
155
  .action(withErrorHandling(searchCommand));
153
156
 
154
157
  program
@@ -2,7 +2,7 @@
2
2
  * cli4ai add - Install packages
3
3
  */
4
4
 
5
- import { existsSync, symlinkSync, mkdirSync, cpSync, rmSync } from 'fs';
5
+ import { existsSync, symlinkSync, mkdirSync, cpSync, rmSync, readdirSync, statSync, unlinkSync, lstatSync } from 'fs';
6
6
  import { resolve, dirname, join, basename, normalize } from 'path';
7
7
  import { createInterface } from 'readline';
8
8
  import { tmpdir } from 'os';
@@ -107,8 +107,6 @@ async function confirm(message: string): Promise<boolean> {
107
107
  * Validate extracted tarball paths to prevent path traversal attacks
108
108
  */
109
109
  function validateTarballPaths(extractedDir: string): boolean {
110
- const { readdirSync, statSync } = require('fs');
111
-
112
110
  function checkPath(dir: string): boolean {
113
111
  const entries = readdirSync(dir, { withFileTypes: true });
114
112
  for (const entry of entries) {
@@ -160,7 +158,6 @@ async function downloadFromNpm(packageName: string, targetDir: string): Promise<
160
158
  }
161
159
 
162
160
  // Find the tarball (it will be named like cli4ai-slack-1.0.2.tgz)
163
- const { readdirSync } = await import('fs');
164
161
  const files = readdirSync(tmpDir);
165
162
  const tarball = files.find(f => f.endsWith('.tgz'));
166
163
 
@@ -533,7 +530,6 @@ async function installPackage(
533
530
  // Remove existing if present
534
531
  if (existsSync(pkgDir)) {
535
532
  try {
536
- const { unlinkSync, rmSync, lstatSync } = await import('fs');
537
533
  const stat = lstatSync(pkgDir);
538
534
  if (stat.isSymbolicLink()) {
539
535
  unlinkSync(pkgDir);
@@ -8,12 +8,43 @@ import { output, outputError, log } from '../lib/cli.js';
8
8
  import { findPackage, loadConfig } from '../core/config.js';
9
9
  import { loadManifest, tryLoadManifest, type Manifest } from '../core/manifest.js';
10
10
  import { existsSync } from 'fs';
11
+ import { remotePackageInfo, RemoteConnectionError, RemoteApiError } from '../core/remote-client.js';
11
12
 
12
13
  interface InfoOptions {
13
14
  versions?: boolean;
15
+ remote?: string;
14
16
  }
15
17
 
16
18
  export async function infoCommand(packageName: string, options: InfoOptions): Promise<void> {
19
+ // Handle remote info
20
+ if (options.remote) {
21
+ try {
22
+ const info = await remotePackageInfo(options.remote, packageName);
23
+ if (!info) {
24
+ outputError('NOT_FOUND', `Package not found on remote: ${packageName}`, {
25
+ remote: options.remote
26
+ });
27
+ return;
28
+ }
29
+ output({
30
+ remote: options.remote,
31
+ name: info.name,
32
+ version: info.version,
33
+ description: info.description,
34
+ commands: info.commands ? Object.keys(info.commands) : [],
35
+ commandDetails: info.commands
36
+ });
37
+ } catch (err) {
38
+ if (err instanceof RemoteConnectionError) {
39
+ outputError('NETWORK_ERROR', err.message, { remote: err.remoteName, url: err.url });
40
+ } else if (err instanceof RemoteApiError) {
41
+ outputError(err.code, err.message, { remote: err.remoteName, details: err.details });
42
+ } else {
43
+ throw err;
44
+ }
45
+ }
46
+ return;
47
+ }
17
48
  // First check if it's installed
18
49
  const installed = findPackage(packageName, process.cwd());
19
50
 
@@ -2,22 +2,45 @@
2
2
  * cli4ai list - Show installed packages
3
3
  */
4
4
 
5
- import { output } from '../lib/cli.js';
5
+ import { output, outputError } from '../lib/cli.js';
6
6
  import {
7
7
  getGlobalPackages,
8
8
  getLocalPackages,
9
9
  getNpmGlobalPackages,
10
10
  type InstalledPackage
11
11
  } from '../core/config.js';
12
+ import { remoteListPackages, RemoteConnectionError, RemoteApiError } from '../core/remote-client.js';
12
13
 
13
14
  interface ListOptions {
14
15
  global?: boolean;
15
16
  json?: boolean;
17
+ remote?: string;
16
18
  }
17
19
 
18
20
  type PackageWithScope = InstalledPackage & { scope: 'local' | 'cli4ai' | 'npm' };
19
21
 
20
22
  export async function listCommand(options: ListOptions): Promise<void> {
23
+ // Handle remote listing
24
+ if (options.remote) {
25
+ try {
26
+ const result = await remoteListPackages(options.remote);
27
+ output({
28
+ remote: options.remote,
29
+ packages: result.packages,
30
+ count: result.packages.length
31
+ });
32
+ } catch (err) {
33
+ if (err instanceof RemoteConnectionError) {
34
+ outputError('NETWORK_ERROR', err.message, { remote: err.remoteName, url: err.url });
35
+ } else if (err instanceof RemoteApiError) {
36
+ outputError(err.code, err.message, { remote: err.remoteName, details: err.details });
37
+ } else {
38
+ throw err;
39
+ }
40
+ }
41
+ return;
42
+ }
43
+
21
44
  let packages: PackageWithScope[];
22
45
 
23
46
  // Get all package sources
@@ -5,12 +5,14 @@
5
5
  import { readdirSync, existsSync } from 'fs';
6
6
  import { resolve } from 'path';
7
7
  import { spawnSync } from 'child_process';
8
- import { output, log } from '../lib/cli.js';
8
+ import { output, outputError, log } from '../lib/cli.js';
9
9
  import { loadConfig, getGlobalPackages, getLocalPackages } from '../core/config.js';
10
10
  import { tryLoadManifest, type Manifest } from '../core/manifest.js';
11
+ import { remoteListPackages, RemoteConnectionError, RemoteApiError } from '../core/remote-client.js';
11
12
 
12
13
  interface SearchOptions {
13
14
  limit?: string;
15
+ remote?: string;
14
16
  }
15
17
 
16
18
  interface SearchResult {
@@ -26,6 +28,41 @@ export async function searchCommand(query: string, options: SearchOptions): Prom
26
28
  const limit = parseInt(options.limit || '20', 10);
27
29
  const queryLower = query.toLowerCase();
28
30
 
31
+ // Handle remote search
32
+ if (options.remote) {
33
+ try {
34
+ const packageList = await remoteListPackages(options.remote);
35
+ const results = packageList.packages
36
+ .filter(pkg =>
37
+ pkg.name.toLowerCase().includes(queryLower) ||
38
+ pkg.path.toLowerCase().includes(queryLower)
39
+ )
40
+ .slice(0, limit)
41
+ .map(pkg => ({
42
+ name: pkg.name,
43
+ version: pkg.version,
44
+ source: 'remote' as const,
45
+ installed: true
46
+ }));
47
+
48
+ output({
49
+ remote: options.remote,
50
+ query,
51
+ results,
52
+ count: results.length
53
+ });
54
+ } catch (err) {
55
+ if (err instanceof RemoteConnectionError) {
56
+ outputError('NETWORK_ERROR', err.message, { remote: err.remoteName, url: err.url });
57
+ } else if (err instanceof RemoteApiError) {
58
+ outputError(err.code, err.message, { remote: err.remoteName, details: err.details });
59
+ } else {
60
+ throw err;
61
+ }
62
+ }
63
+ return;
64
+ }
65
+
29
66
  const results: SearchResult[] = [];
30
67
  const seen = new Set<string>();
31
68