@zju_han/claudex-cli 2.1.88

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.

Potentially problematic release.


This version of @zju_han/claudex-cli might be problematic. Click here for more details.

@@ -0,0 +1,151 @@
1
+
2
+ type AudioCaptureNapi = {
3
+ startRecording(
4
+ onData: (data: Buffer) => void,
5
+ onEnd: () => void,
6
+ ): boolean
7
+ stopRecording(): void
8
+ isRecording(): boolean
9
+ startPlayback(sampleRate: number, channels: number): boolean
10
+ writePlaybackData(data: Buffer): void
11
+ stopPlayback(): void
12
+ isPlaying(): boolean
13
+ // TCC microphone authorization status (macOS only):
14
+ // 0 = notDetermined, 1 = restricted, 2 = denied, 3 = authorized.
15
+ // Linux: always returns 3 (authorized) — no system-level microphone permission API.
16
+ // Windows: returns 3 (authorized) if registry key absent or allowed,
17
+ // 2 (denied) if microphone access is explicitly denied.
18
+ microphoneAuthorizationStatus?(): number
19
+ }
20
+
21
+ let cachedModule: AudioCaptureNapi | null = null
22
+ let loadAttempted = false
23
+
24
+ function loadModule(): AudioCaptureNapi | null {
25
+ if (loadAttempted) {
26
+ return cachedModule
27
+ }
28
+ loadAttempted = true
29
+
30
+ // Supported platforms: macOS (darwin), Linux, Windows (win32)
31
+ const platform = process.platform
32
+ if (platform !== 'darwin' && platform !== 'linux' && platform !== 'win32') {
33
+ return null
34
+ }
35
+
36
+ // Candidate 1: native-embed path (bun compile). AUDIO_CAPTURE_NODE_PATH is
37
+ // defined at build time in build-with-plugins.ts for native builds only — the
38
+ // define resolves it to the static literal "../../audio-capture.node" so bun
39
+ // compile can rewrite it to /$bunfs/root/audio-capture.node. MUST stay a
40
+ // direct require(env var) — bun cannot analyze require(variable) from a loop.
41
+ if (process.env.AUDIO_CAPTURE_NODE_PATH) {
42
+ try {
43
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
44
+ cachedModule = require(
45
+ process.env.AUDIO_CAPTURE_NODE_PATH,
46
+ ) as AudioCaptureNapi
47
+ return cachedModule
48
+ } catch {
49
+ // fall through to runtime fallbacks below
50
+ }
51
+ }
52
+
53
+ // Candidates 2/3: npm-install and dev/source layouts. Dynamic require is
54
+ // fine here — in bundled output (node --target build) require() resolves at
55
+ // runtime relative to cli.js at the package root; in dev it resolves
56
+ // relative to this file (vendor/audio-capture-src/index.ts).
57
+ const platformDir = `${process.arch}-${platform}`
58
+ const fallbacks = [
59
+ `./vendor/audio-capture/${platformDir}/audio-capture.node`,
60
+ `../audio-capture/${platformDir}/audio-capture.node`,
61
+ ]
62
+ for (const p of fallbacks) {
63
+ try {
64
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
65
+ cachedModule = require(p) as AudioCaptureNapi
66
+ return cachedModule
67
+ } catch {
68
+ // try next
69
+ }
70
+ }
71
+ return null
72
+ }
73
+
74
+ export function isNativeAudioAvailable(): boolean {
75
+ return loadModule() !== null
76
+ }
77
+
78
+ export function startNativeRecording(
79
+ onData: (data: Buffer) => void,
80
+ onEnd: () => void,
81
+ ): boolean {
82
+ const mod = loadModule()
83
+ if (!mod) {
84
+ return false
85
+ }
86
+ return mod.startRecording(onData, onEnd)
87
+ }
88
+
89
+ export function stopNativeRecording(): void {
90
+ const mod = loadModule()
91
+ if (!mod) {
92
+ return
93
+ }
94
+ mod.stopRecording()
95
+ }
96
+
97
+ export function isNativeRecordingActive(): boolean {
98
+ const mod = loadModule()
99
+ if (!mod) {
100
+ return false
101
+ }
102
+ return mod.isRecording()
103
+ }
104
+
105
+ export function startNativePlayback(
106
+ sampleRate: number,
107
+ channels: number,
108
+ ): boolean {
109
+ const mod = loadModule()
110
+ if (!mod) {
111
+ return false
112
+ }
113
+ return mod.startPlayback(sampleRate, channels)
114
+ }
115
+
116
+ export function writeNativePlaybackData(data: Buffer): void {
117
+ const mod = loadModule()
118
+ if (!mod) {
119
+ return
120
+ }
121
+ mod.writePlaybackData(data)
122
+ }
123
+
124
+ export function stopNativePlayback(): void {
125
+ const mod = loadModule()
126
+ if (!mod) {
127
+ return
128
+ }
129
+ mod.stopPlayback()
130
+ }
131
+
132
+ export function isNativePlaying(): boolean {
133
+ const mod = loadModule()
134
+ if (!mod) {
135
+ return false
136
+ }
137
+ return mod.isPlaying()
138
+ }
139
+
140
+ // Returns the microphone authorization status.
141
+ // On macOS, returns the TCC status: 0=notDetermined, 1=restricted, 2=denied, 3=authorized.
142
+ // On Linux, always returns 3 (authorized) — no system-level mic permission API.
143
+ // On Windows, returns 3 (authorized) if registry key absent or allowed, 2 (denied) if explicitly denied.
144
+ // Returns 0 (notDetermined) if the native module is unavailable.
145
+ export function microphoneAuthorizationStatus(): number {
146
+ const mod = loadModule()
147
+ if (!mod || !mod.microphoneAuthorizationStatus) {
148
+ return 0
149
+ }
150
+ return mod.microphoneAuthorizationStatus()
151
+ }
@@ -0,0 +1,163 @@
1
+ export type ClipboardImageResult = {
2
+ png: Buffer
3
+ originalWidth: number
4
+ originalHeight: number
5
+ width: number
6
+ height: number
7
+ }
8
+
9
+ // Clipboard functions are macOS-only and only present in darwin binaries;
10
+ // older/non-darwin binaries built before this addition won't export them.
11
+ // Typed as optional so callers can guard. These property names appear only
12
+ // in type-space here; all runtime property access lives in src/ behind
13
+ // feature() so they tree-shake out of builds that don't want them.
14
+ export type NativeModule = {
15
+ processImage: (input: Buffer) => Promise<ImageProcessor>
16
+ readClipboardImage?: (maxWidth: number, maxHeight: number) => ClipboardImageResult | null
17
+ hasClipboardImage?: () => boolean
18
+ }
19
+
20
+ // Lazy: defers dlopen until first call. The .node binary links against
21
+ // CoreGraphics/ImageIO on darwin; resolving that at module-eval time blocks
22
+ // startup because imagePaste.ts pulls this into the REPL chunk via static
23
+ // import. Same pattern as audio-capture-src/index.ts.
24
+ let cachedModule: NativeModule | null = null
25
+ let loadAttempted = false
26
+
27
+ // Raw binding accessor. Callers that need optional exports (e.g. clipboard
28
+ // functions) reach through this; keeping the wrappers on the caller side lets
29
+ // feature() tree-shake the property access strings out of external builds.
30
+ export function getNativeModule(): NativeModule | null {
31
+ if (loadAttempted) return cachedModule
32
+ loadAttempted = true
33
+ try {
34
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
35
+ cachedModule = require('../../image-processor.node')
36
+ } catch {
37
+ cachedModule = null
38
+ }
39
+ return cachedModule
40
+ }
41
+
42
+ interface ImageProcessor {
43
+ metadata(): { width: number; height: number; format: string }
44
+ resize(
45
+ width: number,
46
+ height: number,
47
+ options?: { fit?: string; withoutEnlargement?: boolean },
48
+ ): ImageProcessor
49
+ jpeg(quality?: number): ImageProcessor
50
+ png(options?: {
51
+ compressionLevel?: number
52
+ palette?: boolean
53
+ colors?: number
54
+ }): ImageProcessor
55
+ webp(quality?: number): ImageProcessor
56
+ toBuffer(): Promise<Buffer>
57
+ }
58
+
59
+ interface SharpInstance {
60
+ metadata(): Promise<{ width: number; height: number; format: string }>
61
+ resize(
62
+ width: number,
63
+ height: number,
64
+ options?: { fit?: string; withoutEnlargement?: boolean },
65
+ ): SharpInstance
66
+ jpeg(options?: { quality?: number }): SharpInstance
67
+ png(options?: {
68
+ compressionLevel?: number
69
+ palette?: boolean
70
+ colors?: number
71
+ }): SharpInstance
72
+ webp(options?: { quality?: number }): SharpInstance
73
+ toBuffer(): Promise<Buffer>
74
+ }
75
+
76
+ // Factory function that matches sharp's API
77
+ export function sharp(input: Buffer): SharpInstance {
78
+ let processorPromise: Promise<ImageProcessor> | null = null
79
+
80
+ // Create a chain of operations
81
+ const operations: Array<(proc: ImageProcessor) => void> = []
82
+
83
+ // Track how many operations have been applied to avoid re-applying
84
+ let appliedOperationsCount = 0
85
+
86
+ // Get or create the processor (without applying operations)
87
+ async function ensureProcessor(): Promise<ImageProcessor> {
88
+ if (!processorPromise) {
89
+ processorPromise = (async () => {
90
+ const mod = getNativeModule()
91
+ if (!mod) {
92
+ throw new Error('Native image processor module not available')
93
+ }
94
+ return mod.processImage(input)
95
+ })()
96
+ }
97
+ return processorPromise
98
+ }
99
+
100
+ // Apply any pending operations to the processor
101
+ function applyPendingOperations(proc: ImageProcessor): void {
102
+ for (let i = appliedOperationsCount; i < operations.length; i++) {
103
+ const op = operations[i]
104
+ if (op) {
105
+ op(proc)
106
+ }
107
+ }
108
+ appliedOperationsCount = operations.length
109
+ }
110
+
111
+ const instance: SharpInstance = {
112
+ async metadata() {
113
+ const proc = await ensureProcessor()
114
+ return proc.metadata()
115
+ },
116
+
117
+ resize(
118
+ width: number,
119
+ height: number,
120
+ options?: { fit?: string; withoutEnlargement?: boolean },
121
+ ) {
122
+ operations.push(proc => {
123
+ proc.resize(width, height, options)
124
+ })
125
+ return instance
126
+ },
127
+
128
+ jpeg(options?: { quality?: number }) {
129
+ operations.push(proc => {
130
+ proc.jpeg(options?.quality)
131
+ })
132
+ return instance
133
+ },
134
+
135
+ png(options?: {
136
+ compressionLevel?: number
137
+ palette?: boolean
138
+ colors?: number
139
+ }) {
140
+ operations.push(proc => {
141
+ proc.png(options)
142
+ })
143
+ return instance
144
+ },
145
+
146
+ webp(options?: { quality?: number }) {
147
+ operations.push(proc => {
148
+ proc.webp(options?.quality)
149
+ })
150
+ return instance
151
+ },
152
+
153
+ async toBuffer() {
154
+ const proc = await ensureProcessor()
155
+ applyPendingOperations(proc)
156
+ return proc.toBuffer()
157
+ },
158
+ }
159
+
160
+ return instance
161
+ }
162
+
163
+ export default sharp
@@ -0,0 +1,67 @@
1
+ import { createRequire } from 'module'
2
+ import { fileURLToPath } from 'url'
3
+ import { dirname, join } from 'path'
4
+
5
+ type ModifiersNapi = {
6
+ getModifiers(): string[]
7
+ isModifierPressed(modifier: string): boolean
8
+ }
9
+
10
+ let cachedModule: ModifiersNapi | null = null
11
+
12
+ function loadModule(): ModifiersNapi | null {
13
+ if (cachedModule) {
14
+ return cachedModule
15
+ }
16
+
17
+ // Only works on macOS
18
+ if (process.platform !== 'darwin') {
19
+ return null
20
+ }
21
+
22
+ try {
23
+ if (process.env.MODIFIERS_NODE_PATH) {
24
+ // Bundled mode - use the env var path
25
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
26
+ cachedModule = require(process.env.MODIFIERS_NODE_PATH) as ModifiersNapi
27
+ } else {
28
+ // Dev mode - load from vendor directory
29
+ const modulePath = join(
30
+ dirname(fileURLToPath(import.meta.url)),
31
+ '..',
32
+ 'modifiers-napi',
33
+ `${process.arch}-darwin`,
34
+ 'modifiers.node',
35
+ )
36
+ cachedModule = createRequire(import.meta.url)(modulePath) as ModifiersNapi
37
+ }
38
+ return cachedModule
39
+ } catch {
40
+ return null
41
+ }
42
+ }
43
+
44
+ export function getModifiers(): string[] {
45
+ const mod = loadModule()
46
+ if (!mod) {
47
+ return []
48
+ }
49
+ return mod.getModifiers()
50
+ }
51
+
52
+ export function isModifierPressed(modifier: string): boolean {
53
+ const mod = loadModule()
54
+ if (!mod) {
55
+ return false
56
+ }
57
+ return mod.isModifierPressed(modifier)
58
+ }
59
+
60
+ /**
61
+ * Pre-warm the native module by loading it in advance.
62
+ * Call this early (e.g., at startup) to avoid delay on first use.
63
+ */
64
+ export function prewarm(): void {
65
+ // Just call loadModule to cache it
66
+ loadModule()
67
+ }
@@ -0,0 +1,3 @@
1
+ This project is dual-licensed under the Unlicense and MIT licenses.
2
+
3
+ You may use this code under the terms of either license.
@@ -0,0 +1,58 @@
1
+ import { createRequire } from 'module'
2
+ import { fileURLToPath } from 'url'
3
+ import { dirname, join } from 'path'
4
+
5
+ type UrlHandlerNapi = {
6
+ waitForUrlEvent(timeoutMs: number): string | null
7
+ }
8
+
9
+ let cachedModule: UrlHandlerNapi | null = null
10
+
11
+ function loadModule(): UrlHandlerNapi | null {
12
+ if (cachedModule) {
13
+ return cachedModule
14
+ }
15
+
16
+ // Only works on macOS
17
+ if (process.platform !== 'darwin') {
18
+ return null
19
+ }
20
+
21
+ try {
22
+ if (process.env.URL_HANDLER_NODE_PATH) {
23
+ // Bundled mode - use the env var path
24
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
25
+ cachedModule = require(process.env.URL_HANDLER_NODE_PATH) as UrlHandlerNapi
26
+ } else {
27
+ // Dev mode - load from vendor directory
28
+ const modulePath = join(
29
+ dirname(fileURLToPath(import.meta.url)),
30
+ '..',
31
+ 'url-handler',
32
+ `${process.arch}-darwin`,
33
+ 'url-handler.node',
34
+ )
35
+ cachedModule = createRequire(import.meta.url)(modulePath) as UrlHandlerNapi
36
+ }
37
+ return cachedModule
38
+ } catch {
39
+ return null
40
+ }
41
+ }
42
+
43
+ /**
44
+ * Wait for a macOS URL event (Apple Event kAEGetURL).
45
+ *
46
+ * Initializes NSApplication, registers for the URL event, and pumps
47
+ * the event loop for up to `timeoutMs` milliseconds.
48
+ *
49
+ * Returns the URL string if one was received, or null.
50
+ * Only functional on macOS — returns null on other platforms.
51
+ */
52
+ export function waitForUrlEvent(timeoutMs: number): string | null {
53
+ const mod = loadModule()
54
+ if (!mod) {
55
+ return null
56
+ }
57
+ return mod.waitForUrlEvent(timeoutMs)
58
+ }
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@zju_han/claudex-cli",
3
+ "version": "2.1.88",
4
+ "description": "ClaudeX is a local coding agent CLI powered by OpenAI/Codex-compatible Responses models.",
5
+ "type": "module",
6
+ "license": "SEE LICENSE IN README.md",
7
+ "author": "Anthropic <support@anthropic.com>",
8
+ "homepage": "https://github.com/InDreamer/co-claw-dex",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/InDreamer/co-claw-dex.git"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/InDreamer/co-claw-dex/issues"
15
+ },
16
+ "engines": {
17
+ "node": ">=18.0.0"
18
+ },
19
+ "bin": {
20
+ "claudex": "cli.js"
21
+ },
22
+ "files": [
23
+ "cli.js",
24
+ "dist-ant/**",
25
+ "README.md"
26
+ ]
27
+ }