@linxiraos/pi-natives 1.0.9 → 1.0.10

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/native/index.d.ts CHANGED
@@ -279,7 +279,7 @@ export declare function __ompInstallTokioRuntime(): void
279
279
  * `packages/natives/native/index.js` (which derives the name from
280
280
  * `package.json#version`).
281
281
  */
282
- export declare function __piNativesV1_0_9(): void
282
+ export declare function __piNativesV1_0_10(): void
283
283
 
284
284
  /**
285
285
  * Apply ast-grep rewrite rules to matching files; honors `dryRun` and returns
@@ -1578,6 +1578,32 @@ export interface PatchHunk {
1578
1578
  lines: Array<string>
1579
1579
  }
1580
1580
 
1581
+ /** Markdown and inspection metadata produced from a PDF document. */
1582
+ export interface PdfMarkdownResult {
1583
+ /** Extracted document content in Markdown format. */
1584
+ markdown: string
1585
+ /** Document title from PDF metadata, when present. */
1586
+ title?: string
1587
+ /** Total number of pages in the document. */
1588
+ pageCount: number
1589
+ /** One-indexed page numbers whose content requires OCR. */
1590
+ pagesNeedingOcr: Array<number>
1591
+ /** Whether the document contains text encoding problems. */
1592
+ hasEncodingIssues: boolean
1593
+ }
1594
+
1595
+ /**
1596
+ * Convert an in-memory PDF to Markdown and return its inspection metadata.
1597
+ *
1598
+ * Conversion copies the typed array before dispatch so JavaScript mutation
1599
+ * cannot race the native worker.
1600
+ *
1601
+ * # Errors
1602
+ * Returns an error prefixed with `PDF conversion failed:` when the PDF cannot
1603
+ * be parsed or converted.
1604
+ */
1605
+ export declare function pdfToMarkdown(input: Uint8Array): Promise<PdfMarkdownResult>
1606
+
1581
1607
  export interface PointerOptions {
1582
1608
  button?: string
1583
1609
  count?: number
@@ -2011,1583 +2037,3 @@ export interface WorkProfile {
2011
2037
  * Returns UTF-16 lines with active SGR codes carried across line boundaries.
2012
2038
  */
2013
2039
  export declare function wrapTextWithAnsi(text: string, width: number, tabWidth: number): Array<string>
2014
-
2015
- export declare class AudioCapture {
2016
- /** Open the default microphone and deliver low-latency mono PCM chunks. */
2017
- constructor(sampleRate: number, onAudio: (error: Error | null, samples: Float32Array) => void)
2018
- /** Stop capture immediately and release the microphone. */
2019
- stop(): void
2020
- }
2021
-
2022
- /** Gapless mono `f32` playback through the default speaker. */
2023
- export declare class AudioPlayback {
2024
- /** Open the default speaker at the requested logical sample rate. */
2025
- constructor(sampleRate: number)
2026
- /** Queue mono floating-point PCM in playback order. */
2027
- write(samples: Float32Array): void
2028
- /** Scale audio at render time so gain changes affect already queued samples. */
2029
- setGain(gain: number): void
2030
- /**
2031
- * Close input, wait until queued samples reach the speaker, then release
2032
- * it.
2033
- */
2034
- end(): Promise<void>
2035
- /** Stop immediately and discard all queued samples. */
2036
- stop(): void
2037
- }
2038
-
2039
- /** Persistent, serialized native desktop capture/input/accessibility session. */
2040
- export declare class DesktopSession {
2041
- constructor(options?: DesktopSessionOptions | undefined | null)
2042
- get capabilities(): DesktopCapabilities
2043
- listDisplays(): Promise<Array<DesktopDisplay>>
2044
- listWindows(): Promise<Array<DesktopWindow>>
2045
- capture(target: string, caps?: CaptureCaps | undefined | null): Promise<DesktopCapture>
2046
- click(target: string, x: number, y: number, opts?: PointerOptions | undefined | null): Promise<undefined>
2047
- moveMouse(target: string, x: number, y: number, opts?: PointerOptions | undefined | null): Promise<undefined>
2048
- drag(target: string, path: Array<DesktopPoint>, opts?: PointerOptions | undefined | null): Promise<undefined>
2049
- scroll(target: string, x: number, y: number, dx: number, dy: number, opts?: PointerOptions | undefined | null): Promise<undefined>
2050
- typeText(target: string, text: string, opts?: PointerOptions | undefined | null): Promise<undefined>
2051
- keyChord(target: string, keys: Array<string>, opts?: PointerOptions | undefined | null): Promise<undefined>
2052
- raiseWindow(windowId: string): Promise<undefined>
2053
- axSnapshot(target: string, opts?: AxSnapshotOptions | undefined | null): Promise<AxSnapshot>
2054
- axQuery(target: string, query: AxQuery): Promise<Array<AxNode>>
2055
- /**
2056
- * Accessibility hit-test at global logical desktop coordinates; needs no
2057
- * prior capture.
2058
- */
2059
- axElementAt(target: string, x: number, y: number): Promise<AxNode | undefined | null>
2060
- axFocused(): Promise<AxNode | undefined | null>
2061
- axNode(reference: string): Promise<AxNode>
2062
- axAttributes(reference: string): Promise<Array<[string, string]>>
2063
- axChildren(reference: string): Promise<Array<AxNode>>
2064
- axParent(reference: string): Promise<AxNode | undefined | null>
2065
- axPerform(reference: string, action: string): Promise<undefined>
2066
- axSetValue(reference: string, value: string): Promise<undefined>
2067
- axFocus(reference: string): Promise<undefined>
2068
- axClick(reference: string, opts?: PointerOptions | undefined | null): Promise<undefined>
2069
- close(): Promise<undefined>
2070
- }
2071
-
2072
- /**
2073
- * Process-owned cross-platform advisory lock.
2074
- *
2075
- * `tryAcquire()` is non-blocking; its returned handle reports whether it won
2076
- * through `acquired`. Ownership ends on `release()`, garbage collection, or
2077
- * process exit; `release()` is idempotent.
2078
- */
2079
- export declare class FileLock {
2080
- /** Try to acquire `path` without blocking. */
2081
- static tryAcquire(path: string): FileLock
2082
- /** Whether this handle owns the requested lock. */
2083
- get acquired(): boolean
2084
- /** Release this handle's ownership without affecting a successor. */
2085
- release(): void
2086
- }
2087
-
2088
- /** WebRTC peer that accepts 16 kHz mono PCM and renders remote Opus audio. */
2089
- export declare class LiveWebRtcPeer {
2090
- /**
2091
- * Create an idle peer and register its event, output-level, and failure
2092
- * callbacks.
2093
- */
2094
- constructor(onEvent: (error: Error | null, payload: string) => void, onLevel: (error: Error | null, level: number) => void, onFailure: (error: Error | null, message: string) => void)
2095
- /** Start the native media peer and return its SDP offer. */
2096
- createOffer(): Promise<string>
2097
- /** Apply the remote SDP answer returned by Codex signaling. */
2098
- acceptAnswer(sdp: string): Promise<void>
2099
- /** Wait until the `oai-events` data channel is open. */
2100
- waitForOpen(timeoutMs?: number | undefined | null): Promise<void>
2101
- /** Queue 16 kHz mono floating-point PCM for Opus transmission. */
2102
- pushAudio(samples: Float32Array): void
2103
- /**
2104
- * Enable or disable microphone transmission, discarding partial muted
2105
- * frames.
2106
- */
2107
- setMuted(muted: boolean): void
2108
- /** Close media, the data channel, the peer connection, and speaker playback. */
2109
- close(): Promise<void>
2110
- }
2111
-
2112
- /**
2113
- * Long-lived macOS appearance observer.
2114
- *
2115
- * Subscribes to `AppleInterfaceThemeChangedNotification` via
2116
- * `CFDistributedNotificationCenter` and calls the provided callback
2117
- * with `"dark"` or `"light"` on each change (and once on start).
2118
- *
2119
- * A 2-second polling timer also runs as fallback — distributed
2120
- * notifications may not reliably reach background threads on all
2121
- * macOS versions.
2122
- *
2123
- * On non-macOS platforms, `start()` returns a no-op observer.
2124
- */
2125
- export declare class MacAppearanceObserver {
2126
- static start(callback: (err: null | Error, appearance: MacOSAppearance) => void): MacAppearanceObserver
2127
- stop(): void
2128
- }
2129
-
2130
- /**
2131
- * Long-lived macOS power assertion.
2132
- *
2133
- * On macOS this acquires one or more `IOKit` assertions that prevent the
2134
- * requested sleep modes until the handle is stopped or dropped. On other
2135
- * platforms it is a no-op handle so the caller can keep one cross-platform
2136
- * code path.
2137
- */
2138
- export declare class MacOSPowerAssertion {
2139
- /**
2140
- * Acquire a macOS power assertion. On non-macOS platforms returns a
2141
- * no-op handle so callers can stay cross-platform.
2142
- */
2143
- static start(options?: MacOSPowerAssertionOptions | undefined | null): MacOSPowerAssertion
2144
- /**
2145
- * Release every assertion held by this handle. Safe to call multiple
2146
- * times; subsequent calls are a no-op.
2147
- */
2148
- stop(): void
2149
- }
2150
-
2151
- /** Stable process reference. */
2152
- export declare class Process {
2153
- /** Open a stable process reference from a PID. */
2154
- static fromPid(pid: number): Process | null
2155
- /** Open stable process references whose executable path matches exactly. */
2156
- static fromPath(path: string): Array<Process>
2157
- /** Operating-system process identifier for this process reference. */
2158
- get pid(): number
2159
- /** Parent process id for this process, when available. */
2160
- get ppid(): number | null
2161
- /** Launch arguments for this process. */
2162
- args(): Array<string>
2163
- /**
2164
- * Send `signal` to this process and its descendants, children first.
2165
- *
2166
- * On Linux and macOS the signal is forwarded as-is. On Windows there is no
2167
- * signal abstraction, so the `signal` argument is ignored and the entire
2168
- * tree is hard-killed via `TerminateProcess`. Defaults to the POSIX
2169
- * hard-kill signal.
2170
- */
2171
- killTree(signal?: number | undefined | null): number
2172
- /**
2173
- * Gracefully terminate this process and its descendants.
2174
- *
2175
- * By default this waits 1000ms after polite termination before
2176
- * hard-killing. Pass `graceful_ms < 0` to skip the graceful phase.
2177
- */
2178
- terminate(options?: ProcessTerminateOptions | undefined | null): Promise<boolean>
2179
- /**
2180
- * Wait until this process exits.
2181
- *
2182
- * When `options.timeout_ms` is omitted, waits until the process exits.
2183
- */
2184
- waitForExit(options?: ProcessWaitOptions | undefined | null): Promise<boolean>
2185
- /** Process group id for this process, when supported by the platform. */
2186
- groupId(): number | null
2187
- /** Direct children of this process as stable process references. */
2188
- children(): Array<Process>
2189
- /** Current status of this process reference. */
2190
- status(): ProcessStatus
2191
- }
2192
-
2193
- /** Stateful PTY session for interactive stdin/stdout passthrough. */
2194
- export declare class PtySession {
2195
- constructor()
2196
- /**
2197
- * Start a shell command, stream output chunks, and report the spawned child
2198
- * PID.
2199
- */
2200
- start(options: PtyStartOptions, onChunk?: ((error: Error | null, chunk: string) => void) | undefined | null, onStart?: ((error: Error | null, pid: number) => void) | undefined | null): Promise<PtyRunResult>
2201
- /**
2202
- * Start an executable with separate arguments, stream output chunks, and
2203
- * report the spawned child PID.
2204
- */
2205
- startArgv(options: PtyArgvStartOptions, onChunk?: ((error: Error | null, chunk: string) => void) | undefined | null, onStart?: ((error: Error | null, pid: number) => void) | undefined | null): Promise<PtyRunResult>
2206
- /** Write raw input bytes to PTY stdin. */
2207
- write(data: string): void
2208
- /** Resize the active PTY. */
2209
- resize(cols: number, rows: number): void
2210
- /** Force-kill the active PTY command. */
2211
- kill(): void
2212
- }
2213
-
2214
- /** Persistent brush-core shell session. */
2215
- export declare class Shell {
2216
- /**
2217
- * Create a new shell session from optional configuration.
2218
- *
2219
- * The options set session-scoped environment variables and a snapshot path.
2220
- */
2221
- constructor(options?: ShellOptions | undefined | null)
2222
- /**
2223
- * Run a shell command using the provided options.
2224
- *
2225
- * The `on_chunk` callback receives streamed stdout/stderr output. Returns
2226
- * the exit code when the command completes, or flags when cancelled or
2227
- * timed out.
2228
- */
2229
- run(options: ShellRunOptions, onChunk?: ((error: Error | null, chunk: string) => void) | undefined | null): Promise<ShellRunResult>
2230
- /**
2231
- * Abort all running commands for this shell session.
2232
- *
2233
- * Returns `Ok(())` even when no commands are running.
2234
- */
2235
- abort(): Promise<void>
2236
- /**
2237
- * Count live background jobs (`&`/`nohup` children still running) on this
2238
- * session. Completed jobs are reaped first. The host uses this to retain a
2239
- * per-call shell whose background processes are still running instead of
2240
- * dropping it (which would SIGKILL them via kill-on-drop).
2241
- */
2242
- liveBackgroundJobCount(): Promise<number>
2243
- }
2244
-
2245
- /**
2246
- * Install the bounded Tokio runtime napi-rs adopts for async exports and the
2247
- * bounded Rayon global pool used by native parallel iterators.
2248
- *
2249
- * The JS loader calls this exactly once, synchronously, right *after* `dlopen`
2250
- * returns and *before* any async native or parallel iterator runs — never from
2251
- * `#[module_init]`. Building a multi-thread runtime eagerly spawns worker
2252
- * threads, and doing that during module init (while the dynamic-loader lock is
2253
- * held) deadlocks on some hosts: a fresh worker blocks acquiring the loader
2254
- * lock that the init thread still owns. napi-rs only materializes its runtime
2255
- * on the first async call (`RT` is a `LazyLock`) and
2256
- * `create_custom_tokio_runtime` merely records the runtime in a `OnceLock`, so
2257
- * installing it post-load is still honored.
2258
- *
2259
- * Without the Tokio override napi builds its own default (one worker per CPU,
2260
- * spawned eagerly), which aborts the process (`os error 1455`) on a
2261
- * memory-constrained Windows host before any JS error can surface;
2262
- * [`create_windows_napi_tokio_runtime`] pre-flights the spawn instead. Rayon
2263
- * has the same one-thread-per-core lazy default, so [`configure_rayon_pool`]
2264
- * installs a probed global pool before `count_tokens` or vendored `sort` can
2265
- * trigger it across a N-API nounwind boundary. If no worker thread is
2266
- * spawnable, patched Rayon callsites stay sequential rather than registering a
2267
- * current-thread-only global pool that cannot steal work from later native
2268
- * calls. Idempotent.
2269
- */
2270
- export declare function __ompInstallTokioRuntime(): void
2271
-
2272
- /**
2273
- * Apply ast-grep rewrite rules to matching files; honors `dryRun` and returns
2274
- * a promise.
2275
- */
2276
- export declare function astEdit(options: AstReplaceOptions): Promise<AstReplaceResult>
2277
-
2278
- /** One ast-grep match with source range and optional meta-variables. */
2279
- export interface AstFindMatch {
2280
- /** Display path of the matching file. */
2281
- path: string
2282
- /** Matched source text. */
2283
- text: string
2284
- /** Start byte offset in the file (UTF-8 byte index). */
2285
- byteStart: number
2286
- /** End byte offset in the file (exclusive UTF-8 byte index). */
2287
- byteEnd: number
2288
- /** 1-based start line. */
2289
- startLine: number
2290
- /** 1-based start column. */
2291
- startColumn: number
2292
- /** 1-based end line. */
2293
- endLine: number
2294
- /** 1-based end column. */
2295
- endColumn: number
2296
- /** Meta-variable name to captured text, when `includeMeta` was enabled. */
2297
- metaVariables?: Record<string, string>
2298
- }
2299
-
2300
- /** Options for `astGrep`: patterns, scan scope, and match limits. */
2301
- export interface AstFindOptions {
2302
- /** ast-grep patterns to search for (OR across patterns). */
2303
- patterns?: Array<string>
2304
- /** Language override; otherwise inferred from file extension per candidate. */
2305
- lang?: string
2306
- /** Single file or directory to scan (combined with `glob` when set). */
2307
- path?: string
2308
- /** Optional glob filter relative to the search root. */
2309
- glob?: string
2310
- /** Rule selector for multi-rule ast-grep configurations. */
2311
- selector?: string
2312
- /** Pattern strictness; defaults to smart matching when omitted. */
2313
- strictness?: AstMatchStrictness
2314
- /** Maximum matches to return after `offset` (default applies when omitted). */
2315
- limit?: number
2316
- /** Number of leading matches to skip before applying `limit`. */
2317
- offset?: number
2318
- /** When true, include meta-variable bindings per match. */
2319
- includeMeta?: boolean
2320
- /**
2321
- * Reserved for contextual snippets; not used by the current native find
2322
- * path.
2323
- */
2324
- context?: number
2325
- /** Optional cancellation handle (library-specific). */
2326
- signal?: unknown
2327
- /** Wall-clock timeout for the worker task in milliseconds. */
2328
- timeoutMs?: number
2329
- }
2330
-
2331
- /** Aggregated search statistics and any parse or compile diagnostics. */
2332
- export interface AstFindResult {
2333
- /** Page of matches after sort, offset, and limit. */
2334
- matches: Array<AstFindMatch>
2335
- /** Total matches found before paging (can exceed `matches.length`). */
2336
- totalMatches: number
2337
- /** Distinct files that contained at least one match. */
2338
- filesWithMatches: number
2339
- /** Files examined for the query. */
2340
- filesSearched: number
2341
- /** True when results were truncated by `limit`. */
2342
- limitReached: boolean
2343
- /** Non-fatal parse or pattern errors collected during the run. */
2344
- parseErrors?: Array<string>
2345
- }
2346
-
2347
- /**
2348
- * Search source files with ast-grep patterns; returns a promise resolved on a
2349
- * worker thread.
2350
- */
2351
- export declare function astGrep(options: AstFindOptions): Promise<AstFindResult>
2352
-
2353
- /**
2354
- * Match ast-grep patterns against an in-memory source string; returns a
2355
- * promise resolved on a worker thread.
2356
- *
2357
- * This is the file-free counterpart to [`ast_grep`]: callers that already hold
2358
- * the source (streaming buffers, generated code, editor contents) avoid a
2359
- * temp-file round trip. `lang` is required since there is no path to infer it
2360
- * from.
2361
- */
2362
- export declare function astMatch(options: AstMatchOptions): Promise<AstMatchResult>
2363
-
2364
- /**
2365
- * Options for `astMatch`: run ast-grep patterns against an in-memory source
2366
- * string instead of files on disk.
2367
- */
2368
- export interface AstMatchOptions {
2369
- /** Source code to match against (parsed in memory, never read from disk). */
2370
- source: string
2371
- /** Language of `source` (required; e.g. "ts", "tsx", "rust", "python"). */
2372
- lang: string
2373
- /** ast-grep patterns to search for (OR across patterns). */
2374
- patterns: Array<string>
2375
- /** Rule selector for multi-rule ast-grep configurations. */
2376
- selector?: string
2377
- /** Pattern strictness; defaults to smart matching when omitted. */
2378
- strictness?: AstMatchStrictness
2379
- /** Maximum matches to return after `offset` (default applies when omitted). */
2380
- limit?: number
2381
- /** Number of leading matches to skip before applying `limit`. */
2382
- offset?: number
2383
- /** When true, include meta-variable bindings per match. */
2384
- includeMeta?: boolean
2385
- /** Optional cancellation handle (library-specific). */
2386
- signal?: unknown
2387
- /** Wall-clock timeout for the worker task in milliseconds. */
2388
- timeoutMs?: number
2389
- }
2390
-
2391
- /** Result of an in-memory `astMatch` run. */
2392
- export interface AstMatchResult {
2393
- /** Page of matches after sort, offset, and limit. */
2394
- matches: Array<AstFindMatch>
2395
- /** Total matches found before paging (can exceed `matches.length`). */
2396
- totalMatches: number
2397
- /** True when results were truncated by `limit`. */
2398
- limitReached: boolean
2399
- /** Non-fatal parse or pattern-compile errors collected during the run. */
2400
- parseErrors?: Array<string>
2401
- }
2402
-
2403
- /** ast-grep pattern strictness (controls how patterns match syntax). */
2404
- export declare enum AstMatchStrictness {
2405
- /** Match at the concrete syntax tree level. */
2406
- Cst = 'cst',
2407
- /** Balanced default suitable for most searches. */
2408
- Smart = 'smart',
2409
- /** Match at the AST level. */
2410
- Ast = 'ast',
2411
- /** More permissive matching. */
2412
- Relaxed = 'relaxed',
2413
- /** Match structural signatures. */
2414
- Signature = 'signature',
2415
- /** Template-style pattern matching. */
2416
- Template = 'template'
2417
- }
2418
-
2419
- /**
2420
- * One textual replacement applied to a file (before/after slice and
2421
- * coordinates).
2422
- */
2423
- export interface AstReplaceChange {
2424
- /** File path for this change. */
2425
- path: string
2426
- /** Original matched text. */
2427
- before: string
2428
- /** Replacement text. */
2429
- after: string
2430
- /** Start byte offset of the replaced span. */
2431
- byteStart: number
2432
- /** End byte offset of the replaced span (exclusive). */
2433
- byteEnd: number
2434
- /**
2435
- * Length of deleted text in bytes (may differ from `byteEnd - byteStart`
2436
- * for edge cases).
2437
- */
2438
- deletedLength: number
2439
- /** 1-based start line of the match. */
2440
- startLine: number
2441
- /** 1-based start column. */
2442
- startColumn: number
2443
- /** 1-based end line. */
2444
- endLine: number
2445
- /** 1-based end column. */
2446
- endColumn: number
2447
- }
2448
-
2449
- /** Per-file replacement count after an `astEdit` run. */
2450
- export interface AstReplaceFileChange {
2451
- /** File that had replacements. */
2452
- path: string
2453
- /** Number of replacements in that file. */
2454
- count: number
2455
- }
2456
-
2457
- /**
2458
- * Options for `astEdit`: rewrite rules, scan scope, safety limits, and
2459
- * dry-run.
2460
- */
2461
- export interface AstReplaceOptions {
2462
- /** Map of pattern string to replacement template. */
2463
- rewrites?: Record<string, string>
2464
- /**
2465
- * Language override applied to every file; otherwise inferred per file, so
2466
- * mixed-language paths rewrite each file in its own language.
2467
- */
2468
- lang?: string
2469
- /** Single file or directory to rewrite. */
2470
- path?: string
2471
- /** Optional glob filter within the search root. */
2472
- glob?: string
2473
- /** Rule selector for multi-rule configurations. */
2474
- selector?: string
2475
- /** Pattern strictness for rewrites. */
2476
- strictness?: AstMatchStrictness
2477
- /** When true (default), compute changes without writing files. */
2478
- dryRun?: boolean
2479
- /** Cap on replacement applications across all files. */
2480
- maxReplacements?: number
2481
- /** Cap on distinct files that may be modified. */
2482
- maxFiles?: number
2483
- /** Fail the operation when a file cannot be parsed for rewriting. */
2484
- failOnParseError?: boolean
2485
- /** Optional cancellation handle. */
2486
- signal?: unknown
2487
- /** Wall-clock timeout for the worker task in milliseconds. */
2488
- timeoutMs?: number
2489
- }
2490
-
2491
- /** Summary of an ast-grep rewrite pass, including whether disk writes occurred. */
2492
- export interface AstReplaceResult {
2493
- /** Individual replacement records (may be large). */
2494
- changes: Array<AstReplaceChange>
2495
- /** Replacement counts grouped by file. */
2496
- fileChanges: Array<AstReplaceFileChange>
2497
- /** Total replacements applied or previewed. */
2498
- totalReplacements: number
2499
- /** Files that had at least one replacement. */
2500
- filesTouched: number
2501
- /** Files considered for rewriting. */
2502
- filesSearched: number
2503
- /** False when `dryRun` prevented writing. */
2504
- applied: boolean
2505
- /** True when limits stopped further replacements. */
2506
- limitReached: boolean
2507
- /** Parse or pattern errors when not failing the whole operation. */
2508
- parseErrors?: Array<string>
2509
- }
2510
-
2511
- export interface AxNode {
2512
- ref: string
2513
- role: string
2514
- nativeRole: string
2515
- title?: string
2516
- value?: string
2517
- description?: string
2518
- enabled: boolean
2519
- focused: boolean
2520
- x?: number
2521
- y?: number
2522
- width?: number
2523
- height?: number
2524
- actions?: Array<string>
2525
- childCount: number
2526
- }
2527
-
2528
- export interface AxQuery {
2529
- role?: string
2530
- title?: string
2531
- value?: string
2532
- limit?: number
2533
- }
2534
-
2535
- export interface AxSnapshot {
2536
- text: string
2537
- nodeCount: number
2538
- truncated: boolean
2539
- }
2540
-
2541
- export interface AxSnapshotOptions {
2542
- maxDepth?: number
2543
- maxNodes?: number
2544
- all?: boolean
2545
- }
2546
-
2547
- export interface BlockRange {
2548
- /** 1-indexed inclusive first line of the resolved block. */
2549
- startLine: number
2550
- /** 1-indexed inclusive last line of the resolved block. */
2551
- endLine: number
2552
- }
2553
-
2554
- /**
2555
- * Find the outermost named tree-sitter node that begins on `options.line`.
2556
- *
2557
- * Returns its 1-indexed inclusive line span, or `null` when the language is
2558
- * unrecognized, the line is out of range / blank, no node begins on that line,
2559
- * or the resolved subtree contains a syntax error.
2560
- */
2561
- export declare function blockRangeAt(options: BlockRangeOptions): BlockRange | null
2562
-
2563
- export interface BlockRangeOptions {
2564
- /** Source code to inspect. */
2565
- code: string
2566
- /** Language alias (e.g. "rust", "typescript") used before path inference. */
2567
- lang?: string
2568
- /** File path used to infer language by extension when `lang` is omitted. */
2569
- path?: string
2570
- /** 1-indexed source line the block must begin on. */
2571
- line: number
2572
- }
2573
-
2574
- export interface CaptureCaps {
2575
- maxWidth?: number
2576
- maxHeight?: number
2577
- }
2578
-
2579
- /** Clipboard image payload encoded as PNG bytes. */
2580
- export interface ClipboardImage {
2581
- /** PNG-encoded image bytes. */
2582
- data: Uint8Array
2583
- /** MIME type for the encoded image payload. */
2584
- mimeType: string
2585
- }
2586
-
2587
- /** A context line (before or after a match). */
2588
- export interface ContextLine {
2589
- /** 1-indexed line number in the source file. */
2590
- lineNumber: number
2591
- /** Raw line content (trimmed line ending). */
2592
- line: string
2593
- }
2594
-
2595
- /**
2596
- * Copy plain text to the system clipboard.
2597
- *
2598
- * # Parameters
2599
- * - `text`: UTF-8 text to place on the clipboard.
2600
- *
2601
- * # Errors
2602
- * Returns an error if clipboard access fails.
2603
- */
2604
- export declare function copyToClipboard(text: string): void
2605
-
2606
- /**
2607
- * All pairs `(i, j)` with `i < j` whose cosine similarity meets `threshold`.
2608
- *
2609
- * `vectors` is `count` vectors flattened row-major at `dim` `f64` elements
2610
- * per row (zero-padded, which matches the TS `?? 0` missing-element
2611
- * semantics), so the similarity is bit-identical to the TS pairwise loop in
2612
- * `clusterBySimilarity`. Returns pairs flattened as `[i0, j0, i1, j1, ...]`
2613
- * in the same `(i, j)` visit order as the TS nested loop.
2614
- */
2615
- export declare function cosineSimilarityPairs(vectors: Float64Array, count: number, dim: number, threshold: number): Uint32Array
2616
-
2617
- /**
2618
- * Count tokens in `input`.
2619
- *
2620
- * `input` may be a single string or an array of strings; an array returns
2621
- * the sum across all elements (encoded in parallel via rayon when the global
2622
- * pool is available). Always returns a single token total — use this for any
2623
- * aggregate budget question without paying a per-element napi crossing.
2624
- *
2625
- * Uses ordinary encoding (no special-token handling), which is the right
2626
- * choice for measuring user/model content rather than wire-protocol tokens.
2627
- * Defaults to `o200k_base`; pass `Cl100kBase` for older `OpenAI` models.
2628
- */
2629
- export declare function countTokens(input: string | Array<string>, encoding?: Encoding | undefined | null): number
2630
-
2631
- export interface DesktopCapabilities {
2632
- backend: string
2633
- displayServer?: string
2634
- capture: boolean
2635
- input: boolean
2636
- ax: boolean
2637
- backgroundWindowInput: boolean
2638
- deliveryModes: Array<string>
2639
- capturePermission: string
2640
- inputPermission: string
2641
- axPermission: string
2642
- displayCount: number
2643
- }
2644
-
2645
- export interface DesktopCapture {
2646
- data: Uint8Array
2647
- width: number
2648
- height: number
2649
- /** Pre-scaling capture width in native pixels; equals `width` when unscaled. */
2650
- sourceWidth: number
2651
- /**
2652
- * Pre-scaling capture height in native pixels; equals `height` when
2653
- * unscaled.
2654
- */
2655
- sourceHeight: number
2656
- target: string
2657
- displays: Array<DesktopDisplay>
2658
- backend: string
2659
- displayServer?: string
2660
- }
2661
-
2662
- /**
2663
- * Monitor geometry in both global logical desktop coordinates and composite
2664
- * screenshot pixels.
2665
- */
2666
- export interface DesktopDisplay {
2667
- id: string
2668
- name: string
2669
- x: number
2670
- y: number
2671
- width: number
2672
- height: number
2673
- scale: number
2674
- pixelX: number
2675
- pixelY: number
2676
- pixelWidth: number
2677
- pixelHeight: number
2678
- isPrimary: boolean
2679
- }
2680
-
2681
- export interface DesktopPoint {
2682
- x: number
2683
- y: number
2684
- }
2685
-
2686
- export interface DesktopSessionOptions {
2687
- display?: string
2688
- }
2689
-
2690
- /** One capturable top-level window in global logical desktop coordinates. */
2691
- export interface DesktopWindow {
2692
- /**
2693
- * Backend-defined opaque window id, valid as a capture target while the
2694
- * window lives. Numeric on X11/Win32/macOS; a composite AT-SPI string on
2695
- * Wayland (e.g. `atspi::1.31:/org/a11y/atspi/accessible/1`). Never parse
2696
- * it.
2697
- */
2698
- id: string
2699
- /** Window title; may be empty for untitled windows. */
2700
- title: string
2701
- /** Owning application name. */
2702
- app: string
2703
- /** Owning process id when the platform exposes it. */
2704
- pid?: number
2705
- x: number
2706
- y: number
2707
- width: number
2708
- height: number
2709
- /** Whether the window currently holds input focus. */
2710
- focused: boolean
2711
- }
2712
-
2713
- /**
2714
- * Detect macOS system appearance via CoreFoundation.
2715
- * Returns `"dark"` or `"light"` on macOS, `null` on other platforms.
2716
- */
2717
- export declare function detectMacOSAppearance(): MacOSAppearance | null
2718
-
2719
- /**
2720
- * Generate an Apple `DeviceCheck` attestation token.
2721
- *
2722
- * Resolves with the token (or the error reason) after at most a 1-second
2723
- * wait, matching the upstream `devicecheck.node` addon contract.
2724
- */
2725
- export declare function deviceCheckGenerateToken(): Promise<DeviceCheckTokenResult>
2726
-
2727
- /** Outcome of a single `DCDevice.generateToken` request. */
2728
- export interface DeviceCheckTokenResult {
2729
- /** Whether `DCDevice.isSupported` reported attestation support. */
2730
- supported: boolean
2731
- /**
2732
- * Base64-encoded `DeviceCheck` token; present only when generation
2733
- * succeeded.
2734
- */
2735
- tokenBase64?: string
2736
- /** Human-readable failure reason when no token was produced. */
2737
- error?: string
2738
- /** Wall-clock time spent in the native call, in milliseconds. */
2739
- latencyMs: number
2740
- }
2741
-
2742
- /** One jsdiff change object: a run of added, removed, or common tokens. */
2743
- export interface DiffChange {
2744
- /** Joined token text for this run (lines keep their `
2745
- ` terminators). */
2746
- value: string
2747
- /** Number of tokens in this run. */
2748
- count: number
2749
- /** True when this run exists only in the new text. */
2750
- added: boolean
2751
- /** True when this run exists only in the old text. */
2752
- removed: boolean
2753
- }
2754
-
2755
- /**
2756
- * Diff `oldText.split("
2757
- ")` against `newText.split("
2758
- ")` with jsdiff
2759
- * `diffArrays` semantics (exact code-unit equality, empty lines preserved),
2760
- * returning only run lengths.
2761
- *
2762
- * Callers that map line numbers — like hashline recovery — need the counts,
2763
- * not another copy of the text.
2764
- */
2765
- export declare function diffLineRuns(oldText: string, newText: string): Array<DiffRun>
2766
-
2767
- /**
2768
- * Line diff with jsdiff `diffLines(oldText, newText)` semantics (default
2769
- * options). Change values keep line terminators, and common runs are joined
2770
- * from the new text.
2771
- */
2772
- export declare function diffLines(oldText: string, newText: string): Array<DiffChange>
2773
-
2774
- /** A change run without its token text, for callers that only need counts. */
2775
- export interface DiffRun {
2776
- /** Number of tokens in this run. */
2777
- count: number
2778
- /** True when this run exists only in the new text. */
2779
- added: boolean
2780
- /** True when this run exists only in the old text. */
2781
- removed: boolean
2782
- }
2783
-
2784
- /**
2785
- * Word diff with jsdiff `diffWords(oldText, newText)` semantics (default
2786
- * options).
2787
- *
2788
- * Tokens carry surrounding whitespace, equality ignores it, and the
2789
- * post-pass dedupes whitespace across change boundaries.
2790
- */
2791
- export declare function diffWords(oldText: string, newText: string): Array<DiffChange>
2792
-
2793
- /** Ellipsis strategy for [`truncate_to_width`]. */
2794
- export declare enum Ellipsis {
2795
- /** Use a single Unicode ellipsis character ("…"). */
2796
- Unicode = 0,
2797
- /** Use three ASCII dots ("..."). */
2798
- Ascii = 1,
2799
- /** Omit ellipsis entirely. */
2800
- Omit = 2
2801
- }
2802
-
2803
- /**
2804
- * Matching-bracket context for an arbitrary tree-sitter language.
2805
- *
2806
- * For each multi-line named node whose span crosses the visible window, return
2807
- * the boundary line sitting *outside* that window (the closer when the opener
2808
- * is shown, the opener when the closer is shown). Covers brace and indentation
2809
- * languages alike using real syntactic spans.
2810
- *
2811
- * Returns `null` when the language is unrecognized or the source fails to
2812
- * parse / carries a syntax error (caller should fall back to a lexical scan);
2813
- * a sorted, unique list of 1-indexed boundary lines otherwise.
2814
- */
2815
- export declare function enclosingBlockBoundaries(options: EnclosingBoundaryOptions): Array<number> | null
2816
-
2817
- export interface EnclosingBoundaryOptions {
2818
- /** Source code to inspect. */
2819
- code: string
2820
- /** Language alias (e.g. "rust", "typescript") used before path inference. */
2821
- lang?: string
2822
- /** File path used to infer language by extension when `lang` is omitted. */
2823
- path?: string
2824
- /** 1-indexed inclusive visible line ranges (the lines actually shown). */
2825
- ranges: Array<LineRange>
2826
- }
2827
-
2828
- /**
2829
- * Encode image bytes into a SIXEL escape sequence for terminal rendering.
2830
- *
2831
- * The input image is decoded and resized to the requested pixel dimensions
2832
- * before encoding.
2833
- *
2834
- * # Errors
2835
- * Returns an error if decoding, resizing, or SIXEL encoding fails.
2836
- */
2837
- export declare function encodeSixel(bytes: Uint8Array, targetWidthPx: number, targetHeightPx: number): string
2838
-
2839
- /** Tokenizer encoding to use. */
2840
- export declare enum Encoding {
2841
- /** GPT-4o / o1 / GPT-5 (default). */
2842
- O200kBase = 'O200kBase',
2843
- /** GPT-3.5 / GPT-4 / older. */
2844
- Cl100kBase = 'Cl100kBase'
2845
- }
2846
-
2847
- /**
2848
- * Execute a brush shell command.
2849
- *
2850
- * Creates a fresh session for each call. The `on_chunk` callback receives
2851
- * streamed stdout/stderr output. Returns the exit code when the command
2852
- * completes, or flags when cancelled or timed out.
2853
- */
2854
- export declare function executeShell(options: ShellExecuteOptions, onChunk?: ((error: Error | null, chunk: string) => void) | undefined | null): Promise<ShellRunResult>
2855
-
2856
- /**
2857
- * Extract the before/after slices around an overlay region.
2858
- *
2859
- * Preserves ANSI state so the `after` segment renders correctly after
2860
- * truncation.
2861
- */
2862
- export declare function extractSegments(line: string, beforeEnd: number, afterStart: number, afterLen: number, strictAfter: boolean, tabWidth: number): ExtractSegmentsResult
2863
-
2864
- /** Before/after UTF-16 segments around an overlay region, with measured widths. */
2865
- export interface ExtractSegmentsResult {
2866
- /** UTF-16 content before the overlay region. */
2867
- before: string
2868
- /** Visible width of the `before` segment. */
2869
- beforeWidth: number
2870
- /** UTF-16 content after the overlay region. */
2871
- after: string
2872
- /** Visible width of the `after` segment. */
2873
- afterWidth: number
2874
- }
2875
-
2876
- /** Resolved filesystem entry kind for glob filters and match metadata. */
2877
- export declare enum FileType {
2878
- /** Regular file. */
2879
- File = 1,
2880
- /** Directory. */
2881
- Dir = 2,
2882
- /** Symbolic link. */
2883
- Symlink = 3
2884
- }
2885
-
2886
- /** Fuzzy file path search for autocomplete. */
2887
- export declare function fuzzyFind(options: FuzzyFindOptions): Promise<FuzzyFindResult>
2888
-
2889
- /** A single match in fuzzy find results. */
2890
- export interface FuzzyFindMatch {
2891
- /** Relative path from the search root (uses `/` separators). */
2892
- path: string
2893
- /** Whether this entry is a directory. */
2894
- isDirectory: boolean
2895
- /** Match quality score (higher is better). */
2896
- score: number
2897
- }
2898
-
2899
- /** Options for fuzzy file path search. */
2900
- export interface FuzzyFindOptions {
2901
- /** Fuzzy query to match against file paths (case-insensitive). */
2902
- query: string
2903
- /** Directory to search. */
2904
- path: string
2905
- /** Include hidden files (default: false). */
2906
- hidden?: boolean
2907
- /** Respect .gitignore (default: true). */
2908
- gitignore?: boolean
2909
- /** Enable walker scan caching (default: false). */
2910
- cache?: boolean
2911
- /** Maximum number of matches to return (default: 100). */
2912
- maxResults?: number
2913
- /** Abort signal for cancelling the operation. */
2914
- signal?: unknown
2915
- /** Timeout in milliseconds for the operation. */
2916
- timeoutMs?: number
2917
- }
2918
-
2919
- /** Result of fuzzy file path search. */
2920
- export interface FuzzyFindResult {
2921
- /** Matched entries (up to `maxResults`). */
2922
- matches: Array<FuzzyFindMatch>
2923
- /** Total number of matches found (may exceed `matches.len()`). */
2924
- totalMatches: number
2925
- }
2926
-
2927
- /** Get list of supported languages. */
2928
- export declare function getSupportedLanguages(): Array<string>
2929
-
2930
- /**
2931
- * Get work profile data from the last N seconds.
2932
- *
2933
- * Always-on profiling - no need to start/stop. Just call this to get
2934
- * recent activity.
2935
- */
2936
- export declare function getWorkProfile(lastSeconds: number): WorkProfile
2937
-
2938
- /**
2939
- * Find filesystem entries matching a glob pattern.
2940
- *
2941
- * Resolves the search root, scans entries, applies glob and optional file-type
2942
- * filters, and optionally streams each accepted match through `on_match`.
2943
- *
2944
- * When `sortByMtime` is enabled, the walker ranks matches by mtime before the
2945
- * native layer applies final symlink-aware file-type filtering and callback
2946
- * emission.
2947
- *
2948
- * # Errors
2949
- * Returns an error when the search path cannot be resolved, the path is not a
2950
- * directory, the glob pattern is invalid, or cancellation/timeout is
2951
- * triggered.
2952
- */
2953
- export declare function glob(options: GlobOptions, onMatch?: ((error: Error | null, match: GlobMatch) => void) | undefined | null): Promise<GlobResult>
2954
-
2955
- /** A single filesystem entry from a directory scan. */
2956
- export interface GlobMatch {
2957
- /** Relative path from the search root, using forward slashes. */
2958
- path: string
2959
- /** Resolved filesystem type for the match. */
2960
- fileType: FileType
2961
- /** Modification time in milliseconds since Unix epoch. */
2962
- mtime?: number
2963
- /** File size in bytes for regular files. */
2964
- size?: number
2965
- }
2966
-
2967
- /** Input options for `glob`, including traversal, filtering, and cancellation. */
2968
- export interface GlobOptions {
2969
- /** Glob pattern to match (e.g., "*.ts"). */
2970
- pattern: string
2971
- /** Directory to search. */
2972
- path: string
2973
- /**
2974
- * Filter by file type: "file", "dir", or "symlink". Symlinks are
2975
- * matched for file/dir filters based on their target type.
2976
- */
2977
- fileType?: FileType
2978
- /** Match simple patterns recursively by default (`*.ts` -> recursive). */
2979
- recursive?: boolean
2980
- /** Include hidden files (default: false). */
2981
- hidden?: boolean
2982
- /** Maximum number of results to return. */
2983
- maxResults?: number
2984
- /** Respect .gitignore files (default: true). */
2985
- gitignore?: boolean
2986
- /** Enable walker scan caching (default: false). */
2987
- cache?: boolean
2988
- /** Sort results by mtime (most recent first) before applying limit. */
2989
- sortByMtime?: boolean
2990
- /**
2991
- * Include `node_modules` entries when the pattern does not explicitly
2992
- * mention them.
2993
- */
2994
- includeNodeModules?: boolean
2995
- /** Abort signal for cancelling the operation. */
2996
- signal?: unknown
2997
- /** Timeout in milliseconds for the operation. */
2998
- timeoutMs?: number
2999
- }
3000
-
3001
- /** Result payload returned by a glob operation. */
3002
- export interface GlobResult {
3003
- /** Matched filesystem entries. */
3004
- matches: Array<GlobMatch>
3005
- /** Number of returned matches (`matches.len()`), clamped to `u32::MAX`. */
3006
- totalMatches: number
3007
- }
3008
-
3009
- /**
3010
- * Search files for a regex pattern.
3011
- *
3012
- * # Arguments
3013
- * - `options`: Pattern, path, filters, and output mode.
3014
- * - `on_match`: Optional callback invoked per match/result.
3015
- *
3016
- * # Returns
3017
- * Aggregated results across matching files.
3018
- */
3019
- export declare function grep(options: GrepOptions, onMatch?: ((error: Error | null, match: GrepMatch) => void) | undefined | null): Promise<GrepResult>
3020
-
3021
- /** A single match in a grep result. */
3022
- export interface GrepMatch {
3023
- /** File path for the match (relative for directory searches). */
3024
- path: string
3025
- /** 1-indexed line number (0 for count-only entries). */
3026
- lineNumber: number
3027
- /** The matched line content (empty for count-only entries). */
3028
- line: string
3029
- /** Context lines before the match. */
3030
- contextBefore?: Array<ContextLine>
3031
- /** Context lines after the match. */
3032
- contextAfter?: Array<ContextLine>
3033
- /** Whether the line was truncated. */
3034
- truncated?: boolean
3035
- /** Per-file match count (count mode only). */
3036
- matchCount?: number
3037
- }
3038
-
3039
- /** Options for searching files on disk. */
3040
- export interface GrepOptions {
3041
- /** Regex pattern to search for. */
3042
- pattern: string
3043
- /** Directory or file to search. */
3044
- path: string
3045
- /** Glob filter for filenames (e.g., "*.ts"). */
3046
- glob?: string
3047
- /** Filter by file type (e.g., "js", "py", "rust"). */
3048
- type?: string
3049
- /** Case-insensitive search. */
3050
- ignoreCase?: boolean
3051
- /** Enable multiline matching. */
3052
- multiline?: boolean
3053
- /** Include hidden files (default: true). */
3054
- hidden?: boolean
3055
- /** Respect .gitignore files (default: true). */
3056
- gitignore?: boolean
3057
- /** Maximum number of matches to return. */
3058
- maxCount?: number
3059
- /** Skip first N matches. */
3060
- offset?: number
3061
- /** Lines of context before matches. */
3062
- contextBefore?: number
3063
- /** Lines of context after matches. */
3064
- contextAfter?: number
3065
- /** Lines of context before/after matches (legacy). */
3066
- context?: number
3067
- /** Truncate lines longer than this (characters). */
3068
- maxColumns?: number
3069
- /** Output mode (content, filesWithMatches, or count). */
3070
- mode?: GrepOutputMode
3071
- /**
3072
- * Maximum matches collected per file (content mode). Keeps one hot file
3073
- * from exhausting the global `max_count` budget before other files are
3074
- * reached.
3075
- */
3076
- maxCountPerFile?: number
3077
- /** Abort signal for cancelling the operation. */
3078
- signal?: unknown
3079
- /** Timeout in milliseconds for the operation. */
3080
- timeoutMs?: number
3081
- }
3082
-
3083
- /** Output mode for [`search`] and [`grep`] (string values match JS callers). */
3084
- export declare enum GrepOutputMode {
3085
- /** Emit matched lines (and optional context lines). */
3086
- Content = 'content',
3087
- /** Emit per-file or total counts instead of line content. */
3088
- Count = 'count',
3089
- /** Emit one row per file that matched, without line content. */
3090
- FilesWithMatches = 'filesWithMatches'
3091
- }
3092
-
3093
- /** Result of searching files. */
3094
- export interface GrepResult {
3095
- /** Matches or per-file counts, depending on output mode. */
3096
- matches: Array<GrepMatch>
3097
- /**
3098
- * Total matches across all files, or matched file count in filesWithMatches
3099
- * mode.
3100
- */
3101
- totalMatches: number
3102
- /** Number of files with at least one match. */
3103
- filesWithMatches: number
3104
- /** Number of files searched. */
3105
- filesSearched: number
3106
- /** Whether the limit/offset stopped the search early. */
3107
- limitReached?: boolean
3108
- /** Number of files skipped because they exceed the size limit. */
3109
- skippedOversized?: number
3110
- }
3111
-
3112
- /**
3113
- * Quick check if content matches a pattern.
3114
- *
3115
- * # Arguments
3116
- * - `content`: `Uint8Array`/`Buffer` (zero-copy) or `string` (UTF-8).
3117
- * - `pattern`: `Uint8Array`/`Buffer` (zero-copy) or `string` (UTF-8).
3118
- * - `ignore_case`: Case-insensitive matching.
3119
- * - `multiline`: Enable multiline regex mode.
3120
- *
3121
- * # Returns
3122
- * True if any match exists; false on no match.
3123
- */
3124
- export declare function hasMatch(content: string | Uint8Array, pattern: string | Uint8Array, ignoreCase?: boolean | undefined | null, multiline?: boolean | undefined | null): boolean
3125
-
3126
- /**
3127
- * Highlight code and return ANSI-colored lines.
3128
- *
3129
- * # Arguments
3130
- * * `code` - The source code to highlight
3131
- * * `lang` - Language identifier (e.g., "rust", "typescript", "python")
3132
- * * `colors` - Theme colors as ANSI escape sequences
3133
- *
3134
- * # Returns
3135
- * Highlighted code with ANSI color codes, or the original code if highlighting
3136
- * fails.
3137
- */
3138
- export declare function highlightCode(code: string, lang: string | undefined | null, colors: HighlightColors): string
3139
-
3140
- /**
3141
- * Theme colors for syntax highlighting.
3142
- * Each color is an ANSI escape sequence (e.g., "\x1b[38;2;255;0;0m").
3143
- */
3144
- export interface HighlightColors {
3145
- /** ANSI color for comments. */
3146
- comment: string
3147
- /** ANSI color for keywords. */
3148
- keyword: string
3149
- /** ANSI color for function names. */
3150
- function: string
3151
- /** ANSI color for variables and identifiers. */
3152
- variable: string
3153
- /** ANSI color for string literals. */
3154
- string: string
3155
- /** ANSI color for numeric literals. */
3156
- number: string
3157
- /** ANSI color for type identifiers. */
3158
- type: string
3159
- /** ANSI color for operators. */
3160
- operator: string
3161
- /** ANSI color for punctuation tokens. */
3162
- punctuation: string
3163
- /** ANSI color for diff inserted lines. */
3164
- inserted?: string
3165
- /** ANSI color for diff deleted lines. */
3166
- deleted?: string
3167
- }
3168
-
3169
- /**
3170
- * Convert HTML source to Markdown with optional preprocessing.
3171
- *
3172
- * # Errors
3173
- * Returns an error if the conversion fails or the worker task aborts.
3174
- */
3175
- export declare function htmlToMarkdown(html: string, options?: HtmlToMarkdownOptions | undefined | null): Promise<string>
3176
-
3177
- /** Options for HTML to Markdown conversion. */
3178
- export interface HtmlToMarkdownOptions {
3179
- /** Remove navigation elements, forms, headers, footers. */
3180
- cleanContent?: boolean
3181
- /** Skip images during conversion. */
3182
- skipImages?: boolean
3183
- }
3184
-
3185
- /**
3186
- * Invalidate the walker scan cache.
3187
- *
3188
- * When called with a path, removes entries for roots containing that path.
3189
- * When called without a path, clears the entire cache.
3190
- *
3191
- * Intended to be called after agent file mutations: write, edit, rename, or
3192
- * delete.
3193
- */
3194
- export declare function invalidateFsScanCache(path?: string | undefined | null): void
3195
-
3196
- /** Kind enum of the backend selected by default for this build target. */
3197
- export declare function isoBackend(): IsoBackendKind
3198
-
3199
- /**
3200
- * Isolation backend identifier. Numeric so the JS side can `switch` on
3201
- * the enum without string comparisons.
3202
- */
3203
- export declare enum IsoBackendKind {
3204
- Apfs = 0,
3205
- Btrfs = 1,
3206
- Zfs = 2,
3207
- LinuxReflink = 3,
3208
- Overlayfs = 4,
3209
- WindowsBlockClone = 5,
3210
- Projfs = 6,
3211
- Rcopy = 7
3212
- }
3213
-
3214
- /** How a single file changed between `lower` and `merged`. */
3215
- export declare enum IsoChangeKind {
3216
- Added = 0,
3217
- Modified = 1,
3218
- Removed = 2
3219
- }
3220
-
3221
- /**
3222
- * Capture the changes between `lower` and `merged`.
3223
- *
3224
- * Uses [`pi_iso::IsolationBackend::diff`]'s default implementation —
3225
- * `git diff` when `merged/.git` exists, otherwise a mtime-skipped tree
3226
- * walk. The backend selection only affects the lifecycle methods; diff
3227
- * behaviour is uniform.
3228
- */
3229
- export declare function isoDiff(lower: string, merged: string): Promise<IsoDiff>
3230
-
3231
- export interface IsoDiff {
3232
- files: Array<IsoFileChange>
3233
- }
3234
-
3235
- /** One entry in an [`IsoDiff`]. */
3236
- export interface IsoFileChange {
3237
- /** Path relative to `merged`. */
3238
- path: string
3239
- op: IsoChangeKind
3240
- /**
3241
- * Unified-diff text. `None` (`null` in JS) means the file is binary;
3242
- * read it directly from `merged` if you need the bytes.
3243
- */
3244
- diff?: string
3245
- }
3246
-
3247
- /**
3248
- * True if `message` is an error message produced by [`IsoError::Unavailable`].
3249
- * Use this to distinguish "this backend isn't installed" from a hard
3250
- * failure when handling caught errors on the JS side.
3251
- */
3252
- export declare function isoIsUnavailableError(message: string): boolean
3253
-
3254
- /**
3255
- * Probe whether the requested backend can start on this host. Pass
3256
- * `null`/omit `kind` to probe the platform-native backend.
3257
- */
3258
- export declare function isoProbe(kind?: IsoBackendKind | undefined | null): IsoProbeResult
3259
-
3260
- /** Probe result for a specific isolation backend. */
3261
- export interface IsoProbeResult {
3262
- /** True when the backend's prerequisites are satisfied. */
3263
- available: boolean
3264
- /** Human-readable explanation when `available` is false. */
3265
- reason?: string
3266
- /** Resolved backend kind. */
3267
- kind: IsoBackendKind
3268
- }
3269
-
3270
- /**
3271
- * Pick the best backend available right now. `preferred` is treated as
3272
- * a hint — see [`pi_iso::resolve`] for the exact priority rules.
3273
- */
3274
- export declare function isoResolve(preferred?: IsoBackendKind | undefined | null): IsoResolveResult
3275
-
3276
- /** Outcome of [`iso_resolve`]. */
3277
- export interface IsoResolveResult {
3278
- /** Backend that will actually be tried first. */
3279
- kind: IsoBackendKind
3280
- /** Host-available backends in retry order, starting with `kind`. */
3281
- candidates: Array<IsoBackendKind>
3282
- /**
3283
- * True when the resolver fell back from `preferred` (or from the
3284
- * first automatic candidate) to a different backend.
3285
- */
3286
- fellBack: boolean
3287
- /** Human-readable reason for the fallback, if any. */
3288
- reason?: string
3289
- }
3290
-
3291
- /**
3292
- * Materialise `merged` as a writable view of `lower` using the requested
3293
- * backend. `kind` defaults to the native backend.
3294
- */
3295
- export declare function isoStart(kind: IsoBackendKind | undefined | null, lower: string, merged: string): Promise<void>
3296
-
3297
- /** Tear down a previously started backend at `merged`. */
3298
- export declare function isoStop(kind: IsoBackendKind | undefined | null, merged: string): Promise<void>
3299
-
3300
- /** Event types from Kitty keyboard protocol (flag 2). */
3301
- export declare enum KeyEventType {
3302
- /** Key press event. */
3303
- Press = 1,
3304
- /** Key repeat event. */
3305
- Repeat = 2,
3306
- /** Key release event. */
3307
- Release = 3
3308
- }
3309
-
3310
- export interface LineRange {
3311
- /** 1-indexed inclusive first visible line. */
3312
- startLine: number
3313
- /** 1-indexed inclusive last visible line. */
3314
- endLine: number
3315
- }
3316
-
3317
- /**
3318
- * Walk the workspace once and return tree entries plus AGENTS.md candidates.
3319
- *
3320
- * File-level ignore rules for AGENTS.md are bypassed by checking each
3321
- * traversed directory directly when `collectAgentsMd` is enabled, but ignored
3322
- * directories are still pruned by the walker and are not searched.
3323
- */
3324
- export declare function listWorkspace(options: ListWorkspaceOptions): Promise<ListWorkspaceResult>
3325
-
3326
- /** Input options for `listWorkspace`, the single-pass workspace startup scan. */
3327
- export interface ListWorkspaceOptions {
3328
- /** Directory to scan. */
3329
- path: string
3330
- /** Maximum depth for returned tree entries. Root children are depth 1. */
3331
- maxDepth: number
3332
- /** Include hidden files and directories. Default: false. */
3333
- hidden?: boolean
3334
- /** Respect .gitignore files. Default: true. */
3335
- gitignore?: boolean
3336
- /**
3337
- * Also surface AGENTS.md files in directories at depth 1..=4, even when
3338
- * gitignore would otherwise hide the file. Walks deeper than `maxDepth`
3339
- * to find them. Default: false.
3340
- */
3341
- collectAgentsMd?: boolean
3342
- /** Timeout in milliseconds for the operation. */
3343
- timeoutMs?: number
3344
- /** Abort signal for cancelling the operation. */
3345
- signal?: unknown
3346
- }
3347
-
3348
- /** Result payload returned by a workspace scan. */
3349
- export interface ListWorkspaceResult {
3350
- /** Entries within `maxDepth`, with mtime and regular-file size metadata. */
3351
- entries: Array<GlobMatch>
3352
- /**
3353
- * Directory-scoped AGENTS.md files within depth 1..=4 (capped at 200).
3354
- * Always empty when `collectAgentsMd` is false.
3355
- */
3356
- agentsMdFiles: Array<string>
3357
- /** True when any output cap was hit. */
3358
- truncated: boolean
3359
- }
3360
-
3361
- /**
3362
- * System UI appearance reported by native macOS APIs (`detectMacOSAppearance`
3363
- * and observer).
3364
- */
3365
- export declare enum MacOSAppearance {
3366
- /** Dark color scheme. */
3367
- Dark = 'dark',
3368
- /** Light color scheme. */
3369
- Light = 'light'
3370
- }
3371
-
3372
- /**
3373
- * Options for starting a macOS power assertion.
3374
- *
3375
- * Each boolean maps to a `caffeinate(8)` flag and a corresponding `IOKit`
3376
- * `IOPMAssertion` type. Multiple flags can be combined; when set, one
3377
- * assertion is taken per flag and all are released together when the
3378
- * handle is stopped or dropped.
3379
- *
3380
- * If every flag is unset (or omitted), the handle behaves as if `idle`
3381
- * were `true` — preserving the historical default of `caffeinate -i`.
3382
- */
3383
- export interface MacOSPowerAssertionOptions {
3384
- /** Human-readable reason shown in macOS power diagnostics. */
3385
- reason?: string
3386
- /** `caffeinate -i`: prevent the system from idle-sleeping. */
3387
- idle?: boolean
3388
- /** `caffeinate -s`: prevent the system from sleeping (AC power only). */
3389
- system?: boolean
3390
- /** `caffeinate -u`: declare the user is active (wakes the display). */
3391
- user?: boolean
3392
- /** `caffeinate -d`: prevent the display from idle-sleeping. */
3393
- display?: boolean
3394
- }
3395
-
3396
- /** A single match in the content. */
3397
- export interface Match {
3398
- /** 1-indexed line number. */
3399
- lineNumber: number
3400
- /** The matched line content. */
3401
- line: string
3402
- /** Context lines before the match. */
3403
- contextBefore?: Array<ContextLine>
3404
- /** Context lines after the match. */
3405
- contextAfter?: Array<ContextLine>
3406
- /** Whether the line was truncated. */
3407
- truncated?: boolean
3408
- }
3409
-
3410
- /**
3411
- * Match input data against a key identifier string.
3412
- *
3413
- * Returns true when the bytes represent the specified key with modifiers.
3414
- */
3415
- export declare function matchesKey(data: string, keyId: string, kittyProtocolActive: boolean): boolean
3416
-
3417
- /**
3418
- * Match Kitty protocol input against a codepoint and modifier mask.
3419
- *
3420
- * Returns true when the parsed sequence matches the expected codepoint (or
3421
- * base layout key) and modifier bits.
3422
- */
3423
- export declare function matchesKittySequence(data: string, expectedCodepoint: number, expectedModifier: number): boolean
3424
-
3425
- /**
3426
- * Check if input matches a legacy escape sequence for the given key name.
3427
- *
3428
- * Returns true only when the byte sequence maps to the exact key identifier.
3429
- */
3430
- export declare function matchesLegacySequence(data: string, keyName: string): boolean
3431
-
3432
- /** N-API opt-in handle for the minimizer. */
3433
- export interface MinimizerOptions {
3434
- /** Master switch. Absent / false = disabled. */
3435
- enabled?: boolean
3436
- /**
3437
- * Optional path to a TOML settings file whose values override
3438
- * field-level defaults. `~` is expanded.
3439
- */
3440
- settingsPath?: string
3441
- /**
3442
- * Optional xxHash64 digest (hex) of the settings file contents. When
3443
- * supplied, the engine refuses to honor a settings file whose hash does
3444
- * not match — a lightweight trust gate for agent-controllable paths.
3445
- */
3446
- settingsHash?: string
3447
- /**
3448
- * Opt-in allowlist of program names (e.g. `"git"`). When empty or
3449
- * absent, all built-in filters are active.
3450
- */
3451
- only?: Array<string>
3452
- /** Program names explicitly excluded from minimization. */
3453
- except?: Array<string>
3454
- /**
3455
- * Maximum captured bytes per command before the engine falls back to
3456
- * the raw, un-minimized output. Default 4 MiB.
3457
- */
3458
- maxCaptureBytes?: number
3459
- /**
3460
- * Source-outline level for `cat <source-file>` minimization. Accepts
3461
- * `"default"` (current behavior) or `"aggressive"` (strip function bodies).
3462
- */
3463
- sourceOutlineLevel?: string
3464
- /**
3465
- * Kill-switch to fall back to the pre-PR (legacy) filter behavior for
3466
- * grep / find / pytest. When `Some(true)`, filters that opted into the
3467
- * always-shrink Tier 1 / Tier 2 behavior skip the new code path. When
3468
- * `None`, defers to the `OMP_MINIMIZER_LEGACY_FILTERS` env var.
3469
- */
3470
- legacyFilters?: boolean
3471
- }
3472
-
3473
- /**
3474
- * Telemetry for a single minimization.
3475
- *
3476
- * Surfaced when the minimizer actually rewrote the command's output. The
3477
- * session layer is expected to persist `original_text` via its
3478
- * `ArtifactManager`, splice the resulting `artifact://<id>` reference
3479
- * into `text`, and replace any previously streamed raw output with the
3480
- * minimized text.
3481
- */
3482
- export interface MinimizerResult {
3483
- /**
3484
- * Dispatch label produced by the minimizer (e.g. `"git"`,
3485
- * `"pipeline:gradle"`, `"pipeline+builtin"`).
3486
- */
3487
- filter: string
3488
- /**
3489
- * The minimized replacement text. Callers that streamed raw chunks
3490
- * during execution should clear and replace their accumulated output
3491
- * with this text.
3492
- */
3493
- text: string
3494
- /** The full original capture, before minimization. */
3495
- originalText: string
3496
- /** Captured byte length before minimization. */
3497
- inputBytes: number
3498
- /** Byte length of the minimized text the consumer received. */
3499
- outputBytes: number
3500
- }
3501
-
3502
- /**
3503
- * MMR selection over pre-sorted candidates using Jaccard word similarity.
3504
- *
3505
- * `contents[i]` and `scores[i]` describe candidate `i`, already sorted by
3506
- * relevance exactly as the TS `mmrRerank` sorts them (the JS stable sort
3507
- * stays on the TS side so its tie and NaN semantics are preserved).
3508
- * Replicates the TS selection loop exactly: candidate `0` is always taken
3509
- * first; each round picks the remaining candidate maximizing
3510
- * `lambda * score - (1 - lambda) * maxSimilarity(selected)` with strict
3511
- * `>` comparisons, so ties keep the earliest remaining candidate — and a
3512
- * round where every score is `NaN` picks the first remaining candidate,
3513
- * matching the TS `bestIdx = 0` initialisation. Returns the selected
3514
- * indices into the input order.
3515
- *
3516
- * Word tokenization matches `text.toLowerCase().split(/\s+/)` (ECMA `\s`,
3517
- * Unicode default full case conversion). Known divergence: unpaired
3518
- * surrogates arrive here as U+FFFD, while JS keeps the lone surrogate; both
3519
- * tokenize to a single non-whitespace word so Jaccard counts still agree
3520
- * unless a text mixes U+FFFD words with lone-surrogate words.
3521
- */
3522
- export declare function mmrRerankIndices(contents: Array<string>, scores: Float64Array, lambdaParam: number, topK: number): Uint32Array
3523
-
3524
- /** Parsed Kitty keyboard protocol sequence result for a Kitty input sequence. */
3525
- export interface ParsedKittyResult {
3526
- /** Primary codepoint associated with the key. */
3527
- codepoint: number
3528
- /** Optional shifted key codepoint from the sequence. */
3529
- shiftedKey?: number
3530
- /** Optional base layout key codepoint from the sequence. */
3531
- baseLayoutKey?: number
3532
- /** Modifier bitmask (shift/alt/ctrl), excluding lock bits. */
3533
- modifier: number
3534
- /** Optional event type (1 = press, 2 = repeat, 3 = release). */
3535
- eventType?: KeyEventType
3536
- }
3537
-
3538
- /**
3539
- * Parse terminal input and return a normalized key identifier.
3540
- *
3541
- * Returns a key id like "escape" or "ctrl+c", or None if unrecognized.
3542
- */
3543
- export declare function parseKey(data: string, kittyProtocolActive: boolean): string | null
3544
-
3545
- /**
3546
- * Parse a Kitty keyboard protocol sequence.
3547
- *
3548
- * Returns a structured parse result when the input is a valid Kitty sequence.
3549
- */
3550
- export declare function parseKittySequence(data: string): ParsedKittyResult | null
3551
-
3552
- /** One hunk of a unified diff, matching jsdiff `structuredPatch` hunks. */
3553
- export interface PatchHunk {
3554
- /** 1-based first line of the hunk in the old text. */
3555
- oldStart: number
3556
- /** Number of old-text lines covered by the hunk. */
3557
- oldLines: number
3558
- /** 1-based first line of the hunk in the new text. */
3559
- newStart: number
3560
- /** Number of new-text lines covered by the hunk. */
3561
- newLines: number
3562
- /**
3563
- * Hunk body: `+`/`-`/` `-prefixed lines without trailing newlines, plus
3564
- * `` markers where applicable.
3565
- */
3566
- lines: Array<string>
3567
- }
3568
-
3569
- /** Markdown and inspection metadata produced from a PDF document. */
3570
- export interface PdfMarkdownResult {
3571
- /** Extracted document content in Markdown format. */
3572
- markdown: string
3573
- /** Document title from PDF metadata, when present. */
3574
- title?: string
3575
- /** Total number of pages in the document. */
3576
- pageCount: number
3577
- /** One-indexed page numbers whose content requires OCR. */
3578
- pagesNeedingOcr: Array<number>
3579
- /** Whether the document contains text encoding problems. */
3580
- hasEncodingIssues: boolean
3581
- }
3582
-
3583
- /**
3584
- * Convert an in-memory PDF to Markdown and return its inspection metadata.
3585
- *
3586
- * Conversion copies the typed array before dispatch so JavaScript mutation
3587
- * cannot race the native worker.
3588
- *
3589
- * # Errors
3590
- * Returns an error prefixed with `PDF conversion failed:` when the PDF cannot
3591
- * be parsed or converted.
3592
- */
3593
- export declare function pdfToMarkdown(input: Uint8Array): Promise<PdfMarkdownResult>