@jackwener/opencli 1.0.6 → 1.1.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 (80) hide show
  1. package/README.md +26 -0
  2. package/README.zh-CN.md +3 -0
  3. package/SKILL.md +7 -2
  4. package/dist/cli-manifest.json +506 -6
  5. package/dist/cli.js +51 -1
  6. package/dist/clis/antigravity/serve.js +296 -47
  7. package/dist/clis/arxiv/paper.d.ts +1 -0
  8. package/dist/clis/arxiv/paper.js +21 -0
  9. package/dist/clis/arxiv/search.d.ts +1 -0
  10. package/dist/clis/arxiv/search.js +24 -0
  11. package/dist/clis/arxiv/utils.d.ts +18 -0
  12. package/dist/clis/arxiv/utils.js +49 -0
  13. package/dist/clis/boss/batchgreet.d.ts +1 -0
  14. package/dist/clis/boss/batchgreet.js +147 -0
  15. package/dist/clis/boss/exchange.d.ts +1 -0
  16. package/dist/clis/boss/exchange.js +111 -0
  17. package/dist/clis/boss/greet.d.ts +1 -0
  18. package/dist/clis/boss/greet.js +175 -0
  19. package/dist/clis/boss/invite.d.ts +1 -0
  20. package/dist/clis/boss/invite.js +158 -0
  21. package/dist/clis/boss/joblist.d.ts +1 -0
  22. package/dist/clis/boss/joblist.js +55 -0
  23. package/dist/clis/boss/mark.d.ts +1 -0
  24. package/dist/clis/boss/mark.js +141 -0
  25. package/dist/clis/boss/recommend.d.ts +1 -0
  26. package/dist/clis/boss/recommend.js +83 -0
  27. package/dist/clis/boss/stats.d.ts +1 -0
  28. package/dist/clis/boss/stats.js +116 -0
  29. package/dist/clis/sinafinance/news.d.ts +7 -0
  30. package/dist/clis/sinafinance/news.js +61 -0
  31. package/dist/clis/wikipedia/search.d.ts +1 -0
  32. package/dist/clis/wikipedia/search.js +30 -0
  33. package/dist/clis/wikipedia/summary.d.ts +1 -0
  34. package/dist/clis/wikipedia/summary.js +28 -0
  35. package/dist/clis/wikipedia/utils.d.ts +8 -0
  36. package/dist/clis/wikipedia/utils.js +18 -0
  37. package/dist/clis/xiaohongshu/creator-note-detail.d.ts +64 -5
  38. package/dist/clis/xiaohongshu/creator-note-detail.js +258 -69
  39. package/dist/clis/xiaohongshu/creator-note-detail.test.d.ts +1 -0
  40. package/dist/clis/xiaohongshu/creator-note-detail.test.js +211 -0
  41. package/dist/clis/xiaohongshu/creator-notes-summary.d.ts +28 -0
  42. package/dist/clis/xiaohongshu/creator-notes-summary.js +92 -0
  43. package/dist/clis/xiaohongshu/creator-notes-summary.test.d.ts +1 -0
  44. package/dist/clis/xiaohongshu/creator-notes-summary.test.js +49 -0
  45. package/dist/clis/xiaohongshu/creator-notes.d.ts +18 -5
  46. package/dist/clis/xiaohongshu/creator-notes.js +159 -71
  47. package/dist/clis/xiaohongshu/creator-notes.test.d.ts +1 -0
  48. package/dist/clis/xiaohongshu/creator-notes.test.js +162 -0
  49. package/dist/external.d.ts +20 -0
  50. package/dist/external.js +159 -0
  51. package/docs/.vitepress/config.mts +1 -1
  52. package/docs/public/CNAME +1 -0
  53. package/package.json +1 -1
  54. package/src/browser/cdp.ts +3 -3
  55. package/src/cli.ts +56 -1
  56. package/src/clis/antigravity/serve.ts +323 -50
  57. package/src/clis/arxiv/paper.ts +21 -0
  58. package/src/clis/arxiv/search.ts +24 -0
  59. package/src/clis/arxiv/utils.ts +63 -0
  60. package/src/clis/boss/batchgreet.ts +167 -0
  61. package/src/clis/boss/exchange.ts +126 -0
  62. package/src/clis/boss/greet.ts +198 -0
  63. package/src/clis/boss/invite.ts +177 -0
  64. package/src/clis/boss/joblist.ts +63 -0
  65. package/src/clis/boss/mark.ts +155 -0
  66. package/src/clis/boss/recommend.ts +94 -0
  67. package/src/clis/boss/stats.ts +130 -0
  68. package/src/clis/sinafinance/news.ts +76 -0
  69. package/src/clis/wikipedia/search.ts +32 -0
  70. package/src/clis/wikipedia/summary.ts +28 -0
  71. package/src/clis/wikipedia/utils.ts +20 -0
  72. package/src/clis/xiaohongshu/creator-note-detail.test.ts +223 -0
  73. package/src/clis/xiaohongshu/creator-note-detail.ts +340 -72
  74. package/src/clis/xiaohongshu/creator-notes-summary.test.ts +54 -0
  75. package/src/clis/xiaohongshu/creator-notes-summary.ts +120 -0
  76. package/src/clis/xiaohongshu/creator-notes.test.ts +178 -0
  77. package/src/clis/xiaohongshu/creator-notes.ts +215 -75
  78. package/src/daemon.ts +3 -3
  79. package/src/external-clis.yaml +39 -0
  80. package/src/external.ts +182 -0
@@ -0,0 +1,182 @@
1
+ import * as fs from 'node:fs';
2
+ import * as path from 'node:path';
3
+ import * as os from 'node:os';
4
+ import { fileURLToPath } from 'node:url';
5
+ import { spawnSync, execSync } from 'node:child_process';
6
+ import yaml from 'js-yaml';
7
+ import chalk from 'chalk';
8
+ import { log } from './logger.js';
9
+
10
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
11
+
12
+ export interface ExternalCliInstall {
13
+ mac?: string;
14
+ linux?: string;
15
+ windows?: string;
16
+ default?: string;
17
+ }
18
+
19
+ export interface ExternalCliConfig {
20
+ name: string;
21
+ binary: string;
22
+ description?: string;
23
+ homepage?: string;
24
+ tags?: string[];
25
+ install?: ExternalCliInstall;
26
+ }
27
+
28
+ function getUserRegistryPath(): string {
29
+ const home = os.homedir();
30
+ return path.join(home, '.opencli', 'external-clis.yaml');
31
+ }
32
+
33
+ export function loadExternalClis(): ExternalCliConfig[] {
34
+ const configs = new Map<string, ExternalCliConfig>();
35
+
36
+ // 1. Load built-in
37
+ const builtinPath = path.resolve(__dirname, 'external-clis.yaml');
38
+ try {
39
+ if (fs.existsSync(builtinPath)) {
40
+ const raw = fs.readFileSync(builtinPath, 'utf8');
41
+ const parsed = (yaml.load(raw) || []) as ExternalCliConfig[];
42
+ for (const item of parsed) configs.set(item.name, item);
43
+ }
44
+ } catch (err: any) {
45
+ log.warn(`Failed to parse built-in external-clis.yaml: ${err.message}`);
46
+ }
47
+
48
+ // 2. Load user custom
49
+ const userPath = getUserRegistryPath();
50
+ try {
51
+ if (fs.existsSync(userPath)) {
52
+ const raw = fs.readFileSync(userPath, 'utf8');
53
+ const parsed = (yaml.load(raw) || []) as ExternalCliConfig[];
54
+ for (const item of parsed) {
55
+ configs.set(item.name, item); // Overwrite built-in if duplicated
56
+ }
57
+ }
58
+ } catch (err: any) {
59
+ log.warn(`Failed to parse user external-clis.yaml: ${err.message}`);
60
+ }
61
+
62
+ return Array.from(configs.values()).sort((a, b) => a.name.localeCompare(b.name));
63
+ }
64
+
65
+ export function isBinaryInstalled(binary: string): boolean {
66
+ try {
67
+ const isWindows = os.platform() === 'win32';
68
+ const cmd = isWindows ? 'where' : 'command -v';
69
+ execSync(`${cmd} ${binary}`, { stdio: 'ignore' });
70
+ return true;
71
+ } catch {
72
+ return false;
73
+ }
74
+ }
75
+
76
+ export function getInstallCmd(installConfig?: ExternalCliInstall): string | null {
77
+ if (!installConfig) return null;
78
+ const platform = os.platform();
79
+ if (platform === 'darwin' && installConfig.mac) return installConfig.mac;
80
+ if (platform === 'linux' && installConfig.linux) return installConfig.linux;
81
+ if (platform === 'win32' && installConfig.windows) return installConfig.windows;
82
+ if (installConfig.default) return installConfig.default;
83
+ return null;
84
+ }
85
+
86
+ export function installExternalCli(cli: ExternalCliConfig): boolean {
87
+ if (!cli.install) {
88
+ console.error(chalk.red(`No auto-install command configured for '${cli.name}'.`));
89
+ console.error(`Please install '${cli.binary}' manually.`);
90
+ return false;
91
+ }
92
+
93
+ const cmd = getInstallCmd(cli.install);
94
+ if (!cmd) {
95
+ console.error(chalk.red(`No install command for your platform (${os.platform()}) for '${cli.name}'.`));
96
+ if (cli.homepage) console.error(`See: ${cli.homepage}`);
97
+ return false;
98
+ }
99
+
100
+ console.log(chalk.cyan(`🔹 '${cli.name}' is not installed. Auto-installing...`));
101
+ console.log(chalk.dim(`$ ${cmd}`));
102
+ try {
103
+ execSync(cmd, { stdio: 'inherit' });
104
+ console.log(chalk.green(`✅ Installed '${cli.name}' successfully.\n`));
105
+ return true;
106
+ } catch (err: any) {
107
+ console.error(chalk.red(`❌ Failed to install '${cli.name}': ${err.message}`));
108
+ return false;
109
+ }
110
+ }
111
+
112
+ export async function executeExternalCli(name: string, args: string[]): Promise<void> {
113
+ const configs = loadExternalClis();
114
+ const cli = configs.find((c) => c.name === name);
115
+ if (!cli) {
116
+ throw new Error(`External CLI '${name}' not found in registry.`);
117
+ }
118
+
119
+ // 1. Check if installed
120
+ if (!isBinaryInstalled(cli.binary)) {
121
+ // 2. Try to auto install
122
+ const success = installExternalCli(cli);
123
+ if (!success) {
124
+ process.exitCode = 1;
125
+ return;
126
+ }
127
+ }
128
+
129
+ // 3. Passthrough execution
130
+ // We use spawnSync to properly inherit stdio and block until completion
131
+ const result = spawnSync(cli.binary, args, { stdio: 'inherit' });
132
+ if (result.error) {
133
+ console.error(chalk.red(`Failed to execute '${cli.binary}': ${result.error.message}`));
134
+ process.exitCode = 1;
135
+ return;
136
+ }
137
+
138
+ if (result.status !== null) {
139
+ process.exitCode = result.status;
140
+ }
141
+ }
142
+
143
+ export function registerExternalCli(name: string, binary?: string, install?: string, description?: string): void {
144
+ const userPath = getUserRegistryPath();
145
+ const configDir = path.dirname(userPath);
146
+
147
+ if (!fs.existsSync(configDir)) {
148
+ fs.mkdirSync(configDir, { recursive: true });
149
+ }
150
+
151
+ let items: ExternalCliConfig[] = [];
152
+ if (fs.existsSync(userPath)) {
153
+ try {
154
+ const raw = fs.readFileSync(userPath, 'utf8');
155
+ items = (yaml.load(raw) || []) as ExternalCliConfig[];
156
+ } catch {
157
+ // Ignore
158
+ }
159
+ }
160
+
161
+ const existingIndex = items.findIndex((c) => c.name === name);
162
+
163
+ const newItem: ExternalCliConfig = {
164
+ name,
165
+ binary: binary || name,
166
+ };
167
+ if (description) newItem.description = description;
168
+ if (install) newItem.install = { default: install };
169
+
170
+ if (existingIndex >= 0) {
171
+ // Merge
172
+ items[existingIndex] = { ...items[existingIndex], ...newItem };
173
+ console.log(chalk.green(`Updated '${name}' in user registry.`));
174
+ } else {
175
+ items.push(newItem);
176
+ console.log(chalk.green(`Registered '${name}' in user registry.`));
177
+ }
178
+
179
+ const dump = yaml.dump(items, { indent: 2, sortKeys: true });
180
+ fs.writeFileSync(userPath, dump, 'utf8');
181
+ console.log(chalk.dim(userPath));
182
+ }