@jackwener/opencli 1.7.18 → 1.7.20

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 (120) hide show
  1. package/README.md +18 -17
  2. package/README.zh-CN.md +16 -18
  3. package/cli-manifest.json +311 -186
  4. package/clis/ctrip/ctrip.test.js +486 -1
  5. package/clis/ctrip/flight.js +136 -0
  6. package/clis/ctrip/hotel-search.js +132 -0
  7. package/clis/ctrip/utils.js +298 -0
  8. package/clis/google/search.js +16 -6
  9. package/clis/google-scholar/search.js +20 -5
  10. package/clis/google-scholar/search.test.js +35 -2
  11. package/clis/reddit/home.js +117 -0
  12. package/clis/reddit/home.test.js +127 -0
  13. package/clis/reddit/read.js +400 -54
  14. package/clis/reddit/read.test.js +315 -12
  15. package/clis/reddit/subreddit-info.js +117 -0
  16. package/clis/reddit/subreddit-info.test.js +163 -0
  17. package/clis/reddit/whoami.js +84 -0
  18. package/clis/reddit/whoami.test.js +105 -0
  19. package/clis/rednote/search.js +6 -2
  20. package/clis/twitter/bookmark-folder.js +8 -4
  21. package/clis/twitter/bookmark-folder.test.js +59 -1
  22. package/clis/twitter/bookmarks.js +12 -4
  23. package/clis/twitter/bookmarks.test.js +205 -0
  24. package/clis/twitter/followers.js +20 -5
  25. package/clis/twitter/followers.test.js +44 -0
  26. package/clis/twitter/following.js +36 -20
  27. package/clis/twitter/following.test.js +60 -8
  28. package/clis/twitter/likes.js +28 -13
  29. package/clis/twitter/likes.test.js +111 -1
  30. package/clis/twitter/list-add.js +128 -204
  31. package/clis/twitter/list-add.test.js +97 -1
  32. package/clis/twitter/list-tweets.js +13 -4
  33. package/clis/twitter/list-tweets.test.js +48 -0
  34. package/clis/twitter/lists.js +5 -2
  35. package/clis/twitter/post.js +23 -4
  36. package/clis/twitter/post.test.js +30 -0
  37. package/clis/twitter/profile.js +16 -8
  38. package/clis/twitter/profile.test.js +39 -0
  39. package/clis/twitter/reply.js +133 -10
  40. package/clis/twitter/reply.test.js +55 -0
  41. package/clis/twitter/search.js +188 -170
  42. package/clis/twitter/search.test.js +96 -258
  43. package/clis/twitter/shared.js +167 -16
  44. package/clis/twitter/shared.test.js +102 -1
  45. package/clis/twitter/timeline.js +3 -1
  46. package/clis/twitter/tweets.js +147 -51
  47. package/clis/twitter/tweets.test.js +238 -1
  48. package/clis/xiaohongshu/comments.js +23 -2
  49. package/clis/xiaohongshu/comments.test.js +63 -1
  50. package/clis/xiaohongshu/search.js +168 -13
  51. package/clis/xiaohongshu/search.test.js +82 -8
  52. package/clis/xueqiu/earnings-date.js +2 -2
  53. package/clis/xueqiu/kline.js +2 -2
  54. package/clis/xueqiu/utils.js +19 -0
  55. package/clis/xueqiu/utils.test.js +26 -0
  56. package/clis/zhihu/answer-detail.js +233 -0
  57. package/clis/zhihu/answer-detail.test.js +330 -0
  58. package/clis/zhihu/question.js +44 -10
  59. package/clis/zhihu/question.test.js +78 -1
  60. package/clis/zhihu/recommend.js +103 -0
  61. package/clis/zhihu/recommend.test.js +143 -0
  62. package/dist/src/browser/base-page.d.ts +3 -2
  63. package/dist/src/browser/base-page.test.js +2 -2
  64. package/dist/src/browser/cdp.js +3 -3
  65. package/dist/src/browser/daemon-client.d.ts +1 -0
  66. package/dist/src/browser/daemon-client.js +3 -0
  67. package/dist/src/browser/daemon-client.test.js +20 -0
  68. package/dist/src/browser/page.d.ts +3 -2
  69. package/dist/src/browser/page.js +4 -4
  70. package/dist/src/browser/page.test.js +31 -0
  71. package/dist/src/browser/utils.d.ts +10 -0
  72. package/dist/src/browser/utils.js +37 -0
  73. package/dist/src/browser/utils.test.d.ts +1 -0
  74. package/dist/src/browser/utils.test.js +29 -0
  75. package/dist/src/cli-argv-preprocess.d.ts +37 -0
  76. package/dist/src/cli-argv-preprocess.js +131 -0
  77. package/dist/src/cli-argv-preprocess.test.d.ts +1 -0
  78. package/dist/src/cli-argv-preprocess.test.js +130 -0
  79. package/dist/src/cli.js +131 -89
  80. package/dist/src/cli.test.js +34 -28
  81. package/dist/src/commands/daemon.js +6 -7
  82. package/dist/src/daemon-utils.d.ts +18 -0
  83. package/dist/src/daemon-utils.js +37 -0
  84. package/dist/src/daemon.d.ts +1 -1
  85. package/dist/src/daemon.js +44 -13
  86. package/dist/src/daemon.test.js +42 -1
  87. package/dist/src/doctor.js +15 -16
  88. package/dist/src/download/progress.js +15 -11
  89. package/dist/src/download/progress.test.d.ts +1 -0
  90. package/dist/src/download/progress.test.js +25 -0
  91. package/dist/src/electron-apps.js +0 -1
  92. package/dist/src/electron-apps.test.js +1 -0
  93. package/dist/src/execution.js +1 -3
  94. package/dist/src/execution.test.js +4 -16
  95. package/dist/src/external-clis.yaml +12 -3
  96. package/dist/src/external.d.ts +4 -0
  97. package/dist/src/external.js +3 -0
  98. package/dist/src/external.test.js +24 -1
  99. package/dist/src/help.d.ts +16 -1
  100. package/dist/src/help.js +50 -8
  101. package/dist/src/help.test.js +5 -1
  102. package/dist/src/logger.js +8 -9
  103. package/dist/src/main.js +16 -0
  104. package/dist/src/output.js +4 -5
  105. package/dist/src/runtime-detect.d.ts +1 -1
  106. package/dist/src/runtime-detect.js +1 -1
  107. package/dist/src/runtime-detect.test.js +3 -2
  108. package/dist/src/tui.d.ts +0 -1
  109. package/dist/src/tui.js +9 -22
  110. package/dist/src/types.d.ts +3 -1
  111. package/dist/src/update-check.js +4 -5
  112. package/package.json +5 -4
  113. package/clis/notion/export.js +0 -32
  114. package/clis/notion/favorites.js +0 -85
  115. package/clis/notion/new.js +0 -35
  116. package/clis/notion/read.js +0 -31
  117. package/clis/notion/search.js +0 -47
  118. package/clis/notion/sidebar.js +0 -42
  119. package/clis/notion/status.js +0 -17
  120. package/clis/notion/write.js +0 -41
@@ -0,0 +1,130 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { getBrowserSubcommandNames, rewriteBrowserArgv } from './cli-argv-preprocess.js';
3
+ describe('rewriteBrowserArgv', () => {
4
+ it('rewrites `browser <session> <subcommand>` into `browser --session <name> <subcommand>`', () => {
5
+ expect(rewriteBrowserArgv(['browser', 'work', 'state'])).toEqual([
6
+ 'browser',
7
+ '--session',
8
+ 'work',
9
+ 'state',
10
+ ]);
11
+ });
12
+ it('rewrites with subcommand arguments preserved', () => {
13
+ expect(rewriteBrowserArgv(['browser', 'mercury', 'open', 'https://x.com'])).toEqual([
14
+ 'browser',
15
+ '--session',
16
+ 'mercury',
17
+ 'open',
18
+ 'https://x.com',
19
+ ]);
20
+ });
21
+ it('rewrites `browser <session> bind`', () => {
22
+ expect(rewriteBrowserArgv(['browser', 'mercury', 'bind'])).toEqual([
23
+ 'browser',
24
+ '--session',
25
+ 'mercury',
26
+ 'bind',
27
+ ]);
28
+ });
29
+ it('leaves argv alone when session omitted and a subcommand follows', () => {
30
+ // Commander surfaces the required-flag error itself.
31
+ expect(rewriteBrowserArgv(['browser', 'state'])).toEqual(['browser', 'state']);
32
+ expect(rewriteBrowserArgv(['browser', 'bind'])).toEqual(['browser', 'bind']);
33
+ });
34
+ it('leaves argv alone when the token after `browser` is a flag', () => {
35
+ expect(rewriteBrowserArgv(['browser', '--help'])).toEqual(['browser', '--help']);
36
+ expect(rewriteBrowserArgv(['browser', '-h'])).toEqual(['browser', '-h']);
37
+ });
38
+ it('refuses the retired `opencli browser --session foo ...` user form', () => {
39
+ // The flag form is no longer a public entrance. Tests calling
40
+ // program.parseAsync directly bypass the preprocessor, so internal
41
+ // callers still work; but the user-facing pipeline throws.
42
+ expect(() => rewriteBrowserArgv(['browser', '--session', 'foo', 'state']))
43
+ .toThrowError(/no longer a public option/i);
44
+ expect(() => rewriteBrowserArgv(['browser', '--session=foo', 'state']))
45
+ .toThrowError(/no longer a public option/i);
46
+ });
47
+ it('leaves argv alone when `browser` is not present', () => {
48
+ expect(rewriteBrowserArgv(['twitter', 'tweets', '@elonmusk'])).toEqual([
49
+ 'twitter',
50
+ 'tweets',
51
+ '@elonmusk',
52
+ ]);
53
+ expect(rewriteBrowserArgv(['doctor'])).toEqual(['doctor']);
54
+ });
55
+ it('returns argv unchanged when `browser` is the last token', () => {
56
+ expect(rewriteBrowserArgv(['browser'])).toEqual(['browser']);
57
+ });
58
+ it('only rewrites when `browser` is the root command, not deeper in argv', () => {
59
+ // `opencli adapter init browser/x` — the literal `browser` is a path argument,
60
+ // not the root command. Must not be touched.
61
+ expect(rewriteBrowserArgv(['adapter', 'init', 'browser', 'x'])).toEqual([
62
+ 'adapter',
63
+ 'init',
64
+ 'browser',
65
+ 'x',
66
+ ]);
67
+ // Same for URLs or arbitrary arg values that happen to contain `browser`.
68
+ expect(rewriteBrowserArgv(['twitter', 'tweets', 'https://browser.example.com'])).toEqual([
69
+ 'twitter',
70
+ 'tweets',
71
+ 'https://browser.example.com',
72
+ ]);
73
+ // First-match heuristic must NOT rewrite when an earlier non-flag token
74
+ // already established a different root command.
75
+ expect(rewriteBrowserArgv(['list', 'browser', 'state'])).toEqual([
76
+ 'list',
77
+ 'browser',
78
+ 'state',
79
+ ]);
80
+ });
81
+ it('skips leading root flags before identifying the root command', () => {
82
+ // `--profile` takes a value — the value is not the command.
83
+ expect(rewriteBrowserArgv(['--profile', 'work', 'browser', 'mercury', 'state'])).toEqual([
84
+ '--profile',
85
+ 'work',
86
+ 'browser',
87
+ '--session',
88
+ 'mercury',
89
+ 'state',
90
+ ]);
91
+ // Long form with `=` separator consumes one slot only.
92
+ expect(rewriteBrowserArgv(['--profile=work', 'browser', 'mercury', 'state'])).toEqual([
93
+ '--profile=work',
94
+ 'browser',
95
+ '--session',
96
+ 'mercury',
97
+ 'state',
98
+ ]);
99
+ // Boolean flags don't consume values.
100
+ expect(rewriteBrowserArgv(['-v', 'browser', 'mercury', 'state'])).toEqual([
101
+ '-v',
102
+ 'browser',
103
+ '--session',
104
+ 'mercury',
105
+ 'state',
106
+ ]);
107
+ });
108
+ it('leaves argv alone when the root command is not `browser`, even if `browser` appears later', () => {
109
+ // The first browser keyword does NOT win — it must be at the root.
110
+ expect(rewriteBrowserArgv(['twitter', 'browser', 'work', 'state'])).toEqual([
111
+ 'twitter',
112
+ 'browser',
113
+ 'work',
114
+ 'state',
115
+ ]);
116
+ });
117
+ it('reserved subcommand list covers every known browser subcommand registered in cli.ts', () => {
118
+ const names = getBrowserSubcommandNames();
119
+ const required = [
120
+ 'analyze', 'back', 'bind', 'check', 'click', 'close', 'console', 'dblclick',
121
+ 'dialog', 'drag', 'eval', 'extract', 'fill', 'find', 'focus', 'frames',
122
+ 'get', 'hover', 'init', 'keys', 'network', 'open', 'screenshot', 'scroll',
123
+ 'select', 'state', 'tab', 'type', 'unbind', 'uncheck', 'upload', 'verify',
124
+ 'wait',
125
+ ];
126
+ for (const name of required) {
127
+ expect(names.has(name)).toBe(true);
128
+ }
129
+ });
130
+ });