@dmsdc-ai/aigentry-telepty 0.1.17 → 0.1.19
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/cli.js +41 -1
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -557,6 +557,11 @@ async function main() {
|
|
|
557
557
|
return manageInteractive();
|
|
558
558
|
}
|
|
559
559
|
|
|
560
|
+
if (cmd === '--version' || cmd === '-v' || cmd === 'version') {
|
|
561
|
+
console.log(pkg.version);
|
|
562
|
+
return;
|
|
563
|
+
}
|
|
564
|
+
|
|
560
565
|
if (cmd === 'update') {
|
|
561
566
|
console.log('\x1b[36m🔄 Updating telepty to the latest version...\x1b[0m');
|
|
562
567
|
try {
|
|
@@ -689,6 +694,28 @@ async function main() {
|
|
|
689
694
|
env: { ...process.env, TELEPTY_SESSION_ID: sessionId }
|
|
690
695
|
});
|
|
691
696
|
|
|
697
|
+
// Prompt-ready detection for safe inject delivery
|
|
698
|
+
const PROMPT_PATTERNS = {
|
|
699
|
+
claude: /[❯>]\s*$/,
|
|
700
|
+
gemini: /[❯>]\s*$/,
|
|
701
|
+
codex: /[❯>]\s*$/,
|
|
702
|
+
};
|
|
703
|
+
const cmdBase = path.basename(command).replace(/\..*$/, '');
|
|
704
|
+
const promptPattern = PROMPT_PATTERNS[cmdBase] || /[❯>$#%]\s*$/;
|
|
705
|
+
let promptReady = true; // assume ready initially for first inject
|
|
706
|
+
const injectQueue = [];
|
|
707
|
+
|
|
708
|
+
function flushInjectQueue() {
|
|
709
|
+
if (injectQueue.length === 0) return;
|
|
710
|
+
const batch = injectQueue.splice(0);
|
|
711
|
+
let delay = 0;
|
|
712
|
+
for (const item of batch) {
|
|
713
|
+
setTimeout(() => child.write(item), delay);
|
|
714
|
+
delay += item === '\r' ? 0 : 100;
|
|
715
|
+
}
|
|
716
|
+
promptReady = false;
|
|
717
|
+
}
|
|
718
|
+
|
|
692
719
|
// Connect to daemon WebSocket for inject reception and output relay
|
|
693
720
|
const wsUrl = `ws://${REMOTE_HOST}:${PORT}/api/sessions/${encodeURIComponent(sessionId)}?token=${encodeURIComponent(TOKEN)}`;
|
|
694
721
|
const daemonWs = new WebSocket(wsUrl);
|
|
@@ -703,7 +730,15 @@ async function main() {
|
|
|
703
730
|
try {
|
|
704
731
|
const msg = JSON.parse(message);
|
|
705
732
|
if (msg.type === 'inject') {
|
|
706
|
-
|
|
733
|
+
if (promptReady) {
|
|
734
|
+
child.write(msg.data);
|
|
735
|
+
// After writing prompt text (not \r), mark as not ready until next prompt
|
|
736
|
+
if (msg.data !== '\r' && msg.data.length > 1) {
|
|
737
|
+
promptReady = false;
|
|
738
|
+
}
|
|
739
|
+
} else {
|
|
740
|
+
injectQueue.push(msg.data);
|
|
741
|
+
}
|
|
707
742
|
} else if (msg.type === 'resize') {
|
|
708
743
|
child.resize(msg.cols, msg.rows);
|
|
709
744
|
}
|
|
@@ -741,6 +776,11 @@ async function main() {
|
|
|
741
776
|
if (wsReady && daemonWs.readyState === 1) {
|
|
742
777
|
daemonWs.send(JSON.stringify({ type: 'output', data }));
|
|
743
778
|
}
|
|
779
|
+
// Detect prompt in output to enable inject delivery
|
|
780
|
+
if (promptPattern.test(data)) {
|
|
781
|
+
promptReady = true;
|
|
782
|
+
flushInjectQueue();
|
|
783
|
+
}
|
|
744
784
|
});
|
|
745
785
|
|
|
746
786
|
// Handle child exit
|