pty-manager 1.2.12 → 1.2.14
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/dist/index.d.mts +81 -2
- package/dist/index.d.ts +81 -2
- package/dist/index.js +226 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +226 -5
- package/dist/index.mjs.map +1 -1
- package/dist/pty-worker.js +223 -3
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -35,6 +35,8 @@ interface SpawnConfig {
|
|
|
35
35
|
timeout?: number;
|
|
36
36
|
/** Custom adapter configuration */
|
|
37
37
|
adapterConfig?: Record<string, unknown>;
|
|
38
|
+
/** Per-session stall timeout in ms. Overrides PTYManagerConfig.stallTimeoutMs. */
|
|
39
|
+
stallTimeoutMs?: number;
|
|
38
40
|
}
|
|
39
41
|
/**
|
|
40
42
|
* Handle to a running session
|
|
@@ -139,6 +141,17 @@ interface BlockingPromptInfo {
|
|
|
139
141
|
instructions?: string;
|
|
140
142
|
url?: string;
|
|
141
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* Classification result from external stall analysis
|
|
146
|
+
*/
|
|
147
|
+
interface StallClassification {
|
|
148
|
+
/** What the external classifier determined */
|
|
149
|
+
state: 'waiting_for_input' | 'still_working' | 'task_complete' | 'error';
|
|
150
|
+
/** Description of the detected prompt (for waiting_for_input) */
|
|
151
|
+
prompt?: string;
|
|
152
|
+
/** Suggested response to send (for waiting_for_input with auto-respond) */
|
|
153
|
+
suggestedResponse?: string;
|
|
154
|
+
}
|
|
142
155
|
/**
|
|
143
156
|
* Logger interface (bring your own logger)
|
|
144
157
|
*/
|
|
@@ -187,6 +200,18 @@ interface PTYManagerConfig {
|
|
|
187
200
|
logger?: Logger;
|
|
188
201
|
/** Maximum output log lines per session (default: 1000) */
|
|
189
202
|
maxLogLines?: number;
|
|
203
|
+
/** Enable stall detection (default: false) */
|
|
204
|
+
stallDetectionEnabled?: boolean;
|
|
205
|
+
/** Default stall timeout in ms (default: 8000). Can be overridden per-session via SpawnConfig. */
|
|
206
|
+
stallTimeoutMs?: number;
|
|
207
|
+
/**
|
|
208
|
+
* External classification callback invoked when a stall is detected.
|
|
209
|
+
* Return null or { state: 'still_working' } to reset the timer.
|
|
210
|
+
* Return { state: 'waiting_for_input', suggestedResponse } to auto-respond.
|
|
211
|
+
* Return { state: 'task_complete' } to transition session to ready.
|
|
212
|
+
* Return { state: 'error' } to emit session_error.
|
|
213
|
+
*/
|
|
214
|
+
onStallClassify?: (sessionId: string, recentOutput: string, stallDurationMs: number) => Promise<StallClassification | null>;
|
|
190
215
|
}
|
|
191
216
|
/**
|
|
192
217
|
* Configuration for creating an adapter via factory
|
|
@@ -362,6 +387,7 @@ interface PTYSessionEvents {
|
|
|
362
387
|
question: (question: string) => void;
|
|
363
388
|
exit: (code: number) => void;
|
|
364
389
|
error: (error: Error) => void;
|
|
390
|
+
stall_detected: (recentOutput: string, stallDurationMs: number) => void;
|
|
365
391
|
}
|
|
366
392
|
/**
|
|
367
393
|
* Special key mappings to escape sequences
|
|
@@ -381,9 +407,14 @@ declare class PTYSession extends EventEmitter {
|
|
|
381
407
|
private logger;
|
|
382
408
|
private sessionRules;
|
|
383
409
|
private _lastBlockingPromptHash;
|
|
410
|
+
private _stallTimer;
|
|
411
|
+
private _stallTimeoutMs;
|
|
412
|
+
private _stallDetectionEnabled;
|
|
413
|
+
private _lastStallHash;
|
|
414
|
+
private _stallStartedAt;
|
|
384
415
|
readonly id: string;
|
|
385
416
|
readonly config: SpawnConfig;
|
|
386
|
-
constructor(adapter: CLIAdapter, config: SpawnConfig, logger?: Logger);
|
|
417
|
+
constructor(adapter: CLIAdapter, config: SpawnConfig, logger?: Logger, stallDetectionEnabled?: boolean, defaultStallTimeoutMs?: number);
|
|
387
418
|
get status(): SessionStatus;
|
|
388
419
|
get pid(): number | undefined;
|
|
389
420
|
get startedAt(): Date | undefined;
|
|
@@ -410,6 +441,33 @@ declare class PTYSession extends EventEmitter {
|
|
|
410
441
|
* Clear all session auto-response rules.
|
|
411
442
|
*/
|
|
412
443
|
clearAutoResponseRules(): void;
|
|
444
|
+
/**
|
|
445
|
+
* Start or reset the stall detection timer.
|
|
446
|
+
* Only active when status is "busy" and stall detection is enabled.
|
|
447
|
+
*/
|
|
448
|
+
private resetStallTimer;
|
|
449
|
+
/**
|
|
450
|
+
* Clear the stall detection timer.
|
|
451
|
+
*/
|
|
452
|
+
private clearStallTimer;
|
|
453
|
+
/**
|
|
454
|
+
* Called when the stall timer fires (no output for stallTimeoutMs).
|
|
455
|
+
*/
|
|
456
|
+
private onStallTimerFired;
|
|
457
|
+
/**
|
|
458
|
+
* Simple string hash for deduplication.
|
|
459
|
+
*/
|
|
460
|
+
private simpleHash;
|
|
461
|
+
/**
|
|
462
|
+
* Strip ANSI codes for stall detection output.
|
|
463
|
+
* Replaces cursor-forward sequences with spaces first.
|
|
464
|
+
*/
|
|
465
|
+
private stripAnsiForStall;
|
|
466
|
+
/**
|
|
467
|
+
* Handle external stall classification result.
|
|
468
|
+
* Called by the manager after onStallClassify resolves.
|
|
469
|
+
*/
|
|
470
|
+
handleStallClassification(classification: StallClassification | null): void;
|
|
413
471
|
/**
|
|
414
472
|
* Start the PTY session
|
|
415
473
|
*/
|
|
@@ -510,6 +568,7 @@ interface PTYManagerEvents {
|
|
|
510
568
|
blocking_prompt: (session: SessionHandle, promptInfo: BlockingPromptInfo, autoResponded: boolean) => void;
|
|
511
569
|
message: (message: SessionMessage) => void;
|
|
512
570
|
question: (session: SessionHandle, question: string) => void;
|
|
571
|
+
stall_detected: (session: SessionHandle, recentOutput: string, stallDurationMs: number) => void;
|
|
513
572
|
}
|
|
514
573
|
declare class PTYManager extends EventEmitter {
|
|
515
574
|
private sessions;
|
|
@@ -517,6 +576,9 @@ declare class PTYManager extends EventEmitter {
|
|
|
517
576
|
private maxLogLines;
|
|
518
577
|
private logger;
|
|
519
578
|
readonly adapters: AdapterRegistry;
|
|
579
|
+
private _stallDetectionEnabled;
|
|
580
|
+
private _stallTimeoutMs;
|
|
581
|
+
private _onStallClassify?;
|
|
520
582
|
constructor(config?: PTYManagerConfig);
|
|
521
583
|
/**
|
|
522
584
|
* Register a CLI adapter
|
|
@@ -581,6 +643,11 @@ declare class PTYManager extends EventEmitter {
|
|
|
581
643
|
* Get the underlying PTYSession (for advanced use)
|
|
582
644
|
*/
|
|
583
645
|
getSession(sessionId: string): PTYSession | undefined;
|
|
646
|
+
/**
|
|
647
|
+
* Configure stall detection at runtime.
|
|
648
|
+
* Affects newly spawned sessions only — existing sessions keep their config.
|
|
649
|
+
*/
|
|
650
|
+
configureStallDetection(enabled: boolean, timeoutMs?: number, classify?: (sessionId: string, recentOutput: string, stallDurationMs: number) => Promise<StallClassification | null>): void;
|
|
584
651
|
/**
|
|
585
652
|
* Add an auto-response rule to a session.
|
|
586
653
|
* Session rules are checked before adapter rules.
|
|
@@ -755,6 +822,15 @@ interface BunPTYManagerOptions {
|
|
|
755
822
|
* Example: ['coding-agent-adapters']
|
|
756
823
|
*/
|
|
757
824
|
adapterModules?: string[];
|
|
825
|
+
/** Enable stall detection (default: false) */
|
|
826
|
+
stallDetectionEnabled?: boolean;
|
|
827
|
+
/** Default stall timeout in ms (default: 8000) */
|
|
828
|
+
stallTimeoutMs?: number;
|
|
829
|
+
/**
|
|
830
|
+
* External classification callback invoked when a stall is detected.
|
|
831
|
+
* The worker emits stall_detected; this callback runs on the parent side.
|
|
832
|
+
*/
|
|
833
|
+
onStallClassify?: (sessionId: string, recentOutput: string, stallDurationMs: number) => Promise<StallClassification | null>;
|
|
758
834
|
}
|
|
759
835
|
/**
|
|
760
836
|
* PTY Manager that works with Bun and other non-Node runtimes
|
|
@@ -771,6 +847,9 @@ declare class BunCompatiblePTYManager extends EventEmitter {
|
|
|
771
847
|
private workerPath;
|
|
772
848
|
private env;
|
|
773
849
|
private adapterModules;
|
|
850
|
+
private _stallDetectionEnabled;
|
|
851
|
+
private _stallTimeoutMs;
|
|
852
|
+
private _onStallClassify?;
|
|
774
853
|
constructor(options?: BunPTYManagerOptions);
|
|
775
854
|
private findWorkerPath;
|
|
776
855
|
private startWorker;
|
|
@@ -869,4 +948,4 @@ declare function isBun(): boolean;
|
|
|
869
948
|
*/
|
|
870
949
|
declare function createPTYManager(options?: BunPTYManagerOptions): BunCompatiblePTYManager;
|
|
871
950
|
|
|
872
|
-
export { type AdapterFactoryConfig, AdapterRegistry, type AutoResponseRule, BaseCLIAdapter, type BlockingPromptDetection, type BlockingPromptInfo, type BlockingPromptType, BunCompatiblePTYManager, type BunPTYManagerOptions, type CLIAdapter, type LogOptions, type Logger, type LoginDetection, type MessageType, PTYManager, type PTYManagerConfig, type PTYManagerEvents, PTYSession, type PTYSessionEvents, type ParsedOutput, SPECIAL_KEYS, type SessionFilter, type SessionHandle, type SessionMessage, type SessionStatus, ShellAdapter, type ShellAdapterOptions, type SpawnConfig, type StopOptions, type TerminalAttachment, type WorkerSessionHandle, createAdapter, createPTYManager, isBun };
|
|
951
|
+
export { type AdapterFactoryConfig, AdapterRegistry, type AutoResponseRule, BaseCLIAdapter, type BlockingPromptDetection, type BlockingPromptInfo, type BlockingPromptType, BunCompatiblePTYManager, type BunPTYManagerOptions, type CLIAdapter, type LogOptions, type Logger, type LoginDetection, type MessageType, PTYManager, type PTYManagerConfig, type PTYManagerEvents, PTYSession, type PTYSessionEvents, type ParsedOutput, SPECIAL_KEYS, type SessionFilter, type SessionHandle, type SessionMessage, type SessionStatus, ShellAdapter, type ShellAdapterOptions, type SpawnConfig, type StallClassification, type StopOptions, type TerminalAttachment, type WorkerSessionHandle, createAdapter, createPTYManager, isBun };
|
package/dist/index.d.ts
CHANGED
|
@@ -35,6 +35,8 @@ interface SpawnConfig {
|
|
|
35
35
|
timeout?: number;
|
|
36
36
|
/** Custom adapter configuration */
|
|
37
37
|
adapterConfig?: Record<string, unknown>;
|
|
38
|
+
/** Per-session stall timeout in ms. Overrides PTYManagerConfig.stallTimeoutMs. */
|
|
39
|
+
stallTimeoutMs?: number;
|
|
38
40
|
}
|
|
39
41
|
/**
|
|
40
42
|
* Handle to a running session
|
|
@@ -139,6 +141,17 @@ interface BlockingPromptInfo {
|
|
|
139
141
|
instructions?: string;
|
|
140
142
|
url?: string;
|
|
141
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* Classification result from external stall analysis
|
|
146
|
+
*/
|
|
147
|
+
interface StallClassification {
|
|
148
|
+
/** What the external classifier determined */
|
|
149
|
+
state: 'waiting_for_input' | 'still_working' | 'task_complete' | 'error';
|
|
150
|
+
/** Description of the detected prompt (for waiting_for_input) */
|
|
151
|
+
prompt?: string;
|
|
152
|
+
/** Suggested response to send (for waiting_for_input with auto-respond) */
|
|
153
|
+
suggestedResponse?: string;
|
|
154
|
+
}
|
|
142
155
|
/**
|
|
143
156
|
* Logger interface (bring your own logger)
|
|
144
157
|
*/
|
|
@@ -187,6 +200,18 @@ interface PTYManagerConfig {
|
|
|
187
200
|
logger?: Logger;
|
|
188
201
|
/** Maximum output log lines per session (default: 1000) */
|
|
189
202
|
maxLogLines?: number;
|
|
203
|
+
/** Enable stall detection (default: false) */
|
|
204
|
+
stallDetectionEnabled?: boolean;
|
|
205
|
+
/** Default stall timeout in ms (default: 8000). Can be overridden per-session via SpawnConfig. */
|
|
206
|
+
stallTimeoutMs?: number;
|
|
207
|
+
/**
|
|
208
|
+
* External classification callback invoked when a stall is detected.
|
|
209
|
+
* Return null or { state: 'still_working' } to reset the timer.
|
|
210
|
+
* Return { state: 'waiting_for_input', suggestedResponse } to auto-respond.
|
|
211
|
+
* Return { state: 'task_complete' } to transition session to ready.
|
|
212
|
+
* Return { state: 'error' } to emit session_error.
|
|
213
|
+
*/
|
|
214
|
+
onStallClassify?: (sessionId: string, recentOutput: string, stallDurationMs: number) => Promise<StallClassification | null>;
|
|
190
215
|
}
|
|
191
216
|
/**
|
|
192
217
|
* Configuration for creating an adapter via factory
|
|
@@ -362,6 +387,7 @@ interface PTYSessionEvents {
|
|
|
362
387
|
question: (question: string) => void;
|
|
363
388
|
exit: (code: number) => void;
|
|
364
389
|
error: (error: Error) => void;
|
|
390
|
+
stall_detected: (recentOutput: string, stallDurationMs: number) => void;
|
|
365
391
|
}
|
|
366
392
|
/**
|
|
367
393
|
* Special key mappings to escape sequences
|
|
@@ -381,9 +407,14 @@ declare class PTYSession extends EventEmitter {
|
|
|
381
407
|
private logger;
|
|
382
408
|
private sessionRules;
|
|
383
409
|
private _lastBlockingPromptHash;
|
|
410
|
+
private _stallTimer;
|
|
411
|
+
private _stallTimeoutMs;
|
|
412
|
+
private _stallDetectionEnabled;
|
|
413
|
+
private _lastStallHash;
|
|
414
|
+
private _stallStartedAt;
|
|
384
415
|
readonly id: string;
|
|
385
416
|
readonly config: SpawnConfig;
|
|
386
|
-
constructor(adapter: CLIAdapter, config: SpawnConfig, logger?: Logger);
|
|
417
|
+
constructor(adapter: CLIAdapter, config: SpawnConfig, logger?: Logger, stallDetectionEnabled?: boolean, defaultStallTimeoutMs?: number);
|
|
387
418
|
get status(): SessionStatus;
|
|
388
419
|
get pid(): number | undefined;
|
|
389
420
|
get startedAt(): Date | undefined;
|
|
@@ -410,6 +441,33 @@ declare class PTYSession extends EventEmitter {
|
|
|
410
441
|
* Clear all session auto-response rules.
|
|
411
442
|
*/
|
|
412
443
|
clearAutoResponseRules(): void;
|
|
444
|
+
/**
|
|
445
|
+
* Start or reset the stall detection timer.
|
|
446
|
+
* Only active when status is "busy" and stall detection is enabled.
|
|
447
|
+
*/
|
|
448
|
+
private resetStallTimer;
|
|
449
|
+
/**
|
|
450
|
+
* Clear the stall detection timer.
|
|
451
|
+
*/
|
|
452
|
+
private clearStallTimer;
|
|
453
|
+
/**
|
|
454
|
+
* Called when the stall timer fires (no output for stallTimeoutMs).
|
|
455
|
+
*/
|
|
456
|
+
private onStallTimerFired;
|
|
457
|
+
/**
|
|
458
|
+
* Simple string hash for deduplication.
|
|
459
|
+
*/
|
|
460
|
+
private simpleHash;
|
|
461
|
+
/**
|
|
462
|
+
* Strip ANSI codes for stall detection output.
|
|
463
|
+
* Replaces cursor-forward sequences with spaces first.
|
|
464
|
+
*/
|
|
465
|
+
private stripAnsiForStall;
|
|
466
|
+
/**
|
|
467
|
+
* Handle external stall classification result.
|
|
468
|
+
* Called by the manager after onStallClassify resolves.
|
|
469
|
+
*/
|
|
470
|
+
handleStallClassification(classification: StallClassification | null): void;
|
|
413
471
|
/**
|
|
414
472
|
* Start the PTY session
|
|
415
473
|
*/
|
|
@@ -510,6 +568,7 @@ interface PTYManagerEvents {
|
|
|
510
568
|
blocking_prompt: (session: SessionHandle, promptInfo: BlockingPromptInfo, autoResponded: boolean) => void;
|
|
511
569
|
message: (message: SessionMessage) => void;
|
|
512
570
|
question: (session: SessionHandle, question: string) => void;
|
|
571
|
+
stall_detected: (session: SessionHandle, recentOutput: string, stallDurationMs: number) => void;
|
|
513
572
|
}
|
|
514
573
|
declare class PTYManager extends EventEmitter {
|
|
515
574
|
private sessions;
|
|
@@ -517,6 +576,9 @@ declare class PTYManager extends EventEmitter {
|
|
|
517
576
|
private maxLogLines;
|
|
518
577
|
private logger;
|
|
519
578
|
readonly adapters: AdapterRegistry;
|
|
579
|
+
private _stallDetectionEnabled;
|
|
580
|
+
private _stallTimeoutMs;
|
|
581
|
+
private _onStallClassify?;
|
|
520
582
|
constructor(config?: PTYManagerConfig);
|
|
521
583
|
/**
|
|
522
584
|
* Register a CLI adapter
|
|
@@ -581,6 +643,11 @@ declare class PTYManager extends EventEmitter {
|
|
|
581
643
|
* Get the underlying PTYSession (for advanced use)
|
|
582
644
|
*/
|
|
583
645
|
getSession(sessionId: string): PTYSession | undefined;
|
|
646
|
+
/**
|
|
647
|
+
* Configure stall detection at runtime.
|
|
648
|
+
* Affects newly spawned sessions only — existing sessions keep their config.
|
|
649
|
+
*/
|
|
650
|
+
configureStallDetection(enabled: boolean, timeoutMs?: number, classify?: (sessionId: string, recentOutput: string, stallDurationMs: number) => Promise<StallClassification | null>): void;
|
|
584
651
|
/**
|
|
585
652
|
* Add an auto-response rule to a session.
|
|
586
653
|
* Session rules are checked before adapter rules.
|
|
@@ -755,6 +822,15 @@ interface BunPTYManagerOptions {
|
|
|
755
822
|
* Example: ['coding-agent-adapters']
|
|
756
823
|
*/
|
|
757
824
|
adapterModules?: string[];
|
|
825
|
+
/** Enable stall detection (default: false) */
|
|
826
|
+
stallDetectionEnabled?: boolean;
|
|
827
|
+
/** Default stall timeout in ms (default: 8000) */
|
|
828
|
+
stallTimeoutMs?: number;
|
|
829
|
+
/**
|
|
830
|
+
* External classification callback invoked when a stall is detected.
|
|
831
|
+
* The worker emits stall_detected; this callback runs on the parent side.
|
|
832
|
+
*/
|
|
833
|
+
onStallClassify?: (sessionId: string, recentOutput: string, stallDurationMs: number) => Promise<StallClassification | null>;
|
|
758
834
|
}
|
|
759
835
|
/**
|
|
760
836
|
* PTY Manager that works with Bun and other non-Node runtimes
|
|
@@ -771,6 +847,9 @@ declare class BunCompatiblePTYManager extends EventEmitter {
|
|
|
771
847
|
private workerPath;
|
|
772
848
|
private env;
|
|
773
849
|
private adapterModules;
|
|
850
|
+
private _stallDetectionEnabled;
|
|
851
|
+
private _stallTimeoutMs;
|
|
852
|
+
private _onStallClassify?;
|
|
774
853
|
constructor(options?: BunPTYManagerOptions);
|
|
775
854
|
private findWorkerPath;
|
|
776
855
|
private startWorker;
|
|
@@ -869,4 +948,4 @@ declare function isBun(): boolean;
|
|
|
869
948
|
*/
|
|
870
949
|
declare function createPTYManager(options?: BunPTYManagerOptions): BunCompatiblePTYManager;
|
|
871
950
|
|
|
872
|
-
export { type AdapterFactoryConfig, AdapterRegistry, type AutoResponseRule, BaseCLIAdapter, type BlockingPromptDetection, type BlockingPromptInfo, type BlockingPromptType, BunCompatiblePTYManager, type BunPTYManagerOptions, type CLIAdapter, type LogOptions, type Logger, type LoginDetection, type MessageType, PTYManager, type PTYManagerConfig, type PTYManagerEvents, PTYSession, type PTYSessionEvents, type ParsedOutput, SPECIAL_KEYS, type SessionFilter, type SessionHandle, type SessionMessage, type SessionStatus, ShellAdapter, type ShellAdapterOptions, type SpawnConfig, type StopOptions, type TerminalAttachment, type WorkerSessionHandle, createAdapter, createPTYManager, isBun };
|
|
951
|
+
export { type AdapterFactoryConfig, AdapterRegistry, type AutoResponseRule, BaseCLIAdapter, type BlockingPromptDetection, type BlockingPromptInfo, type BlockingPromptType, BunCompatiblePTYManager, type BunPTYManagerOptions, type CLIAdapter, type LogOptions, type Logger, type LoginDetection, type MessageType, PTYManager, type PTYManagerConfig, type PTYManagerEvents, PTYSession, type PTYSessionEvents, type ParsedOutput, SPECIAL_KEYS, type SessionFilter, type SessionHandle, type SessionMessage, type SessionStatus, ShellAdapter, type ShellAdapterOptions, type SpawnConfig, type StallClassification, type StopOptions, type TerminalAttachment, type WorkerSessionHandle, createAdapter, createPTYManager, isBun };
|