tg-claude 0.3.2 → 0.3.4
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/package.json +2 -3
- package/dist/claude/ClaudeProcess.d.ts +0 -83
- package/dist/claude/ClaudeProcess.d.ts.map +0 -1
- package/dist/claude/ClaudeProcess.js +0 -283
- package/dist/claude/ClaudeProcess.js.map +0 -1
- package/dist/claude/EventAdapter.d.ts +0 -45
- package/dist/claude/EventAdapter.d.ts.map +0 -1
- package/dist/claude/EventAdapter.js +0 -138
- package/dist/claude/EventAdapter.js.map +0 -1
- package/dist/claude/index.d.ts +0 -10
- package/dist/claude/index.d.ts.map +0 -1
- package/dist/claude/index.js +0 -9
- package/dist/claude/index.js.map +0 -1
- package/dist/claude/types.d.ts +0 -244
- package/dist/claude/types.d.ts.map +0 -1
- package/dist/claude/types.js +0 -8
- package/dist/claude/types.js.map +0 -1
- package/dist/env.d.ts +0 -21
- package/dist/env.d.ts.map +0 -1
- package/dist/env.js +0 -49
- package/dist/env.js.map +0 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -433
- package/dist/index.js.map +0 -1
- package/dist/parser/AnsiStripper.d.ts +0 -54
- package/dist/parser/AnsiStripper.d.ts.map +0 -1
- package/dist/parser/AnsiStripper.js +0 -115
- package/dist/parser/AnsiStripper.js.map +0 -1
- package/dist/parser/OptionExtractor.d.ts +0 -31
- package/dist/parser/OptionExtractor.d.ts.map +0 -1
- package/dist/parser/OptionExtractor.js +0 -91
- package/dist/parser/OptionExtractor.js.map +0 -1
- package/dist/parser/OutputParser.d.ts +0 -121
- package/dist/parser/OutputParser.d.ts.map +0 -1
- package/dist/parser/OutputParser.js +0 -306
- package/dist/parser/OutputParser.js.map +0 -1
- package/dist/parser/PromptDetector.d.ts +0 -20
- package/dist/parser/PromptDetector.d.ts.map +0 -1
- package/dist/parser/PromptDetector.js +0 -68
- package/dist/parser/PromptDetector.js.map +0 -1
- package/dist/parser/index.d.ts +0 -7
- package/dist/parser/index.d.ts.map +0 -1
- package/dist/parser/index.js +0 -5
- package/dist/parser/index.js.map +0 -1
- package/dist/parser/types.d.ts +0 -73
- package/dist/parser/types.d.ts.map +0 -1
- package/dist/parser/types.js +0 -2
- package/dist/parser/types.js.map +0 -1
- package/dist/pty/OutputBuffer.d.ts +0 -39
- package/dist/pty/OutputBuffer.d.ts.map +0 -1
- package/dist/pty/OutputBuffer.js +0 -55
- package/dist/pty/OutputBuffer.js.map +0 -1
- package/dist/pty/PtyProcess.d.ts +0 -47
- package/dist/pty/PtyProcess.d.ts.map +0 -1
- package/dist/pty/PtyProcess.js +0 -94
- package/dist/pty/PtyProcess.js.map +0 -1
- package/dist/pty/PtyService.d.ts +0 -55
- package/dist/pty/PtyService.d.ts.map +0 -1
- package/dist/pty/PtyService.js +0 -115
- package/dist/pty/PtyService.js.map +0 -1
- package/dist/pty/index.d.ts +0 -5
- package/dist/pty/index.d.ts.map +0 -1
- package/dist/pty/index.js +0 -4
- package/dist/pty/index.js.map +0 -1
- package/dist/pty/types.d.ts +0 -36
- package/dist/pty/types.d.ts.map +0 -1
- package/dist/pty/types.js +0 -2
- package/dist/pty/types.js.map +0 -1
- package/dist/router/BoundedQueue.d.ts +0 -57
- package/dist/router/BoundedQueue.d.ts.map +0 -1
- package/dist/router/BoundedQueue.js +0 -86
- package/dist/router/BoundedQueue.js.map +0 -1
- package/dist/router/EventRouter.d.ts +0 -103
- package/dist/router/EventRouter.d.ts.map +0 -1
- package/dist/router/EventRouter.js +0 -169
- package/dist/router/EventRouter.js.map +0 -1
- package/dist/router/index.d.ts +0 -13
- package/dist/router/index.d.ts.map +0 -1
- package/dist/router/index.js +0 -12
- package/dist/router/index.js.map +0 -1
- package/dist/router/types.d.ts +0 -104
- package/dist/router/types.d.ts.map +0 -1
- package/dist/router/types.js +0 -6
- package/dist/router/types.js.map +0 -1
- package/dist/setup/envWriter.d.ts +0 -22
- package/dist/setup/envWriter.d.ts.map +0 -1
- package/dist/setup/envWriter.js +0 -68
- package/dist/setup/envWriter.js.map +0 -1
- package/dist/setup/index.d.ts +0 -4
- package/dist/setup/index.d.ts.map +0 -1
- package/dist/setup/index.js +0 -4
- package/dist/setup/index.js.map +0 -1
- package/dist/setup/validators.d.ts +0 -22
- package/dist/setup/validators.d.ts.map +0 -1
- package/dist/setup/validators.js +0 -47
- package/dist/setup/validators.js.map +0 -1
- package/dist/setup/wizard.d.ts +0 -7
- package/dist/setup/wizard.d.ts.map +0 -1
- package/dist/setup/wizard.js +0 -56
- package/dist/setup/wizard.js.map +0 -1
- package/dist/telegram/TelegramBot.d.ts +0 -163
- package/dist/telegram/TelegramBot.d.ts.map +0 -1
- package/dist/telegram/TelegramBot.js +0 -634
- package/dist/telegram/TelegramBot.js.map +0 -1
- package/dist/telegram/index.d.ts +0 -7
- package/dist/telegram/index.d.ts.map +0 -1
- package/dist/telegram/index.js +0 -6
- package/dist/telegram/index.js.map +0 -1
- package/dist/telegram/types.d.ts +0 -30
- package/dist/telegram/types.d.ts.map +0 -1
- package/dist/telegram/types.js +0 -5
- package/dist/telegram/types.js.map +0 -1
- package/dist/terminal/TerminalInterface.d.ts +0 -61
- package/dist/terminal/TerminalInterface.d.ts.map +0 -1
- package/dist/terminal/TerminalInterface.js +0 -218
- package/dist/terminal/TerminalInterface.js.map +0 -1
- package/dist/terminal/index.d.ts +0 -3
- package/dist/terminal/index.d.ts.map +0 -1
- package/dist/terminal/index.js +0 -2
- package/dist/terminal/index.js.map +0 -1
- package/dist/terminal/types.d.ts +0 -17
- package/dist/terminal/types.d.ts.map +0 -1
- package/dist/terminal/types.js +0 -2
- package/dist/terminal/types.js.map +0 -1
package/dist/index.js
DELETED
|
@@ -1,433 +0,0 @@
|
|
|
1
|
-
// PTY imports commented out - replaced by ClaudeProcess
|
|
2
|
-
// import { PtyService, OutputBuffer } from './pty/index.js';
|
|
3
|
-
// import { OutputParser } from './parser/index.js';
|
|
4
|
-
import { loadEnv } from './env.js';
|
|
5
|
-
import { EventRouter } from './router/index.js';
|
|
6
|
-
import { TelegramBot } from './telegram/index.js';
|
|
7
|
-
import { ClaudeProcess, EventAdapter } from './claude/index.js';
|
|
8
|
-
import { TerminalInterface } from './terminal/index.js';
|
|
9
|
-
/**
|
|
10
|
-
* Escape HTML special characters for Telegram HTML mode
|
|
11
|
-
*/
|
|
12
|
-
function escapeHtml(text) {
|
|
13
|
-
return text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* CLI entry point using ClaudeProcess with stream-json output.
|
|
17
|
-
* Spawns Claude CLI as subprocess, parses JSON events, routes to Telegram.
|
|
18
|
-
* Supports multi-turn conversations via Telegram with --resume.
|
|
19
|
-
*/
|
|
20
|
-
// Package version for --version flag
|
|
21
|
-
const VERSION = '0.3.2';
|
|
22
|
-
// Detect sudo/root and exit early with fix instructions
|
|
23
|
-
if (process.getuid && process.getuid() === 0) {
|
|
24
|
-
console.error(`
|
|
25
|
-
Error: tg-claude cannot run as root/sudo.
|
|
26
|
-
|
|
27
|
-
Claude Code refuses to run with elevated privileges for security reasons.
|
|
28
|
-
|
|
29
|
-
To fix npm permission issues (so you don't need sudo):
|
|
30
|
-
|
|
31
|
-
sudo chown -R $(whoami) ~/.npm
|
|
32
|
-
|
|
33
|
-
Then run normally:
|
|
34
|
-
|
|
35
|
-
npx tg-claude "your prompt"
|
|
36
|
-
`);
|
|
37
|
-
process.exit(1);
|
|
38
|
-
}
|
|
39
|
-
// Load and validate environment variables
|
|
40
|
-
const env = loadEnv();
|
|
41
|
-
// Parse command line arguments
|
|
42
|
-
// Usage: tg-claude "Your prompt here"
|
|
43
|
-
const args = process.argv.slice(2);
|
|
44
|
-
// Check for --version / -v flag (before other processing)
|
|
45
|
-
if (args.includes('--version') || args.includes('-v')) {
|
|
46
|
-
console.log(VERSION);
|
|
47
|
-
process.exit(0);
|
|
48
|
-
}
|
|
49
|
-
// Check for --setup flag (before env loading)
|
|
50
|
-
if (args.includes('--setup')) {
|
|
51
|
-
const { setupWizard } = await import('./setup/index.js');
|
|
52
|
-
await setupWizard();
|
|
53
|
-
process.exit(0);
|
|
54
|
-
}
|
|
55
|
-
// Auto-trigger setup wizard if credentials missing and no args
|
|
56
|
-
if (!env.hasTelegram && args.length === 0) {
|
|
57
|
-
const { setupWizard } = await import('./setup/index.js');
|
|
58
|
-
await setupWizard();
|
|
59
|
-
console.log('\nNow run: npx tg-claude "your prompt"\n');
|
|
60
|
-
process.exit(0);
|
|
61
|
-
}
|
|
62
|
-
// Check for --help / -h flag (before other processing)
|
|
63
|
-
if (args.includes('--help') || args.includes('-h') || args.length === 0) {
|
|
64
|
-
console.log(`tg-claude - Control Claude Code from Telegram
|
|
65
|
-
|
|
66
|
-
Usage:
|
|
67
|
-
tg-claude [options] "Your prompt"
|
|
68
|
-
npx tg-claude [options] "Your prompt"
|
|
69
|
-
|
|
70
|
-
Options:
|
|
71
|
-
--setup Run setup wizard to configure Telegram credentials
|
|
72
|
-
--verbose Show additional logging
|
|
73
|
-
--debug Enable debug output
|
|
74
|
-
--quiet Suppress bridge logs, show only Claude output
|
|
75
|
-
--help, -h Show this help message
|
|
76
|
-
--version, -v Show version number
|
|
77
|
-
|
|
78
|
-
Environment Variables:
|
|
79
|
-
TELEGRAM_BOT_TOKEN Bot token from @BotFather (required)
|
|
80
|
-
TELEGRAM_USER_ID Your numeric user ID from @userinfobot (required)
|
|
81
|
-
|
|
82
|
-
Examples:
|
|
83
|
-
tg-claude "Fix the bug in app.js"
|
|
84
|
-
tg-claude --verbose "Explain this codebase"
|
|
85
|
-
npx tg-claude "Create a README"
|
|
86
|
-
|
|
87
|
-
Setup:
|
|
88
|
-
1. Message @BotFather on Telegram, send /newbot, copy the token
|
|
89
|
-
2. Message @userinfobot, copy your numeric ID
|
|
90
|
-
3. Set TELEGRAM_BOT_TOKEN and TELEGRAM_USER_ID
|
|
91
|
-
4. Run with your prompt
|
|
92
|
-
`);
|
|
93
|
-
process.exit(args.length === 0 ? 1 : 0);
|
|
94
|
-
}
|
|
95
|
-
// Check for --verbose flag
|
|
96
|
-
const verboseIndex = args.indexOf('--verbose');
|
|
97
|
-
const verbose = verboseIndex !== -1;
|
|
98
|
-
if (verbose) {
|
|
99
|
-
args.splice(verboseIndex, 1);
|
|
100
|
-
}
|
|
101
|
-
// Check for --debug flag
|
|
102
|
-
const debugIndex = args.indexOf('--debug');
|
|
103
|
-
const debug = debugIndex !== -1;
|
|
104
|
-
if (debug) {
|
|
105
|
-
args.splice(debugIndex, 1);
|
|
106
|
-
}
|
|
107
|
-
// Check for --quiet flag (suppress bridge logs, show only Claude output)
|
|
108
|
-
const quietIndex = args.indexOf('--quiet');
|
|
109
|
-
const quiet = quietIndex !== -1;
|
|
110
|
-
if (quiet) {
|
|
111
|
-
args.splice(quietIndex, 1);
|
|
112
|
-
}
|
|
113
|
-
// Logger that respects --quiet flag
|
|
114
|
-
const log = (message) => {
|
|
115
|
-
if (!quiet) {
|
|
116
|
-
// Write to stderr so it doesn't interfere with Claude's output on stdout
|
|
117
|
-
process.stderr.write(message + '\n');
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
const logWarn = (message) => {
|
|
121
|
-
// Warnings always show (but to stderr)
|
|
122
|
-
process.stderr.write(message + '\n');
|
|
123
|
-
};
|
|
124
|
-
// Prompt is required (help case already handled above)
|
|
125
|
-
if (args.length === 0) {
|
|
126
|
-
console.error('Error: No prompt provided. Run with --help for usage.');
|
|
127
|
-
process.exit(1);
|
|
128
|
-
}
|
|
129
|
-
// Join remaining args as prompt
|
|
130
|
-
const prompt = args.join(' ');
|
|
131
|
-
// Session ID for routing (single session demo)
|
|
132
|
-
const sessionId = 'demo-session';
|
|
133
|
-
// State for session resumption
|
|
134
|
-
let currentClaudeSessionId = null;
|
|
135
|
-
let isProcessing = false;
|
|
136
|
-
// Active process and adapter (for stdin responses to AskUserQuestion)
|
|
137
|
-
let activeClaudeProcess = null;
|
|
138
|
-
let activeAdapter = null;
|
|
139
|
-
// Create event router
|
|
140
|
-
const router = new EventRouter();
|
|
141
|
-
// Create terminal interface for dual-interface mode
|
|
142
|
-
const terminalInterface = new TerminalInterface({
|
|
143
|
-
router,
|
|
144
|
-
sessionId,
|
|
145
|
-
prompt: '> ',
|
|
146
|
-
});
|
|
147
|
-
// Create Telegram bot if credentials are provided
|
|
148
|
-
let telegramBot = null;
|
|
149
|
-
if (env.hasTelegram) {
|
|
150
|
-
telegramBot = new TelegramBot({
|
|
151
|
-
token: env.telegramBotToken,
|
|
152
|
-
allowedUserId: env.telegramUserId,
|
|
153
|
-
});
|
|
154
|
-
log('[TELEGRAM] Bot configured');
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
log('[TELEGRAM] Skipping - TELEGRAM_BOT_TOKEN or TELEGRAM_USER_ID not set');
|
|
158
|
-
}
|
|
159
|
-
// Wire up Telegram response handlers for session resumption
|
|
160
|
-
if (telegramBot) {
|
|
161
|
-
// Button click handler
|
|
162
|
-
telegramBot.onCallback = (callbackSessionId, optionIndex) => {
|
|
163
|
-
log(`[BRIDGE] Received button response: session=${callbackSessionId}, option=${optionIndex}`);
|
|
164
|
-
router.publishInbound({
|
|
165
|
-
sessionId: callbackSessionId,
|
|
166
|
-
type: 'response',
|
|
167
|
-
payload: { text: String(optionIndex), optionIndex },
|
|
168
|
-
timestamp: Date.now(),
|
|
169
|
-
source: 'telegram',
|
|
170
|
-
});
|
|
171
|
-
};
|
|
172
|
-
// Text message handler
|
|
173
|
-
telegramBot.onTextMessage = async (textSessionId, text) => {
|
|
174
|
-
log(`[BRIDGE] Received text response: session=${textSessionId}`);
|
|
175
|
-
// For GSD commands without active session, use the demo session
|
|
176
|
-
const effectiveSessionId = textSessionId === 'telegram-gsd' ? sessionId : textSessionId;
|
|
177
|
-
try {
|
|
178
|
-
router.publishInbound({
|
|
179
|
-
sessionId: effectiveSessionId,
|
|
180
|
-
type: 'response',
|
|
181
|
-
payload: { text, optionIndex: undefined },
|
|
182
|
-
timestamp: Date.now(),
|
|
183
|
-
source: 'telegram',
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
catch (error) {
|
|
187
|
-
// Propagate errors back to Telegram
|
|
188
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
189
|
-
log(`[BRIDGE] Error processing command: ${errorMessage}`);
|
|
190
|
-
// Send error notification to Telegram
|
|
191
|
-
await telegramBot.api.sendMessage(env.telegramUserId, `<b>Error:</b> ${telegramBot.escapeHtml(errorMessage)}`, { parse_mode: 'HTML' });
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
// Log router events
|
|
196
|
-
router.on('sessionCreated', (id) => log(`[ROUTER] Session created: ${id}`));
|
|
197
|
-
router.on('sessionDestroyed', (id) => log(`[ROUTER] Session destroyed: ${id}`));
|
|
198
|
-
router.on('outbound', async (event) => {
|
|
199
|
-
log(`[ROUTER] Outbound event: ${event.type} for session ${event.sessionId}`);
|
|
200
|
-
// Send Telegram notification for prompt events (AskUserQuestion)
|
|
201
|
-
if (event.type === 'prompt' && telegramBot) {
|
|
202
|
-
const promptPayload = event.payload;
|
|
203
|
-
await telegramBot.sendNotification({
|
|
204
|
-
sessionId: event.sessionId,
|
|
205
|
-
question: promptPayload.question,
|
|
206
|
-
options: promptPayload.options,
|
|
207
|
-
rawContext: promptPayload.rawContext,
|
|
208
|
-
multiSelect: promptPayload.multiSelect,
|
|
209
|
-
});
|
|
210
|
-
// Mark session as awaiting input after sending notification
|
|
211
|
-
telegramBot.setAwaitingInput(event.sessionId);
|
|
212
|
-
}
|
|
213
|
-
// Display prompt in terminal as well
|
|
214
|
-
if (event.type === 'prompt') {
|
|
215
|
-
const promptPayload = event.payload;
|
|
216
|
-
// Convert PromptOption (index, text) -> QuestionOption (label, description)
|
|
217
|
-
// PromptOption.text is already "Label - Description" format
|
|
218
|
-
terminalInterface.displayQuestion(promptPayload.question, promptPayload.options.map(opt => ({
|
|
219
|
-
label: opt.text, // Use full text as label (includes label - description)
|
|
220
|
-
description: '', // Already included in label
|
|
221
|
-
})), promptPayload.multiSelect ?? false);
|
|
222
|
-
}
|
|
223
|
-
// Send Telegram notification for completion events
|
|
224
|
-
if (event.type === 'completion' && telegramBot) {
|
|
225
|
-
const completionPayload = event.payload;
|
|
226
|
-
await telegramBot.sendCompletionNotification({
|
|
227
|
-
sessionId: event.sessionId,
|
|
228
|
-
summary: completionPayload.summary,
|
|
229
|
-
duration: completionPayload.duration,
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
// Set terminal awaiting input after completion
|
|
233
|
-
if (event.type === 'completion') {
|
|
234
|
-
terminalInterface.setAwaitingInput(true);
|
|
235
|
-
}
|
|
236
|
-
});
|
|
237
|
-
router.on('queueOverflow', (id, dir) => {
|
|
238
|
-
logWarn(`[ROUTER] Queue overflow: ${dir} for session ${id}`);
|
|
239
|
-
});
|
|
240
|
-
/**
|
|
241
|
-
* Wire a ClaudeProcess to EventAdapter and attach event handlers.
|
|
242
|
-
* Used for both initial process and resumed processes.
|
|
243
|
-
* Stores references to active process/adapter for stdin routing.
|
|
244
|
-
*/
|
|
245
|
-
function wireClaudeProcess(proc, routerRef, routeSessionId) {
|
|
246
|
-
const adapter = new EventAdapter(proc, routerRef, routeSessionId);
|
|
247
|
-
// Store active process/adapter for stdin responses
|
|
248
|
-
activeClaudeProcess = proc;
|
|
249
|
-
activeAdapter = adapter;
|
|
250
|
-
proc.on('init', (e) => {
|
|
251
|
-
currentClaudeSessionId = e.sessionId;
|
|
252
|
-
log(`[CLAUDE] Session started: ${e.sessionId}`);
|
|
253
|
-
log(`[CLAUDE] Model: ${e.model}`);
|
|
254
|
-
log(`[CLAUDE] Tools: ${e.tools.length} available`);
|
|
255
|
-
});
|
|
256
|
-
proc.on('text', (e) => {
|
|
257
|
-
process.stdout.write(e.text);
|
|
258
|
-
});
|
|
259
|
-
proc.on('tool_use', (e) => {
|
|
260
|
-
if (verbose) {
|
|
261
|
-
log(`[CLAUDE] Using tool: ${e.name}`);
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
proc.on('tool_result', (e) => {
|
|
265
|
-
if (verbose) {
|
|
266
|
-
const preview = e.result.slice(0, 100);
|
|
267
|
-
log(`[CLAUDE] Tool result: ${preview}${e.result.length > 100 ? '...' : ''}`);
|
|
268
|
-
}
|
|
269
|
-
});
|
|
270
|
-
proc.on('complete', (e) => {
|
|
271
|
-
log(`\n[CLAUDE] Complete: cost=$${e.cost.toFixed(4)}, duration=${Math.round(e.duration / 1000)}s`);
|
|
272
|
-
log(`[CLAUDE] Session ID for resume: ${e.sessionId}`);
|
|
273
|
-
isProcessing = false;
|
|
274
|
-
// Clear active process reference (process has finished)
|
|
275
|
-
if (activeClaudeProcess === proc) {
|
|
276
|
-
activeClaudeProcess = null;
|
|
277
|
-
}
|
|
278
|
-
telegramBot?.clearAwaitingInput();
|
|
279
|
-
});
|
|
280
|
-
proc.on('error', async (e) => {
|
|
281
|
-
console.error(`[CLAUDE] Error (${e.type}): ${e.message}`);
|
|
282
|
-
if (e.details) {
|
|
283
|
-
console.error('[CLAUDE] Details:', e.details);
|
|
284
|
-
}
|
|
285
|
-
isProcessing = false;
|
|
286
|
-
telegramBot?.clearAwaitingInput();
|
|
287
|
-
// Send error to Telegram
|
|
288
|
-
if (telegramBot && env.telegramUserId) {
|
|
289
|
-
await telegramBot.api.sendMessage(env.telegramUserId, `<b>Claude Error:</b> ${telegramBot.escapeHtml(e.message)}`, { parse_mode: 'HTML' });
|
|
290
|
-
}
|
|
291
|
-
});
|
|
292
|
-
return adapter;
|
|
293
|
-
}
|
|
294
|
-
// Handle inbound responses with session resumption
|
|
295
|
-
router.on('inbound', async (event) => {
|
|
296
|
-
log(`[ROUTER] Inbound event: ${event.type} for session ${event.sessionId}`);
|
|
297
|
-
if (event.type === 'response') {
|
|
298
|
-
const payload = event.payload;
|
|
299
|
-
log(`[BRIDGE] Processing response: "${payload.text.slice(0, 50)}..."`);
|
|
300
|
-
// Check if we're awaiting a question response (AskUserQuestion)
|
|
301
|
-
// If so, write to stdin of the active process instead of spawning new one
|
|
302
|
-
if (activeAdapter?.hasQuestion && activeClaudeProcess?.isRunning) {
|
|
303
|
-
log('[BRIDGE] Answering AskUserQuestion via stdin');
|
|
304
|
-
const written = activeClaudeProcess.writeStdin(payload.text);
|
|
305
|
-
if (written) {
|
|
306
|
-
log('[BRIDGE] Response written to stdin');
|
|
307
|
-
// Reset question state so next response spawns new process
|
|
308
|
-
activeAdapter.reset();
|
|
309
|
-
// Don't clear awaiting state - process will emit completion when done
|
|
310
|
-
return;
|
|
311
|
-
}
|
|
312
|
-
else {
|
|
313
|
-
log('[BRIDGE] Failed to write to stdin - falling through to spawn');
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
// Skip if already processing a request (and not answering a question)
|
|
317
|
-
if (isProcessing && !activeAdapter?.hasQuestion) {
|
|
318
|
-
log('[BRIDGE] Already processing - skipping response');
|
|
319
|
-
return;
|
|
320
|
-
}
|
|
321
|
-
// Create new ClaudeProcess with user's response as prompt
|
|
322
|
-
// Use --resume to continue conversation if sessionId available
|
|
323
|
-
const resumeProc = new ClaudeProcess({
|
|
324
|
-
cwd: process.cwd(),
|
|
325
|
-
prompt: payload.text,
|
|
326
|
-
sessionId: currentClaudeSessionId || undefined, // Resume if available
|
|
327
|
-
permissionMode: 'bypassPermissions',
|
|
328
|
-
});
|
|
329
|
-
// Wire EventAdapter for resumed process
|
|
330
|
-
wireClaudeProcess(resumeProc, router, sessionId);
|
|
331
|
-
isProcessing = true;
|
|
332
|
-
log(`[BRIDGE] Starting resumed ClaudeProcess${currentClaudeSessionId ? ` with session ${currentClaudeSessionId}` : ' (new session)'}`);
|
|
333
|
-
try {
|
|
334
|
-
await resumeProc.start();
|
|
335
|
-
log('[BRIDGE] Resumed ClaudeProcess completed');
|
|
336
|
-
// Re-enable awaiting state for subsequent follow-ups
|
|
337
|
-
telegramBot?.setAwaitingInput(sessionId);
|
|
338
|
-
terminalInterface.setAwaitingInput(true);
|
|
339
|
-
}
|
|
340
|
-
catch (err) {
|
|
341
|
-
console.error('[BRIDGE] Resume error:', err);
|
|
342
|
-
isProcessing = false;
|
|
343
|
-
telegramBot?.clearAwaitingInput();
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
});
|
|
347
|
-
// Bidirectional echo between interfaces
|
|
348
|
-
router.on('inbound', (event) => {
|
|
349
|
-
if (event.type !== 'response')
|
|
350
|
-
return;
|
|
351
|
-
const payload = event.payload;
|
|
352
|
-
// Echo terminal responses to Telegram
|
|
353
|
-
if (event.source === 'terminal' && telegramBot && env.telegramUserId) {
|
|
354
|
-
telegramBot.api.sendMessage(env.telegramUserId, `<i>[Terminal] ${escapeHtml(payload.text)}</i>`, { parse_mode: 'HTML' }).catch(err => log(`[ECHO] Telegram send failed: ${err}`));
|
|
355
|
-
}
|
|
356
|
-
// Echo Telegram responses to terminal
|
|
357
|
-
if (event.source === 'telegram') {
|
|
358
|
-
terminalInterface.displayNotification(`[Telegram] ${payload.text}`);
|
|
359
|
-
}
|
|
360
|
-
});
|
|
361
|
-
// Register session before spawning
|
|
362
|
-
router.registerSession(sessionId);
|
|
363
|
-
telegramBot?.registerSession(sessionId);
|
|
364
|
-
log('Starting Claude CLI with stream-json output...');
|
|
365
|
-
log(`Prompt: ${prompt.slice(0, 100)}${prompt.length > 100 ? '...' : ''}`);
|
|
366
|
-
if (verbose) {
|
|
367
|
-
log('Verbose mode: ON');
|
|
368
|
-
}
|
|
369
|
-
if (debug) {
|
|
370
|
-
log('Debug mode: ON');
|
|
371
|
-
}
|
|
372
|
-
if (quiet) {
|
|
373
|
-
log('Quiet mode: ON (bridge logs suppressed)');
|
|
374
|
-
}
|
|
375
|
-
// Create initial ClaudeProcess
|
|
376
|
-
const claudeProc = new ClaudeProcess({
|
|
377
|
-
cwd: process.cwd(),
|
|
378
|
-
prompt,
|
|
379
|
-
permissionMode: 'bypassPermissions',
|
|
380
|
-
});
|
|
381
|
-
// Wire EventAdapter and event handlers using shared helper
|
|
382
|
-
const adapter = wireClaudeProcess(claudeProc, router, sessionId);
|
|
383
|
-
isProcessing = true;
|
|
384
|
-
// Start Telegram bot if configured (long polling runs in parallel)
|
|
385
|
-
if (telegramBot) {
|
|
386
|
-
telegramBot.start().catch((err) => {
|
|
387
|
-
logWarn(`[TELEGRAM] Failed to start bot: ${err}`);
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
|
-
// Start ClaudeProcess and keep running for multi-turn
|
|
391
|
-
async function main() {
|
|
392
|
-
try {
|
|
393
|
-
await claudeProc.start();
|
|
394
|
-
log('[CLAUDE] Initial process completed');
|
|
395
|
-
// Mark both interfaces as awaiting input for follow-up messages
|
|
396
|
-
telegramBot?.setAwaitingInput(sessionId);
|
|
397
|
-
terminalInterface.setAwaitingInput(true);
|
|
398
|
-
log('[BRIDGE] Waiting for follow-up via Telegram or Terminal...');
|
|
399
|
-
log('[BRIDGE] Type response in terminal or use Telegram. Press Ctrl+C to exit');
|
|
400
|
-
// Keep the process alive for multi-turn conversations
|
|
401
|
-
// The process will continue running until user exits
|
|
402
|
-
await new Promise((resolve) => {
|
|
403
|
-
process.once('SIGINT', () => {
|
|
404
|
-
log('[BRIDGE] Shutting down...');
|
|
405
|
-
resolve();
|
|
406
|
-
});
|
|
407
|
-
process.once('SIGTERM', () => {
|
|
408
|
-
log('[BRIDGE] Shutting down...');
|
|
409
|
-
resolve();
|
|
410
|
-
});
|
|
411
|
-
});
|
|
412
|
-
}
|
|
413
|
-
catch (err) {
|
|
414
|
-
console.error('[CLAUDE] Fatal error:', err);
|
|
415
|
-
process.exit(1);
|
|
416
|
-
}
|
|
417
|
-
finally {
|
|
418
|
-
// Cleanup
|
|
419
|
-
terminalInterface.close();
|
|
420
|
-
telegramBot?.unregisterSession(sessionId);
|
|
421
|
-
router.unregisterSession(sessionId);
|
|
422
|
-
// Store session ID for potential future resume
|
|
423
|
-
const storedSessionId = adapter.lastSessionId;
|
|
424
|
-
if (storedSessionId) {
|
|
425
|
-
log(`[BRIDGE] Session stored for resume: ${storedSessionId}`);
|
|
426
|
-
}
|
|
427
|
-
// Give Telegram a moment to send any pending notifications
|
|
428
|
-
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
429
|
-
process.exit(0);
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
main();
|
|
433
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,6DAA6D;AAC7D,oDAAoD;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAIxD;;GAEG;AACH,SAAS,UAAU,CAAC,IAAY;IAC9B,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACjF,CAAC;AAED;;;;GAIG;AAEH,qCAAqC;AACrC,MAAM,OAAO,GAAG,OAAO,CAAC;AAExB,wDAAwD;AACxD,IAAI,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC;IAC7C,OAAO,CAAC,KAAK,CAAC;;;;;;;;;;;;CAYf,CAAC,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,0CAA0C;AAC1C,MAAM,GAAG,GAAG,OAAO,EAAE,CAAC;AAEtB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A2B,CAAC,CAAC;gBACjC,OAAO,EAAE,CAAC;YACZ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,uBAAuB,EAAE,GAAG,CAAC,CAAC;QAC5C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;YAAS,CAAC;QACT,UAAU;QACV,iBAAiB,CAAC,KAAK,EAAE,CAAC;QAC1B,WAAW,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAC;QAC1C,MAAM,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;QAEpC,+CAA+C;QAC/C,MAAM,eAAe,GAAG,OAAO,CAAC,aAAa,CAAC;QAC9C,IAAI,eAAe,EAAE,CAAC;YACpB,GAAG,CAAC,uCAAuC,eAAe,EAAE,CAAC,CAAC;QAChE,CAAC;QAED,2DAA2D;QAC3D,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;QACzD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC"}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type { ParsedChunk } from './types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Wrapper around strip-ansi that transforms raw PTY output
|
|
4
|
-
* into ParsedChunk objects with both raw and cleaned text.
|
|
5
|
-
*
|
|
6
|
-
* Also handles additional terminal control sequences that strip-ansi may miss.
|
|
7
|
-
*
|
|
8
|
-
* Supports two modes:
|
|
9
|
-
* 1. Instance methods (strip/parse): Buffered stripping for streaming chunks
|
|
10
|
-
* 2. Static method (stripComplete): One-shot stripping for complete text
|
|
11
|
-
*/
|
|
12
|
-
export declare class AnsiStripper {
|
|
13
|
-
private static readonly OSC_PATTERN;
|
|
14
|
-
private static readonly DCS_PATTERN;
|
|
15
|
-
private static readonly CONTROL_CHARS;
|
|
16
|
-
private static readonly INCOMPLETE_SEQUENCE;
|
|
17
|
-
private pendingBuffer;
|
|
18
|
-
/**
|
|
19
|
-
* Check if text ends with an incomplete escape sequence
|
|
20
|
-
*/
|
|
21
|
-
private hasIncompleteSequence;
|
|
22
|
-
/**
|
|
23
|
-
* Internal stripping logic (used by both instance and static methods)
|
|
24
|
-
*/
|
|
25
|
-
private static doStrip;
|
|
26
|
-
/**
|
|
27
|
-
* Strip ANSI escape sequences and control characters from raw terminal output.
|
|
28
|
-
* Buffers incomplete escape sequences across chunk boundaries.
|
|
29
|
-
*
|
|
30
|
-
* @param raw - Raw string potentially containing ANSI codes
|
|
31
|
-
* @returns Cleaned string with ANSI codes and control characters removed
|
|
32
|
-
*/
|
|
33
|
-
strip(raw: string): string;
|
|
34
|
-
/**
|
|
35
|
-
* Force-strip any remaining buffer (for session end)
|
|
36
|
-
* @returns Any remaining buffered content, stripped
|
|
37
|
-
*/
|
|
38
|
-
flush(): string;
|
|
39
|
-
/**
|
|
40
|
-
* Static method for one-shot stripping of complete text.
|
|
41
|
-
* Does NOT use instance buffering - ideal for already-accumulated text.
|
|
42
|
-
*
|
|
43
|
-
* @param text - Complete text to strip (e.g., rawContext)
|
|
44
|
-
* @returns Cleaned string with all ANSI codes removed
|
|
45
|
-
*/
|
|
46
|
-
static stripComplete(text: string): string;
|
|
47
|
-
/**
|
|
48
|
-
* Create a ParsedChunk from raw terminal data
|
|
49
|
-
* @param raw - Raw string from PTY onData event
|
|
50
|
-
* @returns ParsedChunk with raw, text, and timestamp
|
|
51
|
-
*/
|
|
52
|
-
parse(raw: string): ParsedChunk;
|
|
53
|
-
}
|
|
54
|
-
//# sourceMappingURL=AnsiStripper.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AnsiStripper.d.ts","sourceRoot":"","sources":["../../src/parser/AnsiStripper.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C;;;;;;;;;GASG;AACH,qBAAa,YAAY;IAGvB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAwC;IAG3E,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAA0B;IAI7D,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAuC;IAI5E,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAuB;IAGlE,OAAO,CAAC,aAAa,CAAM;IAE3B;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAI7B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,OAAO;IAyBtB;;;;;;OAMG;IACH,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAyB1B;;;OAGG;IACH,KAAK,IAAI,MAAM;IAMf;;;;;;OAMG;IACH,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAI1C;;;;OAIG;IACH,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW;CAOhC"}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import stripAnsi from 'strip-ansi';
|
|
2
|
-
/**
|
|
3
|
-
* Wrapper around strip-ansi that transforms raw PTY output
|
|
4
|
-
* into ParsedChunk objects with both raw and cleaned text.
|
|
5
|
-
*
|
|
6
|
-
* Also handles additional terminal control sequences that strip-ansi may miss.
|
|
7
|
-
*
|
|
8
|
-
* Supports two modes:
|
|
9
|
-
* 1. Instance methods (strip/parse): Buffered stripping for streaming chunks
|
|
10
|
-
* 2. Static method (stripComplete): One-shot stripping for complete text
|
|
11
|
-
*/
|
|
12
|
-
export class AnsiStripper {
|
|
13
|
-
// Pattern to match OSC (Operating System Command) sequences
|
|
14
|
-
// These are used for things like setting window title, hyperlinks, etc.
|
|
15
|
-
static OSC_PATTERN = /\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)/g;
|
|
16
|
-
// Pattern to match DCS (Device Control String) sequences
|
|
17
|
-
static DCS_PATTERN = /\x1bP[^\x1b]*\x1b\\/g;
|
|
18
|
-
// Pattern to match remaining control characters (except newline \n and tab \t)
|
|
19
|
-
// This includes carriage return \r which can cause text overwriting issues
|
|
20
|
-
static CONTROL_CHARS = /[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g;
|
|
21
|
-
// Pattern to detect incomplete escape sequences at end of string
|
|
22
|
-
// Matches: ESC alone, or ESC[ followed by digits/semicolons/colons without terminator
|
|
23
|
-
static INCOMPLETE_SEQUENCE = /\x1b(\[[\d;:]*)?$/;
|
|
24
|
-
// Buffer for incomplete escape sequences across chunks
|
|
25
|
-
pendingBuffer = '';
|
|
26
|
-
/**
|
|
27
|
-
* Check if text ends with an incomplete escape sequence
|
|
28
|
-
*/
|
|
29
|
-
hasIncompleteSequence(text) {
|
|
30
|
-
return AnsiStripper.INCOMPLETE_SEQUENCE.test(text);
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Internal stripping logic (used by both instance and static methods)
|
|
34
|
-
*/
|
|
35
|
-
static doStrip(text) {
|
|
36
|
-
let cleaned = text;
|
|
37
|
-
// First pass: strip ANSI sequences with strip-ansi
|
|
38
|
-
cleaned = stripAnsi(cleaned);
|
|
39
|
-
// Second pass: remove OSC sequences (strip-ansi might miss some)
|
|
40
|
-
cleaned = cleaned.replace(AnsiStripper.OSC_PATTERN, '');
|
|
41
|
-
// Third pass: remove DCS sequences
|
|
42
|
-
cleaned = cleaned.replace(AnsiStripper.DCS_PATTERN, '');
|
|
43
|
-
// Fourth pass: remove remaining control characters
|
|
44
|
-
// Keep \n (newline) and \t (tab) but remove \r (carriage return) etc.
|
|
45
|
-
cleaned = cleaned.replace(AnsiStripper.CONTROL_CHARS, '');
|
|
46
|
-
// Handle carriage return:
|
|
47
|
-
// - \r\n is a normal line ending, convert to \n
|
|
48
|
-
// - \r followed by text (not \n) means "overwrite", so remove text before \r
|
|
49
|
-
cleaned = cleaned.replace(/\r\n/g, '\n'); // Normalize line endings first
|
|
50
|
-
cleaned = cleaned.replace(/[^\n]*\r/g, ''); // Now handle actual overwrites
|
|
51
|
-
return cleaned;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Strip ANSI escape sequences and control characters from raw terminal output.
|
|
55
|
-
* Buffers incomplete escape sequences across chunk boundaries.
|
|
56
|
-
*
|
|
57
|
-
* @param raw - Raw string potentially containing ANSI codes
|
|
58
|
-
* @returns Cleaned string with ANSI codes and control characters removed
|
|
59
|
-
*/
|
|
60
|
-
strip(raw) {
|
|
61
|
-
// Prepend any pending buffer from previous chunk
|
|
62
|
-
const combined = this.pendingBuffer + raw;
|
|
63
|
-
this.pendingBuffer = '';
|
|
64
|
-
// Check if combined text has incomplete sequence at end
|
|
65
|
-
if (this.hasIncompleteSequence(combined)) {
|
|
66
|
-
// Find last newline - ANSI sequences don't span lines
|
|
67
|
-
const lastNewlineIdx = combined.lastIndexOf('\n');
|
|
68
|
-
if (lastNewlineIdx !== -1) {
|
|
69
|
-
// Split at newline: strip complete portion, buffer remainder
|
|
70
|
-
const completePortion = combined.slice(0, lastNewlineIdx + 1);
|
|
71
|
-
this.pendingBuffer = combined.slice(lastNewlineIdx + 1);
|
|
72
|
-
return AnsiStripper.doStrip(completePortion);
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
// No newline - buffer entire string
|
|
76
|
-
this.pendingBuffer = combined;
|
|
77
|
-
return '';
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
// No incomplete sequence - strip everything
|
|
81
|
-
return AnsiStripper.doStrip(combined);
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Force-strip any remaining buffer (for session end)
|
|
85
|
-
* @returns Any remaining buffered content, stripped
|
|
86
|
-
*/
|
|
87
|
-
flush() {
|
|
88
|
-
const remaining = this.pendingBuffer;
|
|
89
|
-
this.pendingBuffer = '';
|
|
90
|
-
return remaining ? AnsiStripper.doStrip(remaining) : '';
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Static method for one-shot stripping of complete text.
|
|
94
|
-
* Does NOT use instance buffering - ideal for already-accumulated text.
|
|
95
|
-
*
|
|
96
|
-
* @param text - Complete text to strip (e.g., rawContext)
|
|
97
|
-
* @returns Cleaned string with all ANSI codes removed
|
|
98
|
-
*/
|
|
99
|
-
static stripComplete(text) {
|
|
100
|
-
return AnsiStripper.doStrip(text);
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Create a ParsedChunk from raw terminal data
|
|
104
|
-
* @param raw - Raw string from PTY onData event
|
|
105
|
-
* @returns ParsedChunk with raw, text, and timestamp
|
|
106
|
-
*/
|
|
107
|
-
parse(raw) {
|
|
108
|
-
return {
|
|
109
|
-
raw,
|
|
110
|
-
text: this.strip(raw),
|
|
111
|
-
timestamp: Date.now(),
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
//# sourceMappingURL=AnsiStripper.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AnsiStripper.js","sourceRoot":"","sources":["../../src/parser/AnsiStripper.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,YAAY,CAAC;AAGnC;;;;;;;;;GASG;AACH,MAAM,OAAO,YAAY;IACvB,4DAA4D;IAC5D,wEAAwE;IAChE,MAAM,CAAU,WAAW,GAAG,oCAAoC,CAAC;IAE3E,yDAAyD;IACjD,MAAM,CAAU,WAAW,GAAG,sBAAsB,CAAC;IAE7D,+EAA+E;IAC/E,2EAA2E;IACnE,MAAM,CAAU,aAAa,GAAG,mCAAmC,CAAC;IAE5E,iEAAiE;IACjE,sFAAsF;IAC9E,MAAM,CAAU,mBAAmB,GAAG,mBAAmB,CAAC;IAElE,uDAAuD;IAC/C,aAAa,GAAG,EAAE,CAAC;IAE3B;;OAEG;IACK,qBAAqB,CAAC,IAAY;QACxC,OAAO,YAAY,CAAC,mBAAmB,CAAC,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AC;gBAC9D,IAAI,CAAC,aAAa,GAAG,QAAQ,CAAC,KAAK,CAAC,cAAc,GAAG,CAAC,CAAC,CAAC;gBACxD,OAAO,YAAY,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;YAC/C,CAAC;iBAAM,CAAC;gBACN,oCAAoC;gBACpC,IAAI,CAAC,aAAa,GAAG,QAAQ,CAAC;gBAC9B,OAAO,EAAE,CAAC;YACZ,CAAC;QACH,CAAC;QAED,4CAA4C;QAC5C,OAAO,YAAY,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACxC,CAAC;IAED;;;OAGG;IACH,KAAK;QACH,MAAM,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC;QACrC,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;QACxB,OAAO,SAAS,CAAC,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC1D,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,aAAa,CAAC,IAAY;QAC/B,OAAO,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,GAAW;QACf,OAAO;YACL,GAAG;YACH,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;YACrB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACtB,CAAC;IACJ,CAAC"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { PromptOption } from './types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Extracts numbered options from Claude Code prompt output.
|
|
4
|
-
* Handles various formats: "1. Text", "> 1. Text", "❯ 1. Text"
|
|
5
|
-
* Also handles TUI-style output where options may not be on separate lines.
|
|
6
|
-
*/
|
|
7
|
-
export declare class OptionExtractor {
|
|
8
|
-
private static readonly OPTION_PATTERN;
|
|
9
|
-
private static readonly GLOBAL_OPTION_PATTERN;
|
|
10
|
-
/**
|
|
11
|
-
* Extract all options from text.
|
|
12
|
-
* First tries line-by-line extraction, then falls back to global pattern.
|
|
13
|
-
* @param text - Cleaned text (ANSI stripped)
|
|
14
|
-
* @returns Array of PromptOption, empty if no options found
|
|
15
|
-
*/
|
|
16
|
-
extract(text: string): PromptOption[];
|
|
17
|
-
/**
|
|
18
|
-
* Extract options line by line (original approach).
|
|
19
|
-
*/
|
|
20
|
-
private extractFromLines;
|
|
21
|
-
/**
|
|
22
|
-
* Extract options using global regex (for TUI output without proper line breaks).
|
|
23
|
-
*/
|
|
24
|
-
private extractGlobal;
|
|
25
|
-
/**
|
|
26
|
-
* Check if text contains any extractable options.
|
|
27
|
-
* @param text - Cleaned text (ANSI stripped)
|
|
28
|
-
*/
|
|
29
|
-
hasOptions(text: string): boolean;
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=OptionExtractor.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"OptionExtractor.d.ts","sourceRoot":"","sources":["../../src/parser/OptionExtractor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C;;;;GAIG;AACH,qBAAa,eAAe;IAG1B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAmC;IAKzE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,qBAAqB,CACyC;IAEtF;;;;;OAKG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,EAAE;IAWrC;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAmBxB;;OAEG;IACH,OAAO,CAAC,aAAa;IA+BrB;;;OAGG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;CAWlC"}
|