@24klynx/cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/break-cache-B716oddK.mjs +71 -0
  2. package/dist/break-cache-B716oddK.mjs.map +1 -0
  3. package/dist/bughunter-DeAizlBM.mjs +32 -0
  4. package/dist/bughunter-DeAizlBM.mjs.map +1 -0
  5. package/dist/clear-C1dFE5aD.mjs +24 -0
  6. package/dist/clear-C1dFE5aD.mjs.map +1 -0
  7. package/dist/config-D-xVXTXi.mjs +2 -0
  8. package/dist/config-Des0z-k9.mjs +147 -0
  9. package/dist/config-Des0z-k9.mjs.map +1 -0
  10. package/dist/context-BmZ8VEan.mjs +128 -0
  11. package/dist/context-BmZ8VEan.mjs.map +1 -0
  12. package/dist/context-viz-2ZZaTL2C.mjs +61 -0
  13. package/dist/context-viz-2ZZaTL2C.mjs.map +1 -0
  14. package/dist/env-CeeZcoDI.mjs +55 -0
  15. package/dist/env-CeeZcoDI.mjs.map +1 -0
  16. package/dist/git-branch-Dn1CP6An.mjs +96 -0
  17. package/dist/git-branch-Dn1CP6An.mjs.map +1 -0
  18. package/dist/headless-launcher-I8NWyD6k.mjs +171 -0
  19. package/dist/headless-launcher-I8NWyD6k.mjs.map +1 -0
  20. package/dist/index.d.mts +970 -0
  21. package/dist/index.d.mts.map +1 -0
  22. package/dist/index.mjs +3243 -0
  23. package/dist/index.mjs.map +1 -0
  24. package/dist/memory-gnURjOnQ.mjs +199 -0
  25. package/dist/memory-gnURjOnQ.mjs.map +1 -0
  26. package/dist/privacy-B6Rm1Xck.mjs +114 -0
  27. package/dist/privacy-B6Rm1Xck.mjs.map +1 -0
  28. package/dist/process-lifecycle-Dg6n2QS-.mjs +784 -0
  29. package/dist/process-lifecycle-Dg6n2QS-.mjs.map +1 -0
  30. package/dist/sandbox-toggle-9akjTw3h.mjs +64 -0
  31. package/dist/sandbox-toggle-9akjTw3h.mjs.map +1 -0
  32. package/dist/stats-DjKezhTJ.mjs +73 -0
  33. package/dist/stats-DjKezhTJ.mjs.map +1 -0
  34. package/dist/status-B3Tw-Ef4.mjs +92 -0
  35. package/dist/status-B3Tw-Ef4.mjs.map +1 -0
  36. package/dist/upgrade-CREWRNeC.mjs +72 -0
  37. package/dist/upgrade-CREWRNeC.mjs.map +1 -0
  38. package/package.json +39 -0
@@ -0,0 +1,970 @@
1
+ import { Database, LynxPaths } from "@lynx/core";
2
+ import { SessionManager } from "@lynx/session";
3
+ import { ToolRegistry } from "@lynx/tools";
4
+ import { HookRegistry, ManifestRegistry, PluginLoader, PredictiveLoader } from "@lynx/plugins";
5
+ import { AgentConfig, McpManager, McpServerConfig, MemoryManager, QueryEngine, SkillDefinition, SkillRegistry } from "@lynx/agent";
6
+ import { RuleEngine } from "@lynx/permissions";
7
+ import { ChannelRegistry, FeishuConfig } from "@lynx/channels";
8
+ import { Command } from "commander";
9
+ import { LlmProvider } from "@lynx/llm";
10
+ import { EventEmitter } from "node:events";
11
+
12
+ //#region src/bootstrap.d.ts
13
+ /** Bridge between the agent engine's permission checks and the TUI's permission dialog. */
14
+ interface PermissionBridge {
15
+ /**
16
+ * Called by the agent engine before executing a tool.
17
+ * Returns true if the tool is allowed, false if denied.
18
+ * May await user interaction via the TUI dialog.
19
+ */
20
+ requestPermission(toolName: string, safety: "Safe" | "WorkspaceSafe" | "RequiresApproval" | "Dangerous", description: string): Promise<boolean>;
21
+ /**
22
+ * Called by the TUI's onPermissionReply callback.
23
+ * Resolves the pending permission Promise.
24
+ */
25
+ handleReply(requestId: string, approved: boolean): void;
26
+ /**
27
+ * Called by the TUI after mount to register the dialog trigger.
28
+ * The handler pushes a permission view onto the TUI stack.
29
+ */
30
+ setTuiHandler(handler: ((req: {
31
+ requestId: string;
32
+ toolName: string;
33
+ description: string;
34
+ safety: "Safe" | "WorkspaceSafe" | "RequiresApproval" | "Dangerous";
35
+ }) => void) | null): void;
36
+ }
37
+ interface AppContext {
38
+ db: Database;
39
+ sessionMgr: SessionManager;
40
+ toolRegistry: ToolRegistry;
41
+ pluginRegistry: {
42
+ manifestRegistry: ManifestRegistry;
43
+ loader: PluginLoader;
44
+ hooks: HookRegistry;
45
+ };
46
+ ruleEngine: RuleEngine;
47
+ engine: QueryEngine;
48
+ provider: LlmProvider;
49
+ /** Mutable agent config — model can be changed at runtime without recreating the engine. */
50
+ agentConfig: AgentConfig;
51
+ /** Permission bridge for tool approval flow. */
52
+ permissionBridge: PermissionBridge;
53
+ /** Skill registry for progressive disclosure (built‑in + user skills). */
54
+ skillRegistry: SkillRegistry;
55
+ /** Current skill definitions for prompt injection. */
56
+ skills: SkillDefinition[];
57
+ /** MCP connection manager for external tool servers. */
58
+ mcpManager: McpManager;
59
+ /** Predictive loader — pre‑warms plugin modules during idle time. */
60
+ predictiveLoader: PredictiveLoader;
61
+ /** Channel registry — manages messaging channel adapters (飞书 etc.). */
62
+ channelRegistry: ChannelRegistry;
63
+ /** Memory manager for persistent cross-session recall. */
64
+ memoryManager: MemoryManager;
65
+ /** Persistent memory facts loaded from disk. */
66
+ memoryFacts: string[];
67
+ /** Textual rules loaded from disk for prompt injection. */
68
+ rules: string[];
69
+ /** Destroy all resources (close DB, stop timers, etc.). */
70
+ destroy(): void;
71
+ }
72
+ interface BootstrapConfig {
73
+ homeDir: string;
74
+ provider: LlmProvider;
75
+ model: string;
76
+ /** Workspace directory (defaults to cwd). Used for loading project-level memory/rules/skills. */
77
+ workspace?: string;
78
+ /** Path to built‑in skills directory (SKILL.md files). */
79
+ skillsDir?: string;
80
+ /** MCP server configurations to connect on startup. */
81
+ mcpServers?: McpServerConfig[];
82
+ /** 飞书 channel configuration (optional — channel not created if omitted). */
83
+ feishu?: FeishuConfig;
84
+ }
85
+ /**
86
+ * Bootstrap the entire Lynx application.
87
+ *
88
+ * This is the ONLY place where cross‑package wiring happens.
89
+ * Every other module only talks to its immediate dependencies
90
+ * through explicit factory‑injected interfaces.
91
+ */
92
+ declare function bootstrap(config: BootstrapConfig): AppContext;
93
+ //#endregion
94
+ //#region src/args.d.ts
95
+ /** Create the full CLI program with all sub‑commands registered. */
96
+ declare function createProgram(): Command;
97
+ /** Parse argv and run the matching command. */
98
+ declare function runCli(argv?: string[]): Promise<void>;
99
+ //#endregion
100
+ //#region src/startup.d.ts
101
+ interface Phase1Result {
102
+ paths: LynxPaths;
103
+ db: Database;
104
+ /** Wall‑clock ms for Phase 1. */
105
+ elapsedMs: number;
106
+ }
107
+ interface StartupResult extends Phase1Result {
108
+ /** Wall‑clock ms for Phase 2. */
109
+ phase2ElapsedMs: number;
110
+ }
111
+ /** Result of a single Phase 2 background task. */
112
+ interface Phase2TaskResult {
113
+ name: string;
114
+ ok: boolean;
115
+ error?: string;
116
+ elapsedMs: number;
117
+ }
118
+ /**
119
+ * Run Phase 1 — blocking startup that must finish before
120
+ * the user sees anything useful.
121
+ *
122
+ * Returns a database handle the rest of the app can use.
123
+ */
124
+ declare function runPhase1(): Phase1Result;
125
+ /**
126
+ * Run Phase 2 — background work that executes after the TUI is rendered.
127
+ *
128
+ * Tasks run sequentially with a setImmediate gap between each so the
129
+ * event loop stays responsive. Each task is independently try‑catched
130
+ * so a single failure doesn't block the rest.
131
+ *
132
+ * Returns the elapsed time in ms.
133
+ */
134
+ declare function runPhase2(result: Phase1Result): Promise<Phase2TaskResult[]>;
135
+ //#endregion
136
+ //#region src/catalog.d.ts
137
+ /**
138
+ * CommandCatalog — structured command registration with
139
+ * per‑command policy (permission mode, tool visibility, etc.).
140
+ *
141
+ * Each command is registered with a name, handler, and a set
142
+ * of policies that control how the agent behaves while executing
143
+ * that command.
144
+ */
145
+ interface CommandPolicy {
146
+ /** Permission mode for this command. */
147
+ permissionMode: "default" | "auto" | "yolo" | "headless" | "plan";
148
+ /** Which tools are visible when this command runs. */
149
+ allowedTools?: string[];
150
+ /** Can this command modify files? */
151
+ allowWrites: boolean;
152
+ }
153
+ interface CommandEntry {
154
+ name: string;
155
+ description: string;
156
+ policy: CommandPolicy;
157
+ /** Lazily‑loaded handler module path. */
158
+ handlerPath: string;
159
+ }
160
+ /** The master list of registered commands. */
161
+ declare const CATALOG: CommandEntry[];
162
+ /** Look up a command by name. */
163
+ declare function findCommand(name: string): CommandEntry | undefined;
164
+ //#endregion
165
+ //#region src/debug.d.ts
166
+ /**
167
+ * Debug logging infrastructure — writes structured JSONL logs
168
+ * to disk for post‑mortem analysis.
169
+ *
170
+ * Uses pino for formatting and rotation. Production logs are
171
+ * JSONL with daily rotation; development uses pino‑pretty.
172
+ */
173
+ type LogLevel = "trace" | "debug" | "info" | "warn" | "error";
174
+ interface DebugLogger {
175
+ trace(msg: string, data?: unknown): void;
176
+ debug(msg: string, data?: unknown): void;
177
+ info(msg: string, data?: unknown): void;
178
+ warn(msg: string, data?: unknown): void;
179
+ error(msg: string, data?: unknown): void;
180
+ }
181
+ /**
182
+ * Create a file‑based debug logger.
183
+ *
184
+ * @param logDir Directory for log files (defaults to ~/.lynx/logs).
185
+ * @param minLevel Minimum level to emit.
186
+ */
187
+ declare function createDebugLogger(logDir: string, minLevel?: LogLevel): DebugLogger;
188
+ //#endregion
189
+ //#region src/doctor/runner.d.ts
190
+ /**
191
+ * Doctor — system health checks.
192
+ *
193
+ * Runs a series of diagnostic checks and prints a report.
194
+ * Each check returns pass/fail with an optional detail message.
195
+ */
196
+ interface CheckResult {
197
+ name: string;
198
+ passed: boolean;
199
+ detail?: string;
200
+ }
201
+ interface DoctorReport {
202
+ checks: CheckResult[];
203
+ allPassed: boolean;
204
+ }
205
+ /** Run all health checks and return the report. */
206
+ declare function runChecks(): DoctorReport;
207
+ /** Print the doctor report to stdout. */
208
+ declare function printReport(report: DoctorReport): void;
209
+ /** Entry point for the `lynx doctor` command. */
210
+ declare function runDoctor(): Promise<void>;
211
+ //#endregion
212
+ //#region src/crestodian/runner.d.ts
213
+ /**
214
+ * Crestodian — non‑interactive LLM query mode.
215
+ *
216
+ * Takes a message from CLI args, sends it to the LLM provider,
217
+ * and prints the response to stdout. No TUI, no interaction.
218
+ *
219
+ * This is the `node lynx.mjs crestodian --message "..."` path.
220
+ */
221
+ /**
222
+ * Run a non‑interactive query against the LLM.
223
+ *
224
+ * Reads API keys from environment variables (DEEPSEEK_API_KEY
225
+ * or OPENAI_API_KEY) and streams the response to stdout.
226
+ */
227
+ declare function runCrestodian(message: string, _model?: string): Promise<void>;
228
+ //#endregion
229
+ //#region src/commands/session.d.ts
230
+ /**
231
+ * Session command — list, resume, fork, and delete sessions
232
+ * from the command line.
233
+ *
234
+ * Uses SessionManager for persistence and SessionPicker for
235
+ * interactive selection when no ID is provided.
236
+ */
237
+ interface SessionCommandOptions {
238
+ action: string;
239
+ id?: string;
240
+ label?: string;
241
+ }
242
+ /** Handle the `lynx sessions` command. */
243
+ declare function handleSessionCommand(opts: SessionCommandOptions): Promise<void>;
244
+ //#endregion
245
+ //#region src/commands/config.d.ts
246
+ interface ConfigCommandOptions {
247
+ show?: boolean;
248
+ set?: string;
249
+ value?: string;
250
+ path?: boolean;
251
+ }
252
+ /** 处理 `lynx config` 命令。 */
253
+ declare function handleConfigCommand(opts: ConfigCommandOptions): Promise<void>;
254
+ //#endregion
255
+ //#region src/entry.d.ts
256
+ /**
257
+ * Unified entry point — the first code that runs after `lynx.mjs`.
258
+ *
259
+ * Responsibilities:
260
+ * 1. Version check (bail early if Node.js < 22.19).
261
+ * 2. Parse CLI args and route to the correct handler.
262
+ * 3. For interactive mode: bootstrap services + launch TUI.
263
+ * 4. For sub‑commands: lazily import the handler.
264
+ *
265
+ * This file intentionally avoids importing heavy modules
266
+ * (Ink, provider implementations) at the top level so that
267
+ * `lynx --version` returns in < 100 ms.
268
+ */
269
+ /** Main entry point. Invoked from `lynx.mjs`. */
270
+ declare function main(argv?: string[]): Promise<void>;
271
+ //#endregion
272
+ //#region src/tui-launcher.d.ts
273
+ /**
274
+ * TUI launcher — boots the application and renders the Ink UI.
275
+ *
276
+ * This module is lazily loaded only when the user enters
277
+ * interactive mode (no sub‑command given).
278
+ */
279
+ /**
280
+ * Launch the interactive TUI.
281
+ *
282
+ * Phase 1: bootstrap services (DB, sessions, tools, agent engine).
283
+ * Phase 2: render the Ink TUI.
284
+ */
285
+ declare function launchTui(): Promise<void>;
286
+ //#endregion
287
+ //#region src/process-lifecycle.d.ts
288
+ interface LifecycleConfig {
289
+ /** AppContext for graceful cleanup. */
290
+ ctx: AppContext;
291
+ /** Callback to abort the current LLM request. */
292
+ onAbortLl: () => void;
293
+ /** Callback to abort the current tool execution. */
294
+ onAbortTool: () => void;
295
+ /** Current abort layer counter (0‑3). Gets incremented by SIGINT. */
296
+ getAbortLayer: () => number;
297
+ /** Increment and return the next abort layer. */
298
+ incrementAbortLayer: () => number;
299
+ /** Reset abort layer counter. */
300
+ resetAbortLayer: () => void;
301
+ /** Whether the TUI is currently streaming (in an active turn). */
302
+ isStreaming: () => boolean;
303
+ }
304
+ /**
305
+ * Install process lifecycle handlers.
306
+ *
307
+ * Only call once. Subsequent calls are no‑ops.
308
+ * Handles SIGINT (3‑layer abort), SIGTERM (graceful shutdown),
309
+ * SIGHUP (graceful shutdown), and terminal loss.
310
+ */
311
+ declare function installProcessLifecycle(config: LifecycleConfig): void;
312
+ /**
313
+ * Register a cleanup handler that runs during graceful shutdown.
314
+ * Replaces any previously registered handler.
315
+ */
316
+ declare function onCleanup(handler: () => void): void;
317
+ /**
318
+ * Remove all process lifecycle handlers (for testing).
319
+ */
320
+ declare function uninstallProcessLifecycle(): void;
321
+ //#endregion
322
+ //#region src/terminal-mode.d.ts
323
+ /**
324
+ * Terminal mode management — alt buffer, mouse tracking, DEC sync.
325
+ *
326
+ * Provides functions to enter/exit the alternate screen buffer,
327
+ * enable/disable mouse tracking, and wrap output with DEC
328
+ * Synchronized Update markers for flicker‑free rendering.
329
+ *
330
+ * All escape sequences are no‑ops on unsupported terminals
331
+ * (graceful degradation).
332
+ */
333
+ /** Enter fullscreen mode: alt buffer only (no mouse tracking). */
334
+ declare function enterFullscreen(): void;
335
+ /** Exit fullscreen mode: restore main buffer. */
336
+ declare function exitFullscreen(): void;
337
+ declare function beginSync(): void;
338
+ declare function endSync(): void;
339
+ /**
340
+ * Execute a callback within a DEC synchronized update region.
341
+ * Exceptions propagate; sync is always ended.
342
+ */
343
+ declare function withSync<T>(fn: () => T): T;
344
+ //#endregion
345
+ //#region src/worker-pool.d.ts
346
+ /**
347
+ * WorkerPool — bounded thread pool for CPU‑bound tasks.
348
+ *
349
+ * Manages a fixed number of worker threads (2‑8) with a FIFO task
350
+ * queue. All workers share the same worker script; tasks differ
351
+ * only by their postMessage payload.
352
+ *
353
+ * Design:
354
+ * - Fixed pool size, configurable at creation time
355
+ * - FIFO queue — tasks are executed in submission order
356
+ * - Auto‑restart — crashed workers replaced up to maxRetries times
357
+ * - Idle shrink — workers idle for > 30s are terminated (min 2 kept)
358
+ * - Graceful shutdown — drain remaining tasks before exit
359
+ */
360
+ /** A unit of work submitted to the pool. */
361
+ interface PoolTask<T = unknown> {
362
+ /** Unique task identifier. */
363
+ id: string;
364
+ /** Data passed to the worker via postMessage. */
365
+ workerData?: T;
366
+ /** Resolve the task with the worker's result. */
367
+ resolve: (result: unknown) => void;
368
+ /** Reject the task on failure. */
369
+ reject: (error: Error) => void;
370
+ /** Number of times this task has been retried after worker crash. */
371
+ retries: number;
372
+ }
373
+ /** Configuration for the worker pool. */
374
+ interface WorkerPoolConfig {
375
+ /** Path to the worker script that all workers execute. */
376
+ workerScript: string | URL;
377
+ /** Number of workers in the pool (clamped to 2‑8). Default: 2. */
378
+ size?: number;
379
+ /** Max restarts per worker before the pool rejects queued tasks. Default: 3. */
380
+ maxRetries?: number;
381
+ /** Idle timeout in ms before shrinking a worker. Default: 30_000. */
382
+ idleTimeoutMs?: number;
383
+ }
384
+ /** Status of the worker pool for introspection. */
385
+ interface PoolStatus {
386
+ size: number;
387
+ active: number;
388
+ idle: number;
389
+ queued: number;
390
+ totalRestarts: number;
391
+ }
392
+ /**
393
+ * Bounded worker thread pool.
394
+ *
395
+ * Usage:
396
+ * ```ts
397
+ * const pool = new WorkerPool({ workerScript: "./heavy-task.js", size: 4 });
398
+ * const result = await pool.enqueue({ input: 42 });
399
+ * await pool.shutdown();
400
+ * ```
401
+ */
402
+ declare class WorkerPool {
403
+ private config;
404
+ private workerScript;
405
+ private queue;
406
+ private workers;
407
+ private runningTasks;
408
+ private nextWorkerId;
409
+ private destroyed;
410
+ private totalRestarts;
411
+ constructor(config: WorkerPoolConfig);
412
+ /**
413
+ * Enqueue a task for execution.
414
+ *
415
+ * Returns a Promise that resolves with the worker's result
416
+ * or rejects if the pool is destroyed.
417
+ */
418
+ enqueue<TResult = unknown>(data?: unknown): Promise<TResult>;
419
+ /** Current pool status for monitoring. */
420
+ status(): PoolStatus;
421
+ /**
422
+ * Gracefully shut down the pool.
423
+ *
424
+ * Waits for active tasks to finish, then terminates all workers.
425
+ * Queued tasks that haven't started are rejected.
426
+ */
427
+ shutdown(): Promise<void>;
428
+ /** Spawn a new worker thread. */
429
+ private spawnWorker;
430
+ /** Replace a crashed worker and re-queue or reject its active task. */
431
+ private handleWorkerCrash;
432
+ /** Try to dequeue and execute pending tasks. */
433
+ private drain;
434
+ /** Execute a single task on a worker. */
435
+ private runTask;
436
+ /** Start or reset the idle timer for a worker. */
437
+ private startIdleTimer;
438
+ /** Attempt to shrink idle workers if above minimum. */
439
+ private maybeShrink;
440
+ /** Terminate a specific idle worker. */
441
+ private shrinkWorker;
442
+ }
443
+ //#endregion
444
+ //#region src/memory-monitor.d.ts
445
+ /** Alert severity levels. */
446
+ type MemoryAlertLevel = "warn" | "danger" | "fatal";
447
+ /** A memory alert event. */
448
+ interface MemoryAlert {
449
+ level: MemoryAlertLevel;
450
+ /** Current heap usage in bytes. */
451
+ heapUsed: number;
452
+ /** Heap usage as percentage of configured threshold. */
453
+ percentage: number;
454
+ /** Threshold that was breached in bytes. */
455
+ threshold: number;
456
+ /** ISO timestamp of the sample. */
457
+ timestamp: string;
458
+ }
459
+ /** Configuration for the memory monitor. */
460
+ interface MemoryMonitorConfig {
461
+ /** Sampling interval in ms. Default: 30_000. */
462
+ intervalMs?: number;
463
+ /** Warn threshold in bytes. Default: 700 * 1024 * 1024. */
464
+ warnThreshold?: number;
465
+ /** Danger threshold in bytes. Default: 900 * 1024 * 1024. */
466
+ dangerThreshold?: number;
467
+ /** Fatal threshold in bytes. Default: 950 * 1024 * 1024. */
468
+ fatalThreshold?: number;
469
+ }
470
+ /** Current memory snapshot. */
471
+ interface MemorySnapshot {
472
+ heapUsed: number;
473
+ heapTotal: number;
474
+ external: number;
475
+ rss: number;
476
+ timestamp: string;
477
+ }
478
+ /**
479
+ * Proactive heap monitor with three‑level alerting.
480
+ *
481
+ * Usage:
482
+ * ```ts
483
+ * const monitor = new MemoryMonitor({ intervalMs: 30_000 });
484
+ * monitor.on("alert", (alert) => {
485
+ * if (alert.level === "fatal") console.error("OOM imminent!");
486
+ * });
487
+ * monitor.start();
488
+ * ```
489
+ */
490
+ declare class MemoryMonitor extends EventEmitter {
491
+ private config;
492
+ private timer;
493
+ private running;
494
+ /** Track the last alert level to avoid repeated warnings. */
495
+ private lastAlertLevel;
496
+ constructor(config?: MemoryMonitorConfig);
497
+ /** Emitted when a memory alert is triggered. */
498
+ onAlert(listener: (alert: MemoryAlert) => void): this;
499
+ /** Emitted on each sample (for dashboards). */
500
+ onSample(listener: (snapshot: MemorySnapshot) => void): this;
501
+ /** Emitted when compaction is requested. */
502
+ onCompact(listener: (info: {
503
+ reason: string;
504
+ heapUsed: number;
505
+ }) => void): this;
506
+ /** Emitted when caches should be flushed. */
507
+ onFlushCaches(listener: (info: {
508
+ reason: string;
509
+ heapUsed: number;
510
+ }) => void): this;
511
+ /** Start periodic heap sampling. No‑op if already running. */
512
+ start(): void;
513
+ /** Stop periodic sampling. */
514
+ stop(): void;
515
+ /** Take a manual snapshot and return it. */
516
+ snapshot(): MemorySnapshot;
517
+ /** Sample heap usage and fire alerts if thresholds are breached. */
518
+ private sample;
519
+ /** Execute the appropriate action for each alert level. */
520
+ private actOnAlert;
521
+ /** Trigger V8 garbage collection if --expose-gc is enabled. */
522
+ private triggerGc;
523
+ }
524
+ //#endregion
525
+ //#region src/update-check.d.ts
526
+ /**
527
+ * UpdateChecker — asynchronous, non‑blocking version check.
528
+ *
529
+ * Queries npm and GitHub for the latest Lynx release and compares
530
+ * against the running version. Designed to never block startup:
531
+ * the check runs in the background and fires a callback when
532
+ * complete.
533
+ *
534
+ * Design (§5.9k):
535
+ * - Async, non‑blocking — fire and forget
536
+ * - O_EXCL lock — only one check runs at a time per process
537
+ * - Dual channel: npm registry + GitHub releases
538
+ * - GitHub as fallback when npm is slow or unreachable
539
+ * - Result cached for the session lifetime
540
+ * - Respects NO_UPDATE_CHECK env var
541
+ */
542
+ /** Result of an update check. */
543
+ interface UpdateResult {
544
+ /** Current installed version. */
545
+ current: string;
546
+ /** Latest available version, or null if unknown. */
547
+ latest: string | null;
548
+ /** Whether a newer version is available. */
549
+ hasUpdate: boolean;
550
+ /** Release notes URL for the latest version. */
551
+ releaseUrl: string | null;
552
+ /** Time the check was performed (ISO string). */
553
+ checkedAt: string;
554
+ /** Which channel provided the result. */
555
+ source: "npm" | "github" | "cache" | "error";
556
+ /** Error message if the check failed. */
557
+ error?: string;
558
+ }
559
+ /** Configuration for the update checker. */
560
+ interface UpdateCheckConfig {
561
+ /** Current version string (e.g. "0.1.0"). */
562
+ currentVersion: string;
563
+ /** npm package name. Default: "lynx". */
564
+ packageName?: string;
565
+ /** GitHub repository in "owner/repo" format. Default: "loongcrown/lynx". */
566
+ githubRepo?: string;
567
+ /** Timeout per request in ms. Default: 5_000. */
568
+ timeoutMs?: number;
569
+ /** Cache duration in ms. Default: 3_600_000 (1 hour). */
570
+ cacheTtlMs?: number;
571
+ }
572
+ /**
573
+ * Check for updates asynchronously.
574
+ *
575
+ * Only one check runs at a time — concurrent calls return the
576
+ * same Promise. Results are cached for the configured TTL.
577
+ *
578
+ * Callers should never await this at startup — fire‑and‑forget
579
+ * and read the result from the cache on next call.
580
+ */
581
+ declare function checkForUpdates(config: UpdateCheckConfig): Promise<UpdateResult>;
582
+ /**
583
+ * Synchronously return the last cached update result.
584
+ * Returns null if no check has been performed yet.
585
+ */
586
+ declare function getLastUpdateResult(): UpdateResult | null;
587
+ /**
588
+ * Clear the cached update result (for testing).
589
+ */
590
+ declare function clearUpdateCache(): void;
591
+ //#endregion
592
+ //#region src/commands/plugin.d.ts
593
+ /**
594
+ * Plugin command — manage installed plugins.
595
+ *
596
+ * Sub‑commands:
597
+ * list — list installed plugins with status
598
+ * enable <name> — enable a disabled plugin
599
+ * disable <name> — disable a plugin (without uninstalling)
600
+ * install <path> — install a plugin from a local path
601
+ * remove <name> — uninstall a plugin
602
+ */
603
+ interface PluginCommandOptions {
604
+ list?: boolean;
605
+ enable?: string;
606
+ disable?: string;
607
+ install?: string;
608
+ remove?: string;
609
+ }
610
+ /** Handle the `lynx plugin` command. */
611
+ declare function handlePluginCommand(opts: PluginCommandOptions): Promise<void>;
612
+ //#endregion
613
+ //#region src/commands/git-commit.d.ts
614
+ /**
615
+ * /commit 命令 — 创建 Git 提交并推送。
616
+ *
617
+ * 生成中文指令,引导模型执行完整的提交工作流:
618
+ * 1. 检查工作区状态和变更摘要
619
+ * 2. 基于用户消息(或自动生成)创建约定式提交
620
+ * 3. git add → git commit → git push
621
+ * 4. --all 标志表示暂存所有变更
622
+ */
623
+ interface CommitCommandArgs {
624
+ /** 用户自定义的提交消息(可选,省略时自动生成)。 */
625
+ message?: string;
626
+ /** 是否暂存所有变更(git add -A)。 */
627
+ all?: boolean;
628
+ }
629
+ /**
630
+ * 处理 /commit 命令,返回一段中文指令引导模型完成提交。
631
+ */
632
+ declare function handleCommitCommand(args: CommitCommandArgs): {
633
+ instruction: string;
634
+ };
635
+ //#endregion
636
+ //#region src/commands/git-review.d.ts
637
+ /**
638
+ * /review 命令 — 审查 GitHub Pull Request。
639
+ *
640
+ * 生成中文指令,引导模型获取 PR 变更并给出结构化审查意见:
641
+ * 1. 获取 PR 信息(列表或详情)
642
+ * 2. 获取 PR diff 内容
643
+ * 3. 系统化分析:bug、风格、测试、安全
644
+ * 4. 输出结构化审查报告
645
+ */
646
+ interface ReviewCommandArgs {
647
+ /** PR 编号(可选,省略时列出所有待审查的 PR)。 */
648
+ number?: number;
649
+ /** 目标分支(用于 gh pr list 的 --base 过滤)。 */
650
+ base?: string;
651
+ }
652
+ /**
653
+ * 处理 /review 命令,返回一段中文指令引导模型完成代码审查。
654
+ */
655
+ declare function handleReviewCommand(args: ReviewCommandArgs): {
656
+ instruction: string;
657
+ };
658
+ //#endregion
659
+ //#region src/commands/git-pr-comments.d.ts
660
+ /**
661
+ * /pr-comments 命令 — 处理 PR 审查评论。
662
+ *
663
+ * 生成中文指令,引导模型:
664
+ * 1. 获取 PR 所有评论
665
+ * 2. 处理未解决的评论(修改代码)
666
+ * 3. 回复已解决的评论(确认)
667
+ */
668
+ interface PrCommentsCommandArgs {
669
+ /** PR 编号(可选,省略时从最近 PR 推断)。 */
670
+ number?: number;
671
+ }
672
+ /**
673
+ * 处理 /pr-comments 命令,返回一段中文指令引导模型处理 PR 评论。
674
+ */
675
+ declare function handlePrCommentsCommand(args: PrCommentsCommandArgs): {
676
+ instruction: string;
677
+ };
678
+ //#endregion
679
+ //#region src/commands/git-issue.d.ts
680
+ /**
681
+ * /issue 命令 — 管理 GitHub Issue。
682
+ *
683
+ * 生成中文指令,引导模型执行 Issue 操作:
684
+ * create — 创建新 Issue
685
+ * list — 列出仓库 Issue
686
+ * view — 查看指定 Issue 详情
687
+ */
688
+ interface IssueCommandArgs {
689
+ /** 操作类型:create 创建、list 列出、view 查看。 */
690
+ action?: "create" | "list" | "view";
691
+ /** Issue 标题(create 时使用)。 */
692
+ title?: string;
693
+ /** Issue 编号(view 时使用)。 */
694
+ number?: number;
695
+ }
696
+ /**
697
+ * 处理 /issue 命令,返回一段中文指令引导模型完成 Issue 操作。
698
+ */
699
+ declare function handleIssueCommand(args: IssueCommandArgs): {
700
+ instruction: string;
701
+ };
702
+ //#endregion
703
+ //#region src/commands/git-autofix.d.ts
704
+ /**
705
+ * /autofix-pr 命令 — 自动修复 PR 问题。
706
+ *
707
+ * ⚠️ 功能正在开发中,当前为占位实现。
708
+ * 后续将与 gh cli 集成,实现自动分析 PR 失败检查并生成修复方案。
709
+ */
710
+ interface AutoFixCommandArgs {
711
+ /** PR 编号(可选)。 */
712
+ number?: number;
713
+ /** 要修复的问题描述(可选)。 */
714
+ issue?: string;
715
+ }
716
+ /**
717
+ * 处理 /autofix-pr 命令。
718
+ *
719
+ * 当前为占位实现,返回开发中提示信息。
720
+ * 后续将实现完整的自动修复管线。
721
+ */
722
+ declare function handleAutoFixCommand(_args: AutoFixCommandArgs): {
723
+ instruction: string;
724
+ };
725
+ //#endregion
726
+ //#region src/commands/git-diff.d.ts
727
+ /**
728
+ * /diff 命令 — 展示 Git 工作区变更。
729
+ *
730
+ * 生成中文指令,引导模型:
731
+ * 1. 运行 git diff 获取未暂存变更
732
+ * 2. 运行 git diff --staged 获取已暂存变更
733
+ * 3. 以结构化格式展示,高亮关键变更
734
+ */
735
+ interface DiffCommandArgs {
736
+ /** 是否仅显示已暂存的变更(git diff --staged)。 */
737
+ staged?: boolean;
738
+ /** 指定要查看 diff 的文件列表(可选)。 */
739
+ files?: string[];
740
+ }
741
+ /**
742
+ * 处理 /diff 命令,返回一段中文指令引导模型展示代码变更。
743
+ */
744
+ declare function handleDiffCommand(args: DiffCommandArgs): {
745
+ instruction: string;
746
+ };
747
+ //#endregion
748
+ //#region src/commands/ant-trace.d.ts
749
+ /**
750
+ * /ant-trace — 工具调用链追踪可视化。
751
+ *
752
+ * 返回 model instruction,指示模型从会话历史中提取 tool_use / tool_result 配对,
753
+ * 构建父子调用树并标注耗时与错误。TUI 层用 local-jsx 渲染为可折叠树形组件。
754
+ *
755
+ * 用法:/ant-trace [--session <id>] 默认追踪当前会话。
756
+ */
757
+ interface AntTraceOptions {
758
+ /** 可选:要追踪的会话 ID,默认当前会话。 */
759
+ sessionId?: string;
760
+ }
761
+ /**
762
+ * 处理 /ant-trace 命令。
763
+ *
764
+ * 返回一条 model instruction,驱动模型检查会话历史中的
765
+ * 工具调用链并生成结构化诊断输出。
766
+ */
767
+ declare function handleAntTraceCommand(opts: AntTraceOptions): {
768
+ instruction: string;
769
+ };
770
+ //#endregion
771
+ //#region src/commands/debug-tool-call.d.ts
772
+ /**
773
+ * /debug-tool-call — 单步工具调用调试器。
774
+ *
775
+ * 用于排查单个工具调用的输入、输出、错误和耗时细分。
776
+ * 支持按工具名称或步骤索引定位调用,不带参数时列出最近的调用概览。
777
+ *
778
+ * 用法:
779
+ * /debug-tool-call 列出最近调用
780
+ * /debug-tool-call --tool <name> 查看指定工具的最后一次调用
781
+ * /debug-tool-call --step <index> 查看指定步骤索引处的工具调用
782
+ */
783
+ interface DebugToolCallOptions {
784
+ /** 按工具名称过滤,查看该工具的最后一次调用详情。 */
785
+ tool?: string;
786
+ /** 按步骤索引定位(从 1 开始),查看该步骤的工具调用。 */
787
+ step?: string;
788
+ }
789
+ /**
790
+ * 处理 /debug-tool-call 命令。
791
+ *
792
+ * 返回一条 model instruction,驱动模型检查会话历史中的
793
+ * 工具调用并输出调试信息。
794
+ */
795
+ declare function handleDebugToolCall(opts: DebugToolCallOptions): {
796
+ instruction: string;
797
+ };
798
+ //#endregion
799
+ //#region src/commands/tasks.d.ts
800
+ /**
801
+ * /tasks — 后台任务监视与控制。
802
+ *
803
+ * 列出当前后台任务状态,支持取消运行中的任务和查看任务详情。
804
+ * 该命令与 TUI 层的 TasksPanel 组件配合使用:
805
+ * - list:打开任务面板,展示实时状态(带色彩编码)
806
+ * - cancel:通过 taskId 取消指定任务
807
+ * - detail:展示任务的完整输出流
808
+ *
809
+ * 用法:
810
+ * /tasks 列出所有任务(默认)
811
+ * /tasks --action cancel --taskId <id> 取消任务
812
+ * /tasks --action detail --taskId <id> 查看任务详情
813
+ */
814
+ interface TasksCommandOptions {
815
+ /** 操作类型:list(默认)、cancel、detail。 */
816
+ action?: string;
817
+ /** cancel 或 detail 操作时必填。 */
818
+ taskId?: string;
819
+ }
820
+ /**
821
+ * 处理 /tasks 命令。
822
+ *
823
+ * 根据 action 返回不同的 model instruction,驱动模型
824
+ * 执行相应的任务管理操作。
825
+ */
826
+ declare function handleTasksCommand(opts: TasksCommandOptions): {
827
+ instruction: string;
828
+ };
829
+ //#endregion
830
+ //#region src/commands/heapdump.d.ts
831
+ /**
832
+ * /heapdump — V8 堆快照,用于内存泄漏诊断。
833
+ *
834
+ * 调用 Node.js 内置的 writeHeapSnapshot() 生成 .heapsnapshot 文件,
835
+ * 保存到 ~/.lynx/heapdumps/ 目录下。可在 Chrome DevTools 的
836
+ * Memory 面板中加载分析。
837
+ *
838
+ * 用法:/heapdump
839
+ */
840
+ /**
841
+ * 处理 /heapdump 命令。
842
+ *
843
+ * 生成立即堆快照并返回文件路径。这是 local 类型命令——
844
+ * 不经过模型,直接在 CLI 进程中执行。
845
+ */
846
+ declare function handleHeapdumpCommand(): Promise<{
847
+ output: string;
848
+ }>;
849
+ //#endregion
850
+ //#region src/commands/perf-issue.d.ts
851
+ /**
852
+ * /perf-issue — 性能问题诊断。
853
+ *
854
+ * 返回 model instruction,驱动模型分析性能问题、检查日志、
855
+ * 筛查慢调用和内存使用模式,并给出优化建议。
856
+ *
857
+ * 用法:
858
+ * /perf-issue 通用性能健康检查
859
+ * /perf-issue --issue <描述> 针对具体问题的诊断
860
+ */
861
+ interface PerfIssueOptions {
862
+ /** 可选:用户描述的具体性能问题。不提供则执行通用健康检查。 */
863
+ issue?: string;
864
+ }
865
+ /**
866
+ * 处理 /perf-issue 命令。
867
+ *
868
+ * 返回 model instruction,驱动模型执行性能诊断分析。
869
+ */
870
+ declare function handlePerfIssueCommand(opts: PerfIssueOptions): {
871
+ instruction: string;
872
+ };
873
+ //#endregion
874
+ //#region src/commands/share.d.ts
875
+ /**
876
+ * /share — 将会话导出为可分享的 Markdown 文件。
877
+ *
878
+ * 从 ~/.lynx/sessions/{sessionId}.json 读取消息,
879
+ * 格式化为干净的 Markdown 后写入 ~/.lynx/exports/ 目录。
880
+ */
881
+ interface ShareCommandOptions {
882
+ sessionId?: string;
883
+ output?: string;
884
+ }
885
+ /**
886
+ * 处理 /share 命令。
887
+ *
888
+ * 将会话消息导出为 Markdown 文件,方便分享。
889
+ * 默认导出最近一次会话,可通过 --session-id 指定。
890
+ */
891
+ declare function handleShareCommand(opts: ShareCommandOptions): Promise<{
892
+ output: string;
893
+ }>;
894
+ //#endregion
895
+ //#region src/commands/export.d.ts
896
+ /**
897
+ * /export — 以多种格式导出会话。
898
+ *
899
+ * 支持三种输出格式:
900
+ * - markdown:与 /share 相同,格式化为可读的 Markdown
901
+ * - json:导出原始消息数组(格式化 JSON)
902
+ * - html:将 Markdown 包裹在基础 HTML 模板中
903
+ */
904
+ interface ExportCommandOptions {
905
+ sessionId?: string;
906
+ format?: "markdown" | "json" | "html";
907
+ output?: string;
908
+ }
909
+ /**
910
+ * 处理 /export 命令。
911
+ *
912
+ * 以指定格式导出会话,支持 markdown / json / html。
913
+ * 默认导出最近一次会话为 markdown 格式。
914
+ */
915
+ declare function handleExportCommand(opts: ExportCommandOptions): Promise<{
916
+ output: string;
917
+ }>;
918
+ //#endregion
919
+ //#region src/commands/tag.d.ts
920
+ /**
921
+ * /tag — 为会话打标签,用于分类管理。
922
+ *
923
+ * 标签数据存储在 ~/.lynx/session-tags.json 中。
924
+ * 支持三种操作:
925
+ * - add:为指定会话添加标签
926
+ * - remove:移除指定标签
927
+ * - list:列出所有带标签的会话,或指定会话的所有标签
928
+ */
929
+ interface TagCommandOptions {
930
+ sessionId?: string;
931
+ tag?: string;
932
+ action?: "add" | "remove" | "list";
933
+ }
934
+ /**
935
+ * 处理 /tag 命令。
936
+ *
937
+ * 为会话添加、移除或列出标签。
938
+ * 默认操作为 list;add/remove 需要提供 --tag 参数。
939
+ */
940
+ declare function handleTagCommand(opts: TagCommandOptions): Promise<{
941
+ output: string;
942
+ }>;
943
+ //#endregion
944
+ //#region src/commands/copy.d.ts
945
+ /**
946
+ * /copy — 将最后一条助手回复复制到剪贴板。
947
+ *
948
+ * 从会话中提取指定索引(从末尾倒数)的助手消息文本,
949
+ * 通过平台对应的剪贴板命令写入系统剪贴板。
950
+ *
951
+ * 支持平台:Windows(PowerShell)、macOS(pbcopy)、
952
+ * Linux(xclip 或 wl-copy)。
953
+ */
954
+ interface CopyCommandOptions {
955
+ sessionId?: string;
956
+ /** 从末尾倒数第几条消息(0 = 最后一条,默认 0)。 */
957
+ index?: number;
958
+ }
959
+ /**
960
+ * 处理 /copy 命令。
961
+ *
962
+ * 将指定索引(从末尾倒数)的助手消息文本复制到系统剪贴板。
963
+ * 默认复制最后一条助手回复。
964
+ */
965
+ declare function handleCopyCommand(opts: CopyCommandOptions): Promise<{
966
+ output: string;
967
+ }>;
968
+ //#endregion
969
+ export { type AntTraceOptions, type AppContext, type AutoFixCommandArgs, type BootstrapConfig, CATALOG, type CheckResult, type CommandEntry, type CommandPolicy, type CommitCommandArgs, type ConfigCommandOptions, type CopyCommandOptions, type DebugLogger, type DebugToolCallOptions, type DiffCommandArgs, type DoctorReport, type ExportCommandOptions, type IssueCommandArgs, type LifecycleConfig, type LogLevel, type MemoryAlert, type MemoryAlertLevel, MemoryMonitor, type MemoryMonitorConfig, type MemorySnapshot, type PerfIssueOptions, type Phase1Result, type PluginCommandOptions, type PoolStatus, type PoolTask, type PrCommentsCommandArgs, type ReviewCommandArgs, type SessionCommandOptions, type ShareCommandOptions, type StartupResult, type TagCommandOptions, type TasksCommandOptions, type UpdateCheckConfig, type UpdateResult, WorkerPool, type WorkerPoolConfig, beginSync, bootstrap, checkForUpdates, clearUpdateCache, createDebugLogger, createProgram, endSync, enterFullscreen, exitFullscreen, findCommand, getLastUpdateResult, handleAntTraceCommand, handleAutoFixCommand, handleCommitCommand, handleConfigCommand, handleCopyCommand, handleDebugToolCall, handleDiffCommand, handleExportCommand, handleHeapdumpCommand, handleIssueCommand, handlePerfIssueCommand, handlePluginCommand, handlePrCommentsCommand, handleReviewCommand, handleSessionCommand, handleShareCommand, handleTagCommand, handleTasksCommand, installProcessLifecycle, launchTui, main, onCleanup, printReport, runChecks, runCli, runCrestodian, runDoctor, runPhase1, runPhase2, uninstallProcessLifecycle, withSync };
970
+ //# sourceMappingURL=index.d.mts.map