pty-manager 1.2.4 → 1.2.7
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 +77 -1
- package/dist/index.d.ts +77 -1
- package/dist/index.js +263 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +263 -7
- package/dist/index.mjs.map +1 -1
- package/dist/pty-worker.js +263 -5
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -379,6 +379,7 @@ declare class PTYSession extends EventEmitter {
|
|
|
379
379
|
private _lastActivityAt;
|
|
380
380
|
private messageCounter;
|
|
381
381
|
private logger;
|
|
382
|
+
private sessionRules;
|
|
382
383
|
readonly id: string;
|
|
383
384
|
readonly config: SpawnConfig;
|
|
384
385
|
constructor(adapter: CLIAdapter, config: SpawnConfig, logger?: Logger);
|
|
@@ -386,6 +387,28 @@ declare class PTYSession extends EventEmitter {
|
|
|
386
387
|
get pid(): number | undefined;
|
|
387
388
|
get startedAt(): Date | undefined;
|
|
388
389
|
get lastActivityAt(): Date | undefined;
|
|
390
|
+
/**
|
|
391
|
+
* Add an auto-response rule to this session.
|
|
392
|
+
* Session rules are checked before adapter rules.
|
|
393
|
+
*/
|
|
394
|
+
addAutoResponseRule(rule: AutoResponseRule): void;
|
|
395
|
+
/**
|
|
396
|
+
* Remove an auto-response rule by pattern.
|
|
397
|
+
* Returns true if a rule was removed.
|
|
398
|
+
*/
|
|
399
|
+
removeAutoResponseRule(pattern: RegExp): boolean;
|
|
400
|
+
/**
|
|
401
|
+
* Set all session auto-response rules, replacing existing ones.
|
|
402
|
+
*/
|
|
403
|
+
setAutoResponseRules(rules: AutoResponseRule[]): void;
|
|
404
|
+
/**
|
|
405
|
+
* Get all session auto-response rules.
|
|
406
|
+
*/
|
|
407
|
+
getAutoResponseRules(): AutoResponseRule[];
|
|
408
|
+
/**
|
|
409
|
+
* Clear all session auto-response rules.
|
|
410
|
+
*/
|
|
411
|
+
clearAutoResponseRules(): void;
|
|
389
412
|
/**
|
|
390
413
|
* Start the PTY session
|
|
391
414
|
*/
|
|
@@ -399,7 +422,8 @@ declare class PTYSession extends EventEmitter {
|
|
|
399
422
|
*/
|
|
400
423
|
private detectAndHandleBlockingPrompt;
|
|
401
424
|
/**
|
|
402
|
-
* Try to match and apply auto-response rules
|
|
425
|
+
* Try to match and apply auto-response rules.
|
|
426
|
+
* Session rules are checked first, then adapter rules.
|
|
403
427
|
*/
|
|
404
428
|
private tryAutoResponse;
|
|
405
429
|
/**
|
|
@@ -550,6 +574,28 @@ declare class PTYManager extends EventEmitter {
|
|
|
550
574
|
* Get the underlying PTYSession (for advanced use)
|
|
551
575
|
*/
|
|
552
576
|
getSession(sessionId: string): PTYSession | undefined;
|
|
577
|
+
/**
|
|
578
|
+
* Add an auto-response rule to a session.
|
|
579
|
+
* Session rules are checked before adapter rules.
|
|
580
|
+
*/
|
|
581
|
+
addAutoResponseRule(sessionId: string, rule: AutoResponseRule): void;
|
|
582
|
+
/**
|
|
583
|
+
* Remove an auto-response rule from a session by pattern.
|
|
584
|
+
* Returns true if a rule was removed.
|
|
585
|
+
*/
|
|
586
|
+
removeAutoResponseRule(sessionId: string, pattern: RegExp): boolean;
|
|
587
|
+
/**
|
|
588
|
+
* Set all auto-response rules for a session, replacing existing ones.
|
|
589
|
+
*/
|
|
590
|
+
setAutoResponseRules(sessionId: string, rules: AutoResponseRule[]): void;
|
|
591
|
+
/**
|
|
592
|
+
* Get all auto-response rules for a session.
|
|
593
|
+
*/
|
|
594
|
+
getAutoResponseRules(sessionId: string): AutoResponseRule[];
|
|
595
|
+
/**
|
|
596
|
+
* Clear all auto-response rules for a session.
|
|
597
|
+
*/
|
|
598
|
+
clearAutoResponseRules(sessionId: string): void;
|
|
553
599
|
}
|
|
554
600
|
|
|
555
601
|
/**
|
|
@@ -696,6 +742,12 @@ interface BunPTYManagerOptions {
|
|
|
696
742
|
workerPath?: string;
|
|
697
743
|
/** Environment variables for worker process */
|
|
698
744
|
env?: Record<string, string>;
|
|
745
|
+
/**
|
|
746
|
+
* Adapter modules to load in the worker process.
|
|
747
|
+
* Each module should export a `createAllAdapters()` function that returns an array of adapters.
|
|
748
|
+
* Example: ['coding-agent-adapters']
|
|
749
|
+
*/
|
|
750
|
+
adapterModules?: string[];
|
|
699
751
|
}
|
|
700
752
|
/**
|
|
701
753
|
* PTY Manager that works with Bun and other non-Node runtimes
|
|
@@ -711,6 +763,7 @@ declare class BunCompatiblePTYManager extends EventEmitter {
|
|
|
711
763
|
private nodePath;
|
|
712
764
|
private workerPath;
|
|
713
765
|
private env;
|
|
766
|
+
private adapterModules;
|
|
714
767
|
constructor(options?: BunPTYManagerOptions);
|
|
715
768
|
private findWorkerPath;
|
|
716
769
|
private startWorker;
|
|
@@ -768,6 +821,29 @@ declare class BunCompatiblePTYManager extends EventEmitter {
|
|
|
768
821
|
* Subscribe to output from a specific session
|
|
769
822
|
*/
|
|
770
823
|
onSessionData(id: string, callback: (data: string) => void): () => void;
|
|
824
|
+
private serializeRule;
|
|
825
|
+
/**
|
|
826
|
+
* Add an auto-response rule to a session.
|
|
827
|
+
* Session rules are checked before adapter rules.
|
|
828
|
+
*/
|
|
829
|
+
addAutoResponseRule(sessionId: string, rule: AutoResponseRule): Promise<void>;
|
|
830
|
+
/**
|
|
831
|
+
* Remove an auto-response rule from a session by pattern.
|
|
832
|
+
* Returns true if a rule was removed.
|
|
833
|
+
*/
|
|
834
|
+
removeAutoResponseRule(sessionId: string, pattern: RegExp): Promise<boolean>;
|
|
835
|
+
/**
|
|
836
|
+
* Set all auto-response rules for a session, replacing existing ones.
|
|
837
|
+
*/
|
|
838
|
+
setAutoResponseRules(sessionId: string, rules: AutoResponseRule[]): Promise<void>;
|
|
839
|
+
/**
|
|
840
|
+
* Get all auto-response rules for a session.
|
|
841
|
+
*/
|
|
842
|
+
getAutoResponseRules(sessionId: string): Promise<AutoResponseRule[]>;
|
|
843
|
+
/**
|
|
844
|
+
* Clear all auto-response rules for a session.
|
|
845
|
+
*/
|
|
846
|
+
clearAutoResponseRules(sessionId: string): Promise<void>;
|
|
771
847
|
/**
|
|
772
848
|
* Shutdown the worker and all sessions
|
|
773
849
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -379,6 +379,7 @@ declare class PTYSession extends EventEmitter {
|
|
|
379
379
|
private _lastActivityAt;
|
|
380
380
|
private messageCounter;
|
|
381
381
|
private logger;
|
|
382
|
+
private sessionRules;
|
|
382
383
|
readonly id: string;
|
|
383
384
|
readonly config: SpawnConfig;
|
|
384
385
|
constructor(adapter: CLIAdapter, config: SpawnConfig, logger?: Logger);
|
|
@@ -386,6 +387,28 @@ declare class PTYSession extends EventEmitter {
|
|
|
386
387
|
get pid(): number | undefined;
|
|
387
388
|
get startedAt(): Date | undefined;
|
|
388
389
|
get lastActivityAt(): Date | undefined;
|
|
390
|
+
/**
|
|
391
|
+
* Add an auto-response rule to this session.
|
|
392
|
+
* Session rules are checked before adapter rules.
|
|
393
|
+
*/
|
|
394
|
+
addAutoResponseRule(rule: AutoResponseRule): void;
|
|
395
|
+
/**
|
|
396
|
+
* Remove an auto-response rule by pattern.
|
|
397
|
+
* Returns true if a rule was removed.
|
|
398
|
+
*/
|
|
399
|
+
removeAutoResponseRule(pattern: RegExp): boolean;
|
|
400
|
+
/**
|
|
401
|
+
* Set all session auto-response rules, replacing existing ones.
|
|
402
|
+
*/
|
|
403
|
+
setAutoResponseRules(rules: AutoResponseRule[]): void;
|
|
404
|
+
/**
|
|
405
|
+
* Get all session auto-response rules.
|
|
406
|
+
*/
|
|
407
|
+
getAutoResponseRules(): AutoResponseRule[];
|
|
408
|
+
/**
|
|
409
|
+
* Clear all session auto-response rules.
|
|
410
|
+
*/
|
|
411
|
+
clearAutoResponseRules(): void;
|
|
389
412
|
/**
|
|
390
413
|
* Start the PTY session
|
|
391
414
|
*/
|
|
@@ -399,7 +422,8 @@ declare class PTYSession extends EventEmitter {
|
|
|
399
422
|
*/
|
|
400
423
|
private detectAndHandleBlockingPrompt;
|
|
401
424
|
/**
|
|
402
|
-
* Try to match and apply auto-response rules
|
|
425
|
+
* Try to match and apply auto-response rules.
|
|
426
|
+
* Session rules are checked first, then adapter rules.
|
|
403
427
|
*/
|
|
404
428
|
private tryAutoResponse;
|
|
405
429
|
/**
|
|
@@ -550,6 +574,28 @@ declare class PTYManager extends EventEmitter {
|
|
|
550
574
|
* Get the underlying PTYSession (for advanced use)
|
|
551
575
|
*/
|
|
552
576
|
getSession(sessionId: string): PTYSession | undefined;
|
|
577
|
+
/**
|
|
578
|
+
* Add an auto-response rule to a session.
|
|
579
|
+
* Session rules are checked before adapter rules.
|
|
580
|
+
*/
|
|
581
|
+
addAutoResponseRule(sessionId: string, rule: AutoResponseRule): void;
|
|
582
|
+
/**
|
|
583
|
+
* Remove an auto-response rule from a session by pattern.
|
|
584
|
+
* Returns true if a rule was removed.
|
|
585
|
+
*/
|
|
586
|
+
removeAutoResponseRule(sessionId: string, pattern: RegExp): boolean;
|
|
587
|
+
/**
|
|
588
|
+
* Set all auto-response rules for a session, replacing existing ones.
|
|
589
|
+
*/
|
|
590
|
+
setAutoResponseRules(sessionId: string, rules: AutoResponseRule[]): void;
|
|
591
|
+
/**
|
|
592
|
+
* Get all auto-response rules for a session.
|
|
593
|
+
*/
|
|
594
|
+
getAutoResponseRules(sessionId: string): AutoResponseRule[];
|
|
595
|
+
/**
|
|
596
|
+
* Clear all auto-response rules for a session.
|
|
597
|
+
*/
|
|
598
|
+
clearAutoResponseRules(sessionId: string): void;
|
|
553
599
|
}
|
|
554
600
|
|
|
555
601
|
/**
|
|
@@ -696,6 +742,12 @@ interface BunPTYManagerOptions {
|
|
|
696
742
|
workerPath?: string;
|
|
697
743
|
/** Environment variables for worker process */
|
|
698
744
|
env?: Record<string, string>;
|
|
745
|
+
/**
|
|
746
|
+
* Adapter modules to load in the worker process.
|
|
747
|
+
* Each module should export a `createAllAdapters()` function that returns an array of adapters.
|
|
748
|
+
* Example: ['coding-agent-adapters']
|
|
749
|
+
*/
|
|
750
|
+
adapterModules?: string[];
|
|
699
751
|
}
|
|
700
752
|
/**
|
|
701
753
|
* PTY Manager that works with Bun and other non-Node runtimes
|
|
@@ -711,6 +763,7 @@ declare class BunCompatiblePTYManager extends EventEmitter {
|
|
|
711
763
|
private nodePath;
|
|
712
764
|
private workerPath;
|
|
713
765
|
private env;
|
|
766
|
+
private adapterModules;
|
|
714
767
|
constructor(options?: BunPTYManagerOptions);
|
|
715
768
|
private findWorkerPath;
|
|
716
769
|
private startWorker;
|
|
@@ -768,6 +821,29 @@ declare class BunCompatiblePTYManager extends EventEmitter {
|
|
|
768
821
|
* Subscribe to output from a specific session
|
|
769
822
|
*/
|
|
770
823
|
onSessionData(id: string, callback: (data: string) => void): () => void;
|
|
824
|
+
private serializeRule;
|
|
825
|
+
/**
|
|
826
|
+
* Add an auto-response rule to a session.
|
|
827
|
+
* Session rules are checked before adapter rules.
|
|
828
|
+
*/
|
|
829
|
+
addAutoResponseRule(sessionId: string, rule: AutoResponseRule): Promise<void>;
|
|
830
|
+
/**
|
|
831
|
+
* Remove an auto-response rule from a session by pattern.
|
|
832
|
+
* Returns true if a rule was removed.
|
|
833
|
+
*/
|
|
834
|
+
removeAutoResponseRule(sessionId: string, pattern: RegExp): Promise<boolean>;
|
|
835
|
+
/**
|
|
836
|
+
* Set all auto-response rules for a session, replacing existing ones.
|
|
837
|
+
*/
|
|
838
|
+
setAutoResponseRules(sessionId: string, rules: AutoResponseRule[]): Promise<void>;
|
|
839
|
+
/**
|
|
840
|
+
* Get all auto-response rules for a session.
|
|
841
|
+
*/
|
|
842
|
+
getAutoResponseRules(sessionId: string): Promise<AutoResponseRule[]>;
|
|
843
|
+
/**
|
|
844
|
+
* Clear all auto-response rules for a session.
|
|
845
|
+
*/
|
|
846
|
+
clearAutoResponseRules(sessionId: string): Promise<void>;
|
|
771
847
|
/**
|
|
772
848
|
* Shutdown the worker and all sessions
|
|
773
849
|
*/
|
package/dist/index.js
CHANGED
|
@@ -321,6 +321,7 @@ var PTYSession = class extends import_events.EventEmitter {
|
|
|
321
321
|
_lastActivityAt = null;
|
|
322
322
|
messageCounter = 0;
|
|
323
323
|
logger;
|
|
324
|
+
sessionRules = [];
|
|
324
325
|
id;
|
|
325
326
|
config;
|
|
326
327
|
get status() {
|
|
@@ -335,6 +336,75 @@ var PTYSession = class extends import_events.EventEmitter {
|
|
|
335
336
|
get lastActivityAt() {
|
|
336
337
|
return this._lastActivityAt ?? void 0;
|
|
337
338
|
}
|
|
339
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
340
|
+
// Runtime Auto-Response Rules API
|
|
341
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
342
|
+
/**
|
|
343
|
+
* Add an auto-response rule to this session.
|
|
344
|
+
* Session rules are checked before adapter rules.
|
|
345
|
+
*/
|
|
346
|
+
addAutoResponseRule(rule) {
|
|
347
|
+
const existingIndex = this.sessionRules.findIndex(
|
|
348
|
+
(r) => r.pattern.source === rule.pattern.source && r.pattern.flags === rule.pattern.flags
|
|
349
|
+
);
|
|
350
|
+
if (existingIndex >= 0) {
|
|
351
|
+
this.sessionRules[existingIndex] = rule;
|
|
352
|
+
this.logger.debug(
|
|
353
|
+
{ sessionId: this.id, pattern: rule.pattern.source, type: rule.type },
|
|
354
|
+
"Replaced existing auto-response rule"
|
|
355
|
+
);
|
|
356
|
+
} else {
|
|
357
|
+
this.sessionRules.push(rule);
|
|
358
|
+
this.logger.debug(
|
|
359
|
+
{ sessionId: this.id, pattern: rule.pattern.source, type: rule.type },
|
|
360
|
+
"Added auto-response rule"
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Remove an auto-response rule by pattern.
|
|
366
|
+
* Returns true if a rule was removed.
|
|
367
|
+
*/
|
|
368
|
+
removeAutoResponseRule(pattern) {
|
|
369
|
+
const initialLength = this.sessionRules.length;
|
|
370
|
+
this.sessionRules = this.sessionRules.filter(
|
|
371
|
+
(r) => !(r.pattern.source === pattern.source && r.pattern.flags === pattern.flags)
|
|
372
|
+
);
|
|
373
|
+
const removed = this.sessionRules.length < initialLength;
|
|
374
|
+
if (removed) {
|
|
375
|
+
this.logger.debug(
|
|
376
|
+
{ sessionId: this.id, pattern: pattern.source },
|
|
377
|
+
"Removed auto-response rule"
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
return removed;
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Set all session auto-response rules, replacing existing ones.
|
|
384
|
+
*/
|
|
385
|
+
setAutoResponseRules(rules) {
|
|
386
|
+
this.sessionRules = [...rules];
|
|
387
|
+
this.logger.debug(
|
|
388
|
+
{ sessionId: this.id, count: rules.length },
|
|
389
|
+
"Set auto-response rules"
|
|
390
|
+
);
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Get all session auto-response rules.
|
|
394
|
+
*/
|
|
395
|
+
getAutoResponseRules() {
|
|
396
|
+
return [...this.sessionRules];
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Clear all session auto-response rules.
|
|
400
|
+
*/
|
|
401
|
+
clearAutoResponseRules() {
|
|
402
|
+
this.sessionRules = [];
|
|
403
|
+
this.logger.debug({ sessionId: this.id }, "Cleared auto-response rules");
|
|
404
|
+
}
|
|
405
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
406
|
+
// Lifecycle
|
|
407
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
338
408
|
/**
|
|
339
409
|
* Start the PTY session
|
|
340
410
|
*/
|
|
@@ -476,23 +546,27 @@ var PTYSession = class extends import_events.EventEmitter {
|
|
|
476
546
|
return false;
|
|
477
547
|
}
|
|
478
548
|
/**
|
|
479
|
-
* Try to match and apply auto-response rules
|
|
549
|
+
* Try to match and apply auto-response rules.
|
|
550
|
+
* Session rules are checked first, then adapter rules.
|
|
480
551
|
*/
|
|
481
552
|
tryAutoResponse() {
|
|
482
|
-
const
|
|
483
|
-
|
|
553
|
+
const adapterRules = this.adapter.autoResponseRules || [];
|
|
554
|
+
const allRules = [...this.sessionRules, ...adapterRules];
|
|
555
|
+
if (allRules.length === 0) {
|
|
484
556
|
return false;
|
|
485
557
|
}
|
|
486
|
-
for (const rule of
|
|
558
|
+
for (const rule of allRules) {
|
|
487
559
|
if (rule.pattern.test(this.outputBuffer)) {
|
|
488
560
|
const safe = rule.safe !== false;
|
|
561
|
+
const isSessionRule = this.sessionRules.includes(rule);
|
|
489
562
|
if (safe) {
|
|
490
563
|
this.logger.info(
|
|
491
564
|
{
|
|
492
565
|
sessionId: this.id,
|
|
493
566
|
promptType: rule.type,
|
|
494
567
|
description: rule.description,
|
|
495
|
-
response: rule.response
|
|
568
|
+
response: rule.response,
|
|
569
|
+
source: isSessionRule ? "session" : "adapter"
|
|
496
570
|
},
|
|
497
571
|
"Applying auto-response rule"
|
|
498
572
|
);
|
|
@@ -963,6 +1037,61 @@ var PTYManager = class extends import_events2.EventEmitter {
|
|
|
963
1037
|
getSession(sessionId) {
|
|
964
1038
|
return this.sessions.get(sessionId);
|
|
965
1039
|
}
|
|
1040
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
1041
|
+
// Runtime Auto-Response Rules API
|
|
1042
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
1043
|
+
/**
|
|
1044
|
+
* Add an auto-response rule to a session.
|
|
1045
|
+
* Session rules are checked before adapter rules.
|
|
1046
|
+
*/
|
|
1047
|
+
addAutoResponseRule(sessionId, rule) {
|
|
1048
|
+
const session = this.sessions.get(sessionId);
|
|
1049
|
+
if (!session) {
|
|
1050
|
+
throw new Error(`Session not found: ${sessionId}`);
|
|
1051
|
+
}
|
|
1052
|
+
session.addAutoResponseRule(rule);
|
|
1053
|
+
}
|
|
1054
|
+
/**
|
|
1055
|
+
* Remove an auto-response rule from a session by pattern.
|
|
1056
|
+
* Returns true if a rule was removed.
|
|
1057
|
+
*/
|
|
1058
|
+
removeAutoResponseRule(sessionId, pattern) {
|
|
1059
|
+
const session = this.sessions.get(sessionId);
|
|
1060
|
+
if (!session) {
|
|
1061
|
+
throw new Error(`Session not found: ${sessionId}`);
|
|
1062
|
+
}
|
|
1063
|
+
return session.removeAutoResponseRule(pattern);
|
|
1064
|
+
}
|
|
1065
|
+
/**
|
|
1066
|
+
* Set all auto-response rules for a session, replacing existing ones.
|
|
1067
|
+
*/
|
|
1068
|
+
setAutoResponseRules(sessionId, rules) {
|
|
1069
|
+
const session = this.sessions.get(sessionId);
|
|
1070
|
+
if (!session) {
|
|
1071
|
+
throw new Error(`Session not found: ${sessionId}`);
|
|
1072
|
+
}
|
|
1073
|
+
session.setAutoResponseRules(rules);
|
|
1074
|
+
}
|
|
1075
|
+
/**
|
|
1076
|
+
* Get all auto-response rules for a session.
|
|
1077
|
+
*/
|
|
1078
|
+
getAutoResponseRules(sessionId) {
|
|
1079
|
+
const session = this.sessions.get(sessionId);
|
|
1080
|
+
if (!session) {
|
|
1081
|
+
throw new Error(`Session not found: ${sessionId}`);
|
|
1082
|
+
}
|
|
1083
|
+
return session.getAutoResponseRules();
|
|
1084
|
+
}
|
|
1085
|
+
/**
|
|
1086
|
+
* Clear all auto-response rules for a session.
|
|
1087
|
+
*/
|
|
1088
|
+
clearAutoResponseRules(sessionId) {
|
|
1089
|
+
const session = this.sessions.get(sessionId);
|
|
1090
|
+
if (!session) {
|
|
1091
|
+
throw new Error(`Session not found: ${sessionId}`);
|
|
1092
|
+
}
|
|
1093
|
+
session.clearAutoResponseRules();
|
|
1094
|
+
}
|
|
966
1095
|
};
|
|
967
1096
|
|
|
968
1097
|
// src/adapters/base-adapter.ts
|
|
@@ -1049,7 +1178,7 @@ var BaseCLIAdapter = class {
|
|
|
1049
1178
|
instructions: "Please select a project or workspace"
|
|
1050
1179
|
};
|
|
1051
1180
|
}
|
|
1052
|
-
if (/\[y\/n\]|\(y\/n\)|\[Y\/n\]|\[y\/N\]
|
|
1181
|
+
if (/\[y\/n\]|\(y\/n\)|\[Y\/n\]|\[y\/N\]|\(Y\)es\/\(N\)o|Yes\/No\??/i.test(stripped)) {
|
|
1053
1182
|
return {
|
|
1054
1183
|
detected: true,
|
|
1055
1184
|
type: "unknown",
|
|
@@ -1057,7 +1186,49 @@ var BaseCLIAdapter = class {
|
|
|
1057
1186
|
// Last 200 chars for context
|
|
1058
1187
|
options: ["y", "n"],
|
|
1059
1188
|
canAutoRespond: false,
|
|
1060
|
-
instructions: "
|
|
1189
|
+
instructions: "Confirmation prompt detected"
|
|
1190
|
+
};
|
|
1191
|
+
}
|
|
1192
|
+
if (/^\s*[›>]?\s*[1-9]\.\s+\w+/m.test(stripped) && /\?\s*$/m.test(stripped)) {
|
|
1193
|
+
const optionMatches = stripped.match(/[›>]?\s*([1-9])\.\s+([^\n]+)/g);
|
|
1194
|
+
const options = optionMatches ? optionMatches.map((m) => m.replace(/^[›>\s]*/, "").trim()) : [];
|
|
1195
|
+
return {
|
|
1196
|
+
detected: true,
|
|
1197
|
+
type: "unknown",
|
|
1198
|
+
prompt: stripped.slice(-300),
|
|
1199
|
+
options: options.length > 0 ? options : void 0,
|
|
1200
|
+
canAutoRespond: false,
|
|
1201
|
+
instructions: "Menu selection prompt detected"
|
|
1202
|
+
};
|
|
1203
|
+
}
|
|
1204
|
+
if (/press enter|hit enter|enter to (confirm|continue|proceed)|press return/i.test(stripped)) {
|
|
1205
|
+
return {
|
|
1206
|
+
detected: true,
|
|
1207
|
+
type: "unknown",
|
|
1208
|
+
prompt: stripped.slice(-200),
|
|
1209
|
+
suggestedResponse: "\n",
|
|
1210
|
+
canAutoRespond: false,
|
|
1211
|
+
instructions: "Enter/confirm prompt detected"
|
|
1212
|
+
};
|
|
1213
|
+
}
|
|
1214
|
+
if (/trust|allow|permission|grant access/i.test(stripped) && /\?\s*$/m.test(stripped)) {
|
|
1215
|
+
return {
|
|
1216
|
+
detected: true,
|
|
1217
|
+
type: "permission",
|
|
1218
|
+
prompt: stripped.slice(-200),
|
|
1219
|
+
canAutoRespond: false,
|
|
1220
|
+
instructions: "Permission/trust prompt detected"
|
|
1221
|
+
};
|
|
1222
|
+
}
|
|
1223
|
+
const lines = stripped.split("\n").filter((l) => l.trim());
|
|
1224
|
+
const lastLine = lines[lines.length - 1] || "";
|
|
1225
|
+
if (/\?\s*$/.test(lastLine) && lastLine.length < 200) {
|
|
1226
|
+
return {
|
|
1227
|
+
detected: true,
|
|
1228
|
+
type: "unknown",
|
|
1229
|
+
prompt: lastLine.trim(),
|
|
1230
|
+
canAutoRespond: false,
|
|
1231
|
+
instructions: "Question prompt detected"
|
|
1061
1232
|
};
|
|
1062
1233
|
}
|
|
1063
1234
|
return { detected: false };
|
|
@@ -1338,11 +1509,13 @@ var BunCompatiblePTYManager = class extends import_events3.EventEmitter {
|
|
|
1338
1509
|
nodePath;
|
|
1339
1510
|
workerPath;
|
|
1340
1511
|
env;
|
|
1512
|
+
adapterModules;
|
|
1341
1513
|
constructor(options = {}) {
|
|
1342
1514
|
super();
|
|
1343
1515
|
this.nodePath = options.nodePath || "node";
|
|
1344
1516
|
this.workerPath = options.workerPath || this.findWorkerPath();
|
|
1345
1517
|
this.env = options.env || {};
|
|
1518
|
+
this.adapterModules = options.adapterModules || [];
|
|
1346
1519
|
this.readyPromise = new Promise((resolve) => {
|
|
1347
1520
|
this.readyResolve = resolve;
|
|
1348
1521
|
});
|
|
@@ -1401,6 +1574,9 @@ var BunCompatiblePTYManager = class extends import_events3.EventEmitter {
|
|
|
1401
1574
|
const id = event.id;
|
|
1402
1575
|
switch (eventType) {
|
|
1403
1576
|
case "worker_ready":
|
|
1577
|
+
if (this.adapterModules.length > 0) {
|
|
1578
|
+
this.sendCommand({ cmd: "registerAdapters", modules: this.adapterModules });
|
|
1579
|
+
}
|
|
1404
1580
|
this.ready = true;
|
|
1405
1581
|
this.readyResolve();
|
|
1406
1582
|
this.emit("ready");
|
|
@@ -1500,6 +1676,18 @@ var BunCompatiblePTYManager = class extends import_events3.EventEmitter {
|
|
|
1500
1676
|
this.resolvePending("list", sessions);
|
|
1501
1677
|
break;
|
|
1502
1678
|
}
|
|
1679
|
+
case "rules": {
|
|
1680
|
+
const serializedRules = event.rules;
|
|
1681
|
+
const rules = serializedRules.map((r) => ({
|
|
1682
|
+
pattern: new RegExp(r.pattern, r.flags || ""),
|
|
1683
|
+
type: r.type,
|
|
1684
|
+
response: r.response,
|
|
1685
|
+
description: r.description,
|
|
1686
|
+
safe: r.safe
|
|
1687
|
+
}));
|
|
1688
|
+
this.resolvePending(`getRules:${id}`, rules);
|
|
1689
|
+
break;
|
|
1690
|
+
}
|
|
1503
1691
|
case "ack": {
|
|
1504
1692
|
const cmd = event.cmd;
|
|
1505
1693
|
const success = event.success;
|
|
@@ -1637,6 +1825,74 @@ var BunCompatiblePTYManager = class extends import_events3.EventEmitter {
|
|
|
1637
1825
|
this.on(`data:${id}`, handler);
|
|
1638
1826
|
return () => this.off(`data:${id}`, handler);
|
|
1639
1827
|
}
|
|
1828
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
1829
|
+
// Runtime Auto-Response Rules API
|
|
1830
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
1831
|
+
serializeRule(rule) {
|
|
1832
|
+
return {
|
|
1833
|
+
pattern: rule.pattern.source,
|
|
1834
|
+
flags: rule.pattern.flags || void 0,
|
|
1835
|
+
type: rule.type,
|
|
1836
|
+
response: rule.response,
|
|
1837
|
+
description: rule.description,
|
|
1838
|
+
safe: rule.safe
|
|
1839
|
+
};
|
|
1840
|
+
}
|
|
1841
|
+
/**
|
|
1842
|
+
* Add an auto-response rule to a session.
|
|
1843
|
+
* Session rules are checked before adapter rules.
|
|
1844
|
+
*/
|
|
1845
|
+
async addAutoResponseRule(sessionId, rule) {
|
|
1846
|
+
await this.waitForReady();
|
|
1847
|
+
const serialized = this.serializeRule(rule);
|
|
1848
|
+
this.sendCommand({ cmd: "addRule", id: sessionId, rule: serialized });
|
|
1849
|
+
await this.createPending(`addRule:${sessionId}`);
|
|
1850
|
+
}
|
|
1851
|
+
/**
|
|
1852
|
+
* Remove an auto-response rule from a session by pattern.
|
|
1853
|
+
* Returns true if a rule was removed.
|
|
1854
|
+
*/
|
|
1855
|
+
async removeAutoResponseRule(sessionId, pattern) {
|
|
1856
|
+
await this.waitForReady();
|
|
1857
|
+
this.sendCommand({
|
|
1858
|
+
cmd: "removeRule",
|
|
1859
|
+
id: sessionId,
|
|
1860
|
+
pattern: pattern.source,
|
|
1861
|
+
flags: pattern.flags || void 0
|
|
1862
|
+
});
|
|
1863
|
+
try {
|
|
1864
|
+
await this.createPending(`removeRule:${sessionId}`);
|
|
1865
|
+
return true;
|
|
1866
|
+
} catch {
|
|
1867
|
+
return false;
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
/**
|
|
1871
|
+
* Set all auto-response rules for a session, replacing existing ones.
|
|
1872
|
+
*/
|
|
1873
|
+
async setAutoResponseRules(sessionId, rules) {
|
|
1874
|
+
await this.waitForReady();
|
|
1875
|
+
const serialized = rules.map((r) => this.serializeRule(r));
|
|
1876
|
+
this.sendCommand({ cmd: "setRules", id: sessionId, rules: serialized });
|
|
1877
|
+
await this.createPending(`setRules:${sessionId}`);
|
|
1878
|
+
}
|
|
1879
|
+
/**
|
|
1880
|
+
* Get all auto-response rules for a session.
|
|
1881
|
+
*/
|
|
1882
|
+
async getAutoResponseRules(sessionId) {
|
|
1883
|
+
await this.waitForReady();
|
|
1884
|
+
this.sendCommand({ cmd: "getRules", id: sessionId });
|
|
1885
|
+
const rules = await this.createPending(`getRules:${sessionId}`);
|
|
1886
|
+
return rules;
|
|
1887
|
+
}
|
|
1888
|
+
/**
|
|
1889
|
+
* Clear all auto-response rules for a session.
|
|
1890
|
+
*/
|
|
1891
|
+
async clearAutoResponseRules(sessionId) {
|
|
1892
|
+
await this.waitForReady();
|
|
1893
|
+
this.sendCommand({ cmd: "clearRules", id: sessionId });
|
|
1894
|
+
await this.createPending(`clearRules:${sessionId}`);
|
|
1895
|
+
}
|
|
1640
1896
|
/**
|
|
1641
1897
|
* Shutdown the worker and all sessions
|
|
1642
1898
|
*/
|