telecoder 1.2.0 → 1.3.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.
- package/.env.example +142 -130
- package/CHANGELOG.md +683 -2
- package/README.md +36 -32
- package/dist/audio/transcribe.js +0 -9
- package/dist/bin/mcp-server.js +46 -61
- package/dist/bot/bot.js +162 -181
- package/dist/bot/command-catalog.js +263 -0
- package/dist/bot/deleted-threads.js +103 -0
- package/dist/bot/file-access.js +35 -26
- package/dist/bot/handlers/album.handler.js +128 -0
- package/dist/bot/handlers/{fork.handler.js → branch.handler.js} +267 -280
- package/dist/bot/handlers/command/access.js +1 -1
- package/dist/bot/handlers/command/admin.js +86 -110
- package/dist/bot/handlers/command/all-view.js +33 -0
- package/dist/bot/handlers/command/auto-approve.js +3 -3
- package/dist/bot/handlers/command/background.js +37 -0
- package/dist/bot/handlers/command/botname.js +76 -0
- package/dist/bot/handlers/command/btw.js +20 -69
- package/dist/bot/handlers/command/cleanup.js +329 -0
- package/dist/bot/handlers/command/model.js +40 -119
- package/dist/bot/handlers/command/prefs-scope.js +255 -90
- package/dist/bot/handlers/command/project.js +31 -109
- package/dist/bot/handlers/command/resume.js +8 -4
- package/dist/bot/handlers/command/session.js +74 -213
- package/dist/bot/handlers/command/settings.js +92 -447
- package/dist/bot/handlers/command/shared.js +32 -35
- package/dist/bot/handlers/command/tasks.js +263 -95
- package/dist/bot/handlers/command/thread.js +128 -0
- package/dist/bot/handlers/command/topic-store.js +14 -53
- package/dist/bot/handlers/command/topic.js +8 -61
- package/dist/bot/handlers/command/{cost.js → usage.js} +32 -59
- package/dist/bot/handlers/command-fallback.js +179 -0
- package/dist/bot/handlers/command.handler.js +96 -422
- package/dist/bot/handlers/{schedule.handler.js → loop.handler.js} +159 -73
- package/dist/bot/handlers/media-fallback.js +12 -7
- package/dist/bot/handlers/message/replies.js +10 -87
- package/dist/bot/handlers/message/shared.js +9 -31
- package/dist/bot/handlers/message/turn-notify.js +15 -49
- package/dist/bot/handlers/message/turn-runner.js +18 -103
- package/dist/bot/handlers/message.handler.js +59 -52
- package/dist/bot/handlers/newbot.handler.js +13 -4
- package/dist/bot/handlers/photo.handler.js +88 -129
- package/dist/bot/handlers/prompts.handler.js +11 -11
- package/dist/bot/handlers/running-note.js +2 -2
- package/dist/bot/handlers/session-guard.js +4 -4
- package/dist/bot/handlers/suggestion.handler.js +2 -2
- package/dist/bot/handlers/tree.handler.js +20 -20
- package/dist/bot/handlers/voice.handler.js +23 -85
- package/dist/bot/kept-threads.js +51 -0
- package/dist/bot/middleware/album-collector.js +69 -0
- package/dist/bot/middleware/auth.middleware.js +1 -1
- package/dist/bot/middleware/group-mention.middleware.js +11 -5
- package/dist/bot/middleware/queued-messages.js +143 -32
- package/dist/bot/middleware/stale-filter.js +0 -22
- package/dist/build-info.json +5 -5
- package/dist/claude/ask-user-form.js +517 -0
- package/dist/claude/ask-user.js +94 -26
- package/dist/claude/auto-topic-haiku.js +17 -0
- package/dist/claude/available-commands.js +22 -19
- package/dist/claude/background-hint.js +91 -0
- package/dist/claude/{fork-tree.js → branch-tree.js} +9 -9
- package/dist/claude/carry-over.js +0 -2
- package/dist/claude/ccr-shim.js +12 -10
- package/dist/claude/claude-auth.js +6 -10
- package/dist/claude/command-parser.js +49 -43
- package/dist/claude/cost-overlay-scraper.js +7 -2
- package/dist/claude/effort-level.js +5 -0
- package/dist/claude/enabled-plugins.js +12 -16
- package/dist/claude/in-flight-tracker.js +21 -0
- package/dist/claude/mcp-bridge.js +86 -58
- package/dist/claude/memory-guard.js +400 -0
- package/dist/claude/message-offsets.js +5 -5
- package/dist/claude/modal-relay.js +401 -34
- package/dist/claude/model-catalog.js +20 -3
- package/dist/claude/monitor-relay.js +130 -15
- package/dist/claude/native-commands.js +40 -0
- package/dist/claude/{pending-forks.js → pending-branches.js} +26 -26
- package/dist/claude/permission-gate.js +11 -10
- package/dist/claude/permission-mode.js +19 -45
- package/dist/claude/prewarm.js +70 -0
- package/dist/claude/pty-idle-reaper.js +96 -0
- package/dist/claude/pty-provider.js +473 -188
- package/dist/claude/pty-spawn-config.js +79 -32
- package/dist/claude/pty-watch.js +201 -0
- package/dist/claude/request-queue.js +7 -35
- package/dist/claude/rewind.js +111 -0
- package/dist/claude/scheduled-runner.js +1 -3
- package/dist/claude/scheduler.js +6 -2
- package/dist/claude/scope-guard.js +8 -3
- package/dist/claude/screen-marks.js +83 -0
- package/dist/claude/screen-render.js +96 -0
- package/dist/claude/session-history.js +4 -2
- package/dist/claude/session-jsonl.js +162 -15
- package/dist/claude/session-manager.js +29 -8
- package/dist/claude/session-move.js +70 -0
- package/dist/claude/shell-mode-gate.js +60 -0
- package/dist/claude/side-question.js +20 -17
- package/dist/claude/stage-images.js +5 -5
- package/dist/claude/tasks-overlay-scraper.js +143 -20
- package/dist/claude/thread-judge-haiku.js +88 -0
- package/dist/claude/tip-scraper.js +3 -4
- package/dist/claude/tui-modal.js +272 -27
- package/dist/claude/tui-state.js +74 -2
- package/dist/claude/turn-end.js +15 -1
- package/dist/claude/turn-prose.js +1 -1
- package/dist/claude/typed-answer.js +104 -0
- package/dist/claude/update-banner-relay.js +1 -1
- package/dist/cli/commands/doctor.js +48 -15
- package/dist/cli/commands/help.js +11 -2
- package/dist/cli/commands/init.js +16 -13
- package/dist/cli/commands/service.js +40 -8
- package/dist/cli/commands/start.js +10 -0
- package/dist/cli/commands/watch.js +322 -0
- package/dist/cli/dispatch.js +5 -0
- package/dist/cli/init/env-file.js +1 -1
- package/dist/cli/init/flow.js +114 -47
- package/dist/cli/init/prompter.js +8 -0
- package/dist/cli/init/telegram.js +35 -9
- package/dist/cli/service/render.js +3 -3
- package/dist/config.js +156 -131
- package/dist/index.js +107 -31
- package/dist/launcher.js +34 -7
- package/dist/providers/ccr-introspect.js +1 -8
- package/dist/providers/ccr-provider.js +19 -20
- package/dist/providers/claude-provider.js +4 -57
- package/dist/providers/prefs-sync.js +16 -59
- package/dist/providers/provider-router.js +24 -23
- package/dist/providers/spawn-settings.js +45 -0
- package/dist/providers/user-preferences.js +127 -19
- package/dist/restart-when-idle.js +27 -7
- package/dist/startup/auto-continue.js +2 -2
- package/dist/startup/auto-resume.js +3 -15
- package/dist/startup/notices.js +1 -1
- package/dist/startup/verify-token.js +4 -4
- package/dist/telegram/action-logger.js +3 -165
- package/dist/telegram/background-activity-card.js +1 -1
- package/dist/telegram/botname-settings.js +71 -125
- package/dist/telegram/client-options.js +6 -7
- package/dist/telegram/force-reply-tracker.js +55 -16
- package/dist/telegram/message-sender.js +92 -360
- package/dist/telegram/prompt-label.js +11 -5
- package/dist/telegram/streaming-turn.js +5 -7
- package/dist/telegram/table-lists.js +56 -0
- package/dist/telegram/task-list.js +4 -4
- package/dist/telegram/task-tracker.js +45 -126
- package/dist/telegram/terminal-renderer.js +1 -5
- package/dist/telegram/thread-titles.js +74 -2
- package/dist/telegram/threads-setup.js +1 -1
- package/dist/utils/admins.js +2 -2
- package/dist/utils/bot-icon.js +248 -0
- package/dist/utils/bot-token.js +8 -5
- package/dist/utils/build-info.js +3 -3
- package/dist/utils/caffeinate.js +6 -3
- package/dist/utils/claude-env.js +0 -1
- package/dist/utils/claude-version.js +2 -2
- package/dist/utils/config-home.js +3 -3
- package/dist/utils/download.js +41 -15
- package/dist/utils/exit-codes.js +11 -0
- package/dist/utils/format.js +3 -6
- package/dist/utils/home-project.js +1 -1
- package/dist/utils/idle-restart.js +1 -1
- package/dist/utils/install-mode.js +1 -1
- package/dist/utils/instance-config.js +1 -1
- package/dist/utils/instances.js +1 -1
- package/dist/utils/keyed-settings.js +2 -2
- package/dist/utils/memory-pressure.js +60 -0
- package/dist/utils/npm-version.js +2 -2
- package/dist/utils/resolve-claude-bin.js +13 -24
- package/dist/utils/respawn-backoff.js +9 -0
- package/dist/utils/stale-launcher.js +1 -1
- package/dist/utils/systemd.js +8 -8
- package/dist/utils/telegram-proxy.js +72 -0
- package/dist/utils/uploads-dir.js +27 -0
- package/dist/utils/verbosity.js +8 -8
- package/dist/utils/version-check.js +5 -5
- package/package.json +3 -4
- package/dist/bot/handlers/command/media.js +0 -197
- package/dist/bot/handlers/command/streaming-mode.js +0 -16
- package/dist/bot/handlers/message/throttle.js +0 -49
- package/dist/claude/agent-watchdog.js +0 -162
- package/dist/claude/agent.js +0 -1458
- package/dist/claude/held-query.js +0 -190
- package/dist/claude/mcp-tools.js +0 -354
- package/dist/claude/sdk-permission-gate.js +0 -77
- package/dist/claude/session-cost.js +0 -41
- package/dist/claude/system-prompt.js +0 -162
- package/dist/providers/sdk-provider.js +0 -37
- package/dist/telegram/telegraph-settings.js +0 -31
- package/dist/telegram/telegraph.js +0 -453
- package/dist/telegram/terminal-settings.js +0 -25
- package/dist/tts/tts-settings.js +0 -62
- package/dist/tts/tts.js +0 -245
- package/dist/tts/voice-reply.js +0 -78
- package/dist/utils/debug-agent.js +0 -117
- package/dist/utils/debug-watchdog.js +0 -121
- package/dist/utils/project-data-dir.js +0 -33
- package/dist/utils/reasoning-summary.js +0 -12
|
@@ -27,12 +27,24 @@
|
|
|
27
27
|
* dialog, it has moved it on. So the relay follows it ({@link relayDialog})
|
|
28
28
|
* until claude is back at its input box, offering each screen as it offered
|
|
29
29
|
* the first.
|
|
30
|
+
*
|
|
31
|
+
* And some of it is answered in words. A dialog with a text field (`/add-dir`,
|
|
32
|
+
* `/export`'s file name, `/config`'s search) takes a message typed into it,
|
|
33
|
+
* and a permission prompt takes one as the note that goes with No. Both are
|
|
34
|
+
* ordinary messages sent while the dialog is open, as a typed answer to
|
|
35
|
+
* telecoder_ask_user is (typed-answer.ts). See {@link typedInput}.
|
|
36
|
+
*
|
|
37
|
+
* A dialog with tabs is several dialogs behind one heading. `/permissions`
|
|
38
|
+
* keeps its allow, ask and deny rules on a tab each, and `/status` is the
|
|
39
|
+
* first tab of the dialog `/config` and `/usage` open further along. Each tab
|
|
40
|
+
* gets a button, and the relay does the walking there ({@link switchTab}).
|
|
30
41
|
*/
|
|
31
42
|
import * as path from 'path';
|
|
32
|
-
import { closeExpiredQuestion, createPendingQuestion, questionTimeoutMinutes } from './ask-user.js';
|
|
33
|
-
import { arrowsTo, keystrokeFor, parseModal } from './tui-modal.js';
|
|
43
|
+
import { closeAnsweredQuestion, closeExpiredQuestion, createPendingQuestion, questionTimeoutMinutes, resolvePendingQuestionWithText, } from './ask-user.js';
|
|
44
|
+
import { arrowsTo, keystrokeFor, parseModal, tabsOn, } from './tui-modal.js';
|
|
34
45
|
import { hasInputBox, screenSignature } from './tui-state.js';
|
|
35
|
-
import {
|
|
46
|
+
import { acceptTypedAnswers, acknowledgeTypedAnswer, shownTypedAnswer } from './typed-answer.js';
|
|
47
|
+
import { clip, EntityText } from '../telegram/entities.js';
|
|
36
48
|
import { parseSessionKey } from '../utils/session-key.js';
|
|
37
49
|
import { sanitizeError } from '../utils/sanitize.js';
|
|
38
50
|
/** Settle time after writing a key, before re-reading the screen. */
|
|
@@ -50,12 +62,25 @@ const ARROW_GAP_MS = 20;
|
|
|
50
62
|
const PRESS_POLL_MS = 100;
|
|
51
63
|
/** How long one arrow of a scroll gets to show up on screen before the scroll gives up. */
|
|
52
64
|
const REDRAW_MS = 500;
|
|
65
|
+
/** How long a tab gets to open after the arrow that asks for it. */
|
|
66
|
+
const TAB_SWITCH_MS = 1_500;
|
|
67
|
+
/**
|
|
68
|
+
* Most presses of ↓ spent getting a resting list to take the cursor. `/config`
|
|
69
|
+
* needs two from its tabs: one to the search box, one more to the list.
|
|
70
|
+
*/
|
|
71
|
+
const MAX_WAKE_STEPS = 3;
|
|
72
|
+
/** Tab buttons to a row. Their names are short, and a dialog can have six. */
|
|
73
|
+
const TABS_PER_ROW = 2;
|
|
53
74
|
/**
|
|
54
75
|
* Most rows offered as buttons: a whole screenful, which at 40 rows is about
|
|
55
76
|
* twenty. A list longer than that scrolls, and its scroll buttons reach the
|
|
56
77
|
* rest.
|
|
57
78
|
*/
|
|
58
79
|
const MAX_ROW_BUTTONS = 20;
|
|
80
|
+
/** The dialog on screen, read with everything the pty can say about it. */
|
|
81
|
+
function read(pty, screen = pty.screen()) {
|
|
82
|
+
return parseModal(screen, pty.marks?.());
|
|
83
|
+
}
|
|
59
84
|
/**
|
|
60
85
|
* The buttons a dialog earns. Numbered rows first, in the dialog's own order,
|
|
61
86
|
* then the footer keys that are answers rather than navigation — `Esc to
|
|
@@ -67,31 +92,65 @@ const MAX_ROW_BUTTONS = 20;
|
|
|
67
92
|
* gets a scroll button at each end it continues beyond, placed at that end,
|
|
68
93
|
* and each row it draws gets a button of its own. The cap of seven this used
|
|
69
94
|
* to have left `/mcp`'s 111-tool list reachable as far as its seventh tool.
|
|
95
|
+
*
|
|
96
|
+
* Tabs come first, one button for each the dialog isn't on. A lone `↓` in
|
|
97
|
+
* the footer is the way from the tabs into the list, and gets a button only
|
|
98
|
+
* while the list has no cursor to offer rows by. Once it has, a row's own
|
|
99
|
+
* button makes that step.
|
|
70
100
|
*/
|
|
71
101
|
export function buildChoices(modal) {
|
|
102
|
+
const tabs = (modal.tabs?.names ?? []).flatMap((name, index) => (index === modal.tabs.active ? [] : [{ kind: 'tab', label: `Tab: ${name}`, index }]));
|
|
72
103
|
const rows = [];
|
|
73
104
|
if (modal.highlighted >= 0) {
|
|
74
105
|
for (const option of modal.options.slice(0, MAX_ROW_BUTTONS)) {
|
|
75
106
|
const prefix = option.number === undefined ? '' : `${option.number}. `;
|
|
76
107
|
rows.push({ kind: 'row', label: `${prefix}${option.label}`, index: option.index });
|
|
77
108
|
}
|
|
109
|
+
// A list that only marks its edge doesn't say how much lies past it.
|
|
110
|
+
const count = (n) => (modal.more.uncounted ? '' : ` (${n} more)`);
|
|
78
111
|
if (modal.more.above > 0) {
|
|
79
|
-
rows.unshift({ kind: 'page', label: `↑ Scroll up
|
|
112
|
+
rows.unshift({ kind: 'page', label: `↑ Scroll up${count(modal.more.above)}`, direction: 'up' });
|
|
80
113
|
}
|
|
81
114
|
if (modal.more.below > 0) {
|
|
82
|
-
rows.push({ kind: 'page', label: `↓ Scroll down
|
|
115
|
+
rows.push({ kind: 'page', label: `↓ Scroll down${count(modal.more.below)}`, direction: 'down' });
|
|
83
116
|
}
|
|
84
117
|
}
|
|
85
118
|
const keys = [];
|
|
86
119
|
for (const hint of modal.hints) {
|
|
87
120
|
if (rows.length > 0 && /^Enter/.test(hint.key))
|
|
88
121
|
continue;
|
|
122
|
+
if (hint.key === '↓' && rows.length > 0)
|
|
123
|
+
continue;
|
|
89
124
|
const key = keystrokeFor(hint.key);
|
|
90
125
|
if (key === null)
|
|
91
126
|
continue;
|
|
92
127
|
keys.push({ kind: 'key', label: `${hint.key} — ${hint.action}`, key });
|
|
93
128
|
}
|
|
94
|
-
return [...rows, ...keys];
|
|
129
|
+
return [...tabs, ...rows, ...keys];
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* The buttons as Telegram lays them out: one to a row, except tabs, which sit
|
|
133
|
+
* side by side as they do in the dialog. `data` gives each button's callback
|
|
134
|
+
* by its index in `labels`.
|
|
135
|
+
*/
|
|
136
|
+
export function layOut(choices, labels, data) {
|
|
137
|
+
const rows = [];
|
|
138
|
+
let tabRow = null;
|
|
139
|
+
labels.forEach((text, index) => {
|
|
140
|
+
const button = { text, callback_data: data(index) };
|
|
141
|
+
if (choices[index]?.kind !== 'tab') {
|
|
142
|
+
tabRow = null;
|
|
143
|
+
rows.push([button]);
|
|
144
|
+
}
|
|
145
|
+
else if (tabRow && tabRow.length < TABS_PER_ROW) {
|
|
146
|
+
tabRow.push(button);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
tabRow = [button];
|
|
150
|
+
rows.push(tabRow);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
return rows;
|
|
95
154
|
}
|
|
96
155
|
/**
|
|
97
156
|
* The message above the buttons: claude's dialog, laid out for a phone.
|
|
@@ -126,14 +185,15 @@ function appendDialog(b, modal) {
|
|
|
126
185
|
b.pre(part.lines.join('\n'));
|
|
127
186
|
}
|
|
128
187
|
else if (part.kind === 'options') {
|
|
129
|
-
const { above, below } = modal.more;
|
|
188
|
+
const { above, below, uncounted } = modal.more;
|
|
189
|
+
const count = (n) => (uncounted ? 'more' : `${n} more`);
|
|
130
190
|
[
|
|
131
|
-
...(above > 0 ? [`↑ ${above}
|
|
191
|
+
...(above > 0 ? [`↑ ${count(above)}`] : []),
|
|
132
192
|
...modal.options.map((o) => {
|
|
133
193
|
const key = o.number === undefined ? '•' : `${o.number}.`;
|
|
134
194
|
return `${key} ${o.text}${o.detail ? ` — ${o.detail}` : ''}`;
|
|
135
195
|
}),
|
|
136
|
-
...(below > 0 ? [`↓ ${below}
|
|
196
|
+
...(below > 0 ? [`↓ ${count(below)}`] : []),
|
|
137
197
|
].forEach((row, n) => b.newline(n > 0 ? 1 : 0).add(row));
|
|
138
198
|
}
|
|
139
199
|
else {
|
|
@@ -145,10 +205,23 @@ function appendDialog(b, modal) {
|
|
|
145
205
|
b.bold(line);
|
|
146
206
|
else
|
|
147
207
|
b.add(line);
|
|
208
|
+
if (i === 0 && n === 0 && modal.tabs)
|
|
209
|
+
appendTabs(b.newline(), modal.tabs);
|
|
148
210
|
});
|
|
149
211
|
}
|
|
150
212
|
});
|
|
151
213
|
}
|
|
214
|
+
/** The dialog's tabs on one line, the open one in bold and brackets. */
|
|
215
|
+
function appendTabs(b, tabs) {
|
|
216
|
+
tabs.names.forEach((name, i) => {
|
|
217
|
+
if (i > 0)
|
|
218
|
+
b.add(' · ');
|
|
219
|
+
if (i === tabs.active)
|
|
220
|
+
b.bold(`[${name}]`);
|
|
221
|
+
else
|
|
222
|
+
b.add(name);
|
|
223
|
+
});
|
|
224
|
+
}
|
|
152
225
|
/**
|
|
153
226
|
* Why the turn stops at a dialog that is still open, for the chat.
|
|
154
227
|
*
|
|
@@ -183,14 +256,51 @@ export function openDialogError(dialog, stage) {
|
|
|
183
256
|
return `I stopped waiting on this turn — ${dialog.why}. Claude Code is still paused on that dialog.`;
|
|
184
257
|
}
|
|
185
258
|
}
|
|
186
|
-
/**
|
|
259
|
+
/**
|
|
260
|
+
* What a message typed while `modal` is open does there, or null when the
|
|
261
|
+
* dialog has no place for words.
|
|
262
|
+
*
|
|
263
|
+
* Keys typed at a dialog with no such place are keystrokes: at a permission
|
|
264
|
+
* prompt a digit picks a row. So a message is only ever typed where the
|
|
265
|
+
* dialog shows it takes text, and there are two such places.
|
|
266
|
+
*
|
|
267
|
+
* `field`: the dialog draws a text field. The message replaces what the field
|
|
268
|
+
* holds, and the dialog is relayed again as it then stands, with the path's
|
|
269
|
+
* completions or the settings the search left, for a tap to commit. Nothing is
|
|
270
|
+
* committed by typing.
|
|
271
|
+
*
|
|
272
|
+
* `note`: a permission prompt whose footer says `Tab to amend`. Tab turns the
|
|
273
|
+
* row under the cursor into `…, and tell Claude what to do next`, on Yes as
|
|
274
|
+
* much as on No. A message goes to No, never to the row the cursor starts on,
|
|
275
|
+
* which is Yes: someone who writes "don't, use the staging database" at a
|
|
276
|
+
* prompt has not approved the command it asks about. Yes with a note stays a
|
|
277
|
+
* tap on Yes and a message after it.
|
|
278
|
+
*/
|
|
279
|
+
export function typedInput(modal) {
|
|
280
|
+
if (modal.field)
|
|
281
|
+
return 'field';
|
|
282
|
+
const amends = modal.hints.some((hint) => hint.key === 'Tab' && /^amend\b/.test(hint.action));
|
|
283
|
+
return amends && refusalRow(modal) ? 'note' : null;
|
|
284
|
+
}
|
|
285
|
+
/** The row that says No and nothing else. */
|
|
286
|
+
function refusalRow(modal) {
|
|
287
|
+
return modal.options.find((option) => option.text === 'No');
|
|
288
|
+
}
|
|
289
|
+
/** What a tap does, what a message does, and what happens once either has. */
|
|
187
290
|
function closingLine(modal, stage) {
|
|
291
|
+
const typing = typedInput(modal);
|
|
292
|
+
const typed = typing === 'field'
|
|
293
|
+
? "✏️ Send a message and I'll type it into the field, then show you the dialog again."
|
|
294
|
+
: typing === 'note'
|
|
295
|
+
? '✏️ Or send a message saying what Claude should do instead. That answers No, with your note.'
|
|
296
|
+
: null;
|
|
188
297
|
if (buildChoices(modal).length === 0) {
|
|
189
|
-
return 'It offers no key I can press from here, so it needs someone at the terminal.';
|
|
298
|
+
return typed ?? 'It offers no key I can press from here, so it needs someone at the terminal.';
|
|
190
299
|
}
|
|
191
|
-
|
|
300
|
+
const tap = stage === 'before-prompt'
|
|
192
301
|
? "Tap your answer and I'll press it in Claude Code, then send your message."
|
|
193
302
|
: "Tap your answer and I'll press it in Claude Code so it can carry on.";
|
|
303
|
+
return typed ? `${tap}\n${typed}` : tap;
|
|
194
304
|
}
|
|
195
305
|
/**
|
|
196
306
|
* Relay the dialog on screen to the chat and press whatever comes back — one
|
|
@@ -202,52 +312,86 @@ function closingLine(modal, stage) {
|
|
|
202
312
|
* honest outcome and leaves the dialog for a person to deal with.
|
|
203
313
|
*/
|
|
204
314
|
export async function relayModal(pty, sessionKey, ctx, cwd, stage) {
|
|
205
|
-
const modal =
|
|
315
|
+
const modal = read(pty);
|
|
206
316
|
if (!modal)
|
|
207
317
|
return { kind: 'declined', why: 'the screen could not be read as a dialog' };
|
|
208
318
|
const choices = buildChoices(modal);
|
|
319
|
+
const typing = typedInput(modal);
|
|
209
320
|
const labels = [...choices.map((c) => c.label), '✋ Leave it alone'];
|
|
210
321
|
const message = buildModalMessage(modal, cwd, stage);
|
|
211
|
-
if (choices.length === 0) {
|
|
322
|
+
if (choices.length === 0 && !typing) {
|
|
212
323
|
await send(ctx, sessionKey, message, undefined);
|
|
213
324
|
return { kind: 'declined', why: 'the dialog offers no keys this bot can press' };
|
|
214
325
|
}
|
|
215
326
|
// Waits QUESTION_TIMEOUT_MINUTES, like any other question the turn asks.
|
|
216
327
|
const { id, promise } = createPendingQuestion(labels, undefined, sessionKey);
|
|
217
|
-
const keyboard =
|
|
328
|
+
const keyboard = layOut(choices, labels, (idx) => `q:${id}:${idx}`);
|
|
218
329
|
const { sent, entities } = await send(ctx, sessionKey, message, keyboard);
|
|
330
|
+
// A message sent now is for the dialog, when it has a place for one.
|
|
331
|
+
const stopTyped = typing
|
|
332
|
+
? acceptTypedAnswers({
|
|
333
|
+
sessionKey,
|
|
334
|
+
chatId: parseSessionKey(sessionKey).chatId,
|
|
335
|
+
messageId: sent.message_id,
|
|
336
|
+
take: async (msgCtx, text) => {
|
|
337
|
+
if (resolvePendingQuestionWithText(id, text, msgCtx.from?.id) !== 'resolved')
|
|
338
|
+
return false;
|
|
339
|
+
await acknowledgeTypedAnswer(msgCtx);
|
|
340
|
+
return true;
|
|
341
|
+
},
|
|
342
|
+
})
|
|
343
|
+
: undefined;
|
|
219
344
|
const answer = await promise;
|
|
345
|
+
stopTyped?.();
|
|
220
346
|
if (!answer) {
|
|
221
347
|
await closeExpiredQuestion(ctx.api, sent, message.text, `No answer within ${questionTimeoutMinutes()} min, so I left the dialog alone.`, entities);
|
|
222
348
|
return { kind: 'timeout' };
|
|
223
349
|
}
|
|
224
|
-
|
|
225
|
-
if (
|
|
350
|
+
// A tap closes its question in bot.ts; a typed answer has no tap to do it.
|
|
351
|
+
if (answer.typed) {
|
|
352
|
+
await closeAnsweredQuestion(ctx.api, sent, message.text, shownTypedAnswer(answer.label), entities);
|
|
353
|
+
}
|
|
354
|
+
const choice = answer.typed ? undefined : choices[answer.index];
|
|
355
|
+
if (!answer.typed && !choice)
|
|
226
356
|
return { kind: 'declined', why: 'you chose to leave it alone' };
|
|
227
357
|
// The tap can come minutes after the message went out. A key meant for this
|
|
228
358
|
// dialog means something else anywhere else — at the input box, `s` is a
|
|
229
359
|
// letter typed into the next message — so look again before pressing it.
|
|
230
360
|
const screen = pty.screen();
|
|
231
|
-
const current = hasInputBox(screen) ? null :
|
|
361
|
+
const current = hasInputBox(screen) ? null : read(pty, screen);
|
|
232
362
|
if (!current || !sameDialog(current, modal)) {
|
|
233
363
|
return { kind: 'failed', why: 'the dialog changed before your answer reached it' };
|
|
234
364
|
}
|
|
365
|
+
if (!choice) {
|
|
366
|
+
return typedInput(current) === 'field'
|
|
367
|
+
? typeIntoField(pty, current, answer.label)
|
|
368
|
+
: refuseWithNote(pty, current, answer.label);
|
|
369
|
+
}
|
|
235
370
|
if (choice.kind === 'key') {
|
|
236
371
|
pty.write(choice.key);
|
|
237
372
|
return { kind: 'answered', label: choice.label, dialog: current };
|
|
238
373
|
}
|
|
239
|
-
if (choice.kind === '
|
|
240
|
-
return
|
|
374
|
+
if (choice.kind === 'tab')
|
|
375
|
+
return switchTab(pty, current, choice.index, choice.label);
|
|
376
|
+
if (choice.kind === 'page') {
|
|
377
|
+
const awake = await wake(pty, current);
|
|
378
|
+
if ('kind' in awake)
|
|
379
|
+
return awake;
|
|
380
|
+
return awake.more.uncounted
|
|
381
|
+
? reveal(pty, awake, choice.direction, choice.label)
|
|
382
|
+
: scroll(pty, awake, choice.direction, choice.label);
|
|
383
|
+
}
|
|
241
384
|
return pressOption(pty, current, choice.index, choice.label);
|
|
242
385
|
}
|
|
243
386
|
/**
|
|
244
387
|
* True when two reads are of the same dialog, whatever has changed inside it.
|
|
245
388
|
* A row can be redrawn while the dialog waits for its answer without changing
|
|
246
|
-
* what that answer presses. A different heading, a different number of rows
|
|
247
|
-
*
|
|
389
|
+
* what that answer presses. A different heading, a different number of rows,
|
|
390
|
+
* different keys in the footer or another tab would.
|
|
248
391
|
*/
|
|
249
392
|
function sameDialog(a, b) {
|
|
250
|
-
return a.title === b.title && a.options.length === b.options.length && sameHints(a, b)
|
|
393
|
+
return a.title === b.title && a.options.length === b.options.length && sameHints(a, b)
|
|
394
|
+
&& a.tabs?.active === b.tabs?.active;
|
|
251
395
|
}
|
|
252
396
|
/** True when two reads show the dialog exactly as it was: same rows, same cursor, same keys. */
|
|
253
397
|
function drawnAlike(a, b) {
|
|
@@ -266,7 +410,20 @@ function sameHints(a, b) {
|
|
|
266
410
|
* asked is one where Enter commits an option nobody chose.
|
|
267
411
|
*/
|
|
268
412
|
async function pressOption(pty, modal, index, label) {
|
|
269
|
-
const
|
|
413
|
+
const landed = await walkTo(pty, modal, index);
|
|
414
|
+
if ('kind' in landed)
|
|
415
|
+
return landed;
|
|
416
|
+
pty.write('\r');
|
|
417
|
+
return { kind: 'answered', label, dialog: landed, option: modal.options[index] };
|
|
418
|
+
}
|
|
419
|
+
/** Walk the cursor to `index` and read the dialog back with it there, or say why it isn't. */
|
|
420
|
+
async function walkTo(pty, modal, index) {
|
|
421
|
+
// A list that isn't taking keys has to be given them before a walk along it
|
|
422
|
+
// can be counted.
|
|
423
|
+
const from = await wake(pty, modal);
|
|
424
|
+
if ('kind' in from)
|
|
425
|
+
return from;
|
|
426
|
+
const arrows = arrowsTo(from, index);
|
|
270
427
|
if (arrows === null)
|
|
271
428
|
return { kind: 'failed', why: 'the dialog\'s cursor position could not be read' };
|
|
272
429
|
for (const arrow of arrows) {
|
|
@@ -274,7 +431,7 @@ async function pressOption(pty, modal, index, label) {
|
|
|
274
431
|
await delay(ARROW_GAP_MS);
|
|
275
432
|
}
|
|
276
433
|
await delay(KEY_SETTLE_MS);
|
|
277
|
-
const landed =
|
|
434
|
+
const landed = read(pty);
|
|
278
435
|
if (!landed)
|
|
279
436
|
return { kind: 'failed', why: 'the dialog changed shape while being answered' };
|
|
280
437
|
// Which row the cursor is on is read off what the row says. A list that
|
|
@@ -286,17 +443,225 @@ async function pressOption(pty, modal, index, label) {
|
|
|
286
443
|
const wanted = modal.options[index];
|
|
287
444
|
const reached = landed.options[landed.highlighted];
|
|
288
445
|
const scrolled = landed.more.above !== modal.more.above || landed.more.below !== modal.more.below;
|
|
289
|
-
if (!reached || !sameRow(reached, wanted) || (!scrolled && landed.highlighted !== index)) {
|
|
446
|
+
if (!reached || landed.resting || !sameRow(reached, wanted) || (!scrolled && landed.highlighted !== index)) {
|
|
290
447
|
return {
|
|
291
448
|
kind: 'failed',
|
|
292
449
|
why: `the cursor stopped on "${reached?.label ?? 'no row'}", not "${wanted.label}"`,
|
|
293
450
|
};
|
|
294
451
|
}
|
|
295
|
-
|
|
296
|
-
|
|
452
|
+
return landed;
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Give a resting list the keys: ↓ until its cursor is drawn live.
|
|
456
|
+
*
|
|
457
|
+
* `/config` opens with its keys going to the search box and its list's cursor
|
|
458
|
+
* drawn grey on the first row. The first ↓ there moves to the list and leaves
|
|
459
|
+
* the cursor where it is, so a walk of three arrows to the fourth row ended
|
|
460
|
+
* on the third, and the row tapped was refused. From the dialog's tabs it is
|
|
461
|
+
* two presses, the search box being on the way. How many is read off the
|
|
462
|
+
* screen, not counted: the glyph turns from grey to its colour when the list
|
|
463
|
+
* has the keys.
|
|
464
|
+
*
|
|
465
|
+
* Returns the dialog as it then stands, which is `modal` itself for a list
|
|
466
|
+
* that was listening all along.
|
|
467
|
+
*/
|
|
468
|
+
async function wake(pty, modal) {
|
|
469
|
+
let now = modal;
|
|
470
|
+
for (let presses = 0; now.resting && presses < MAX_WAKE_STEPS; presses++) {
|
|
471
|
+
pty.write('\x1b[B');
|
|
472
|
+
await delay(KEY_SETTLE_MS);
|
|
473
|
+
const next = read(pty);
|
|
474
|
+
if (!next || next.highlighted < 0) {
|
|
475
|
+
return { kind: 'failed', why: 'the dialog changed shape while being answered' };
|
|
476
|
+
}
|
|
477
|
+
now = next;
|
|
478
|
+
}
|
|
479
|
+
return now.resting ? { kind: 'failed', why: 'the dialog\'s list didn\'t take the cursor' } : now;
|
|
480
|
+
}
|
|
481
|
+
/** True when ←/→ will move along the dialog's tabs as it stands. */
|
|
482
|
+
function tabsListening(modal) {
|
|
483
|
+
if (modal.hints.some((hint) => hint.key.startsWith('←/→') && /^switch\b/.test(hint.action)))
|
|
484
|
+
return true;
|
|
485
|
+
// A tab with nothing to pick (`/status`) names no arrows at all, and its
|
|
486
|
+
// tabs take them: there is nowhere else for them to go.
|
|
487
|
+
return modal.highlighted < 0 && !modal.hints.some((hint) => /[↑↓←→]/u.test(hint.key));
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* Open the tab at `index`: get the keys to the row of tabs, then step along
|
|
491
|
+
* it, watching each step land.
|
|
492
|
+
*
|
|
493
|
+
* Where ←/→ go depends on which part of the dialog has the keys. With them on
|
|
494
|
+
* a list or in a search box they do something else, or nothing, and the tabs
|
|
495
|
+
* are reached by going up: `/config` says `↑ to tabs` from its search box,
|
|
496
|
+
* which is itself one ↑ above the top of its list. So ↑ is pressed until the
|
|
497
|
+
* footer says the arrows switch tabs, for at most the rows above the cursor
|
|
498
|
+
* and the two steps past them. A list that wraps at its top never gets
|
|
499
|
+
* there, and the switch is given up with the cursor moved and nothing else.
|
|
500
|
+
*
|
|
501
|
+
* Then one arrow for each tab between here and there, never round the end,
|
|
502
|
+
* and each has to open the tab next to the last. A tab opens before its
|
|
503
|
+
* content has loaded, so the steps are checked on the row of tabs alone.
|
|
504
|
+
*/
|
|
505
|
+
async function switchTab(pty, modal, index, label) {
|
|
506
|
+
const failed = (why) => ({ kind: 'failed', why });
|
|
507
|
+
if (!modal.tabs || index < 0 || index >= modal.tabs.names.length) {
|
|
508
|
+
return failed('the dialog has no such tab');
|
|
509
|
+
}
|
|
510
|
+
let now = modal;
|
|
511
|
+
const climb = (now.highlighted >= 0 ? now.highlighted + now.more.above : 0) + 2;
|
|
512
|
+
for (let presses = 0; !tabsListening(now) && presses < climb; presses++) {
|
|
513
|
+
pty.write('\x1b[A');
|
|
514
|
+
const next = await redrawn(pty, now);
|
|
515
|
+
if (!next?.tabs)
|
|
516
|
+
return failed('the dialog\'s tabs couldn\'t be reached');
|
|
517
|
+
now = next;
|
|
518
|
+
}
|
|
519
|
+
if (!tabsListening(now) || !now.tabs)
|
|
520
|
+
return failed('the dialog\'s tabs couldn\'t be reached');
|
|
521
|
+
let at = now.tabs.active;
|
|
522
|
+
const arrow = index > at ? '\x1b[C' : '\x1b[D';
|
|
523
|
+
while (at !== index) {
|
|
524
|
+
const want = at + (index > at ? 1 : -1);
|
|
525
|
+
pty.write(arrow);
|
|
526
|
+
const opened = await tabOpened(pty, at);
|
|
527
|
+
if (opened !== want) {
|
|
528
|
+
return failed(`the dialog didn't open "${modal.tabs.names[want]}" when asked`);
|
|
529
|
+
}
|
|
530
|
+
at = want;
|
|
531
|
+
}
|
|
532
|
+
return { kind: 'answered', label, dialog: modal };
|
|
297
533
|
}
|
|
534
|
+
/** The tab that opened in place of `was`, or null if none did in time. */
|
|
535
|
+
async function tabOpened(pty, was) {
|
|
536
|
+
const deadline = Date.now() + TAB_SWITCH_MS;
|
|
537
|
+
while (Date.now() < deadline) {
|
|
538
|
+
await delay(ARROW_GAP_MS);
|
|
539
|
+
const tabs = tabsOn(pty.screen(), pty.marks?.());
|
|
540
|
+
if (tabs && tabs.active !== was)
|
|
541
|
+
return tabs.active;
|
|
542
|
+
}
|
|
543
|
+
return null;
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* True when two reads are of the same row. A numbered row can say more with
|
|
547
|
+
* the cursor on it than without: `/rewind` draws `4. Summarize from here`, and
|
|
548
|
+
* `4. Summarize from here: add context (optional)` once the cursor arrives. It
|
|
549
|
+
* is still row 4, so a row with a number matches when one text opens the other.
|
|
550
|
+
*/
|
|
298
551
|
function sameRow(a, b) {
|
|
299
|
-
|
|
552
|
+
if (a.number !== b.number)
|
|
553
|
+
return false;
|
|
554
|
+
if (a.text === b.text)
|
|
555
|
+
return true;
|
|
556
|
+
return a.number !== undefined && (a.text.startsWith(b.text) || b.text.startsWith(a.text));
|
|
557
|
+
}
|
|
558
|
+
/** What a message comes to as keys: one line, with nothing in it a terminal would act on. */
|
|
559
|
+
function keyable(text) {
|
|
560
|
+
return text.replace(/[\u0000-\u001f\u007f]+/g, ' ').replace(/\s+/g, ' ').trim();
|
|
561
|
+
}
|
|
562
|
+
/** The footer's `/ to search`: the list has the keys, and `/` hands them to the search box. */
|
|
563
|
+
function searchKey(hint) {
|
|
564
|
+
return hint.key === '/' && /^search\b/.test(hint.action);
|
|
565
|
+
}
|
|
566
|
+
/** How much of a typed message has to show up on screen to count as typed. */
|
|
567
|
+
const TYPED_NEEDLE = 16;
|
|
568
|
+
/**
|
|
569
|
+
* Type a message into the dialog's text field, in place of what it holds.
|
|
570
|
+
*
|
|
571
|
+
* Ctrl+U first: `/export` opens with a file name already in its field, and a
|
|
572
|
+
* name typed after it would be appended to it. On an empty field the press
|
|
573
|
+
* does nothing. Then the field is read back, because text that didn't arrive
|
|
574
|
+
* is a dialog about to be confirmed with something else in it. A field
|
|
575
|
+
* narrower than the text shows the end of it, so either end counts.
|
|
576
|
+
*
|
|
577
|
+
* Before any of it, the keys have to be going to the field. `/config` keeps
|
|
578
|
+
* them on its list once a row has been picked, and says `/ to search`.
|
|
579
|
+
*/
|
|
580
|
+
async function typeIntoField(pty, modal, text) {
|
|
581
|
+
const line = keyable(text);
|
|
582
|
+
if (!line)
|
|
583
|
+
return { kind: 'failed', why: 'the message had no text to type' };
|
|
584
|
+
// With the keys on a list, text is keys pressed at it, and `/config` reads
|
|
585
|
+
// Space as "change this setting". Where the footer names the key that moves
|
|
586
|
+
// to the search box, that comes first, and has to have worked.
|
|
587
|
+
if (modal.hints.some(searchKey)) {
|
|
588
|
+
pty.write('/');
|
|
589
|
+
await delay(KEY_SETTLE_MS);
|
|
590
|
+
const focused = read(pty);
|
|
591
|
+
if (!focused?.field || focused.hints.some(searchKey)) {
|
|
592
|
+
return { kind: 'failed', why: 'the dialog\'s search box didn\'t take the keys' };
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
pty.write('\x15');
|
|
596
|
+
await delay(KEY_SETTLE_MS);
|
|
597
|
+
pty.write(line);
|
|
598
|
+
await delay(KEY_SETTLE_MS);
|
|
599
|
+
const shown = read(pty)?.field?.value.replace(/\s+/g, ' ');
|
|
600
|
+
if (!shown || !(shown.includes(line.slice(0, TYPED_NEEDLE)) || shown.includes(line.slice(-TYPED_NEEDLE)))) {
|
|
601
|
+
return { kind: 'failed', why: 'the dialog\'s field didn\'t take the text' };
|
|
602
|
+
}
|
|
603
|
+
return { kind: 'answered', label: `typed “${clip(line, 40)}”`, dialog: modal };
|
|
604
|
+
}
|
|
605
|
+
/**
|
|
606
|
+
* Answer a permission prompt No, with a note: walk to No, Tab, type, Enter.
|
|
607
|
+
*
|
|
608
|
+
* Each step is read back before the next. Tab has to have turned the row into
|
|
609
|
+
* `No, and tell Claude what to do differently`, or the note would be typed at
|
|
610
|
+
* a list, where its letters and digits are keys. And the note has to be in the
|
|
611
|
+
* row before Enter, or Enter sends a bare No and the note is lost.
|
|
612
|
+
*/
|
|
613
|
+
async function refuseWithNote(pty, modal, text) {
|
|
614
|
+
const line = keyable(text);
|
|
615
|
+
const no = refusalRow(modal);
|
|
616
|
+
if (!line || !no)
|
|
617
|
+
return { kind: 'failed', why: 'this dialog has no place for a note' };
|
|
618
|
+
const landed = await walkTo(pty, modal, no.index);
|
|
619
|
+
if ('kind' in landed)
|
|
620
|
+
return landed;
|
|
621
|
+
pty.write('\t');
|
|
622
|
+
await delay(KEY_SETTLE_MS);
|
|
623
|
+
const amended = read(pty);
|
|
624
|
+
const field = amended?.options[amended.highlighted];
|
|
625
|
+
if (!amended || !field || field.number !== no.number || field.text === no.text || !/^No\b/.test(field.text)) {
|
|
626
|
+
return { kind: 'failed', why: 'the dialog didn\'t open a note on its No row' };
|
|
627
|
+
}
|
|
628
|
+
pty.write(line);
|
|
629
|
+
await delay(KEY_SETTLE_MS);
|
|
630
|
+
const typed = read(pty);
|
|
631
|
+
const row = typed?.options[typed.highlighted];
|
|
632
|
+
if (!typed || !row || row.number !== no.number || !row.text.includes(line.slice(0, TYPED_NEEDLE))) {
|
|
633
|
+
return { kind: 'failed', why: 'the dialog didn\'t take the note' };
|
|
634
|
+
}
|
|
635
|
+
pty.write('\r');
|
|
636
|
+
return { kind: 'answered', label: `No — ${clip(line, 40)}`, dialog: typed, option: no };
|
|
637
|
+
}
|
|
638
|
+
/**
|
|
639
|
+
* Bring one more row of a windowed list into view.
|
|
640
|
+
*
|
|
641
|
+
* A list that marks its edge with a bare arrow says only that it goes on, so
|
|
642
|
+
* there is no count to scroll by ({@link scroll}). Its window moves when the
|
|
643
|
+
* cursor steps past the edge row, one row a step. So: walk to the edge row,
|
|
644
|
+
* step once more, which the marker says is there to step to, and check the
|
|
645
|
+
* cursor is still on the edge with a new row under it. Then one step back.
|
|
646
|
+
* The cursor hides the marker of the row it is on, so with it left on the edge
|
|
647
|
+
* the next screen could not say whether the list goes on further.
|
|
648
|
+
*/
|
|
649
|
+
async function reveal(pty, modal, direction, label) {
|
|
650
|
+
const [on, back] = direction === 'down' ? ['\x1b[B', '\x1b[A'] : ['\x1b[A', '\x1b[B'];
|
|
651
|
+
const edgeOf = (m) => (direction === 'down' ? m.options.length - 1 : 0);
|
|
652
|
+
const atEdge = await walkTo(pty, modal, edgeOf(modal));
|
|
653
|
+
if ('kind' in atEdge)
|
|
654
|
+
return atEdge;
|
|
655
|
+
pty.write(on);
|
|
656
|
+
const shifted = await redrawn(pty, atEdge);
|
|
657
|
+
const was = atEdge.options[atEdge.highlighted];
|
|
658
|
+
const now = shifted?.options[shifted.highlighted];
|
|
659
|
+
if (!shifted || !now || !was || shifted.highlighted !== edgeOf(shifted) || sameRow(now, was)) {
|
|
660
|
+
return { kind: 'failed', why: 'the list didn\'t move on the way it said it would' };
|
|
661
|
+
}
|
|
662
|
+
pty.write(back);
|
|
663
|
+
await redrawn(pty, shifted);
|
|
664
|
+
return { kind: 'answered', label, dialog: modal };
|
|
300
665
|
}
|
|
301
666
|
/**
|
|
302
667
|
* Scroll a long list on by a screenful less one row. The one row is what
|
|
@@ -338,7 +703,7 @@ async function redrawn(pty, before) {
|
|
|
338
703
|
while (Date.now() < deadline) {
|
|
339
704
|
await delay(ARROW_GAP_MS);
|
|
340
705
|
const screen = pty.screen();
|
|
341
|
-
const next = hasInputBox(screen) ? null :
|
|
706
|
+
const next = hasInputBox(screen) ? null : read(pty, screen);
|
|
342
707
|
if (next && !drawnAlike(next, before))
|
|
343
708
|
return next;
|
|
344
709
|
}
|
|
@@ -355,10 +720,10 @@ async function redrawn(pty, before) {
|
|
|
355
720
|
* Split out from the caller because this is the judgement that decides whether
|
|
356
721
|
* a turn gets interrupted, and it is worth being able to point real screens at.
|
|
357
722
|
*/
|
|
358
|
-
export function blockingModal(screenText) {
|
|
723
|
+
export function blockingModal(screenText, marks) {
|
|
359
724
|
if (hasInputBox(screenText))
|
|
360
725
|
return null;
|
|
361
|
-
return parseModal(screenText);
|
|
726
|
+
return parseModal(screenText, marks);
|
|
362
727
|
}
|
|
363
728
|
/**
|
|
364
729
|
* Relay a dialog, and keep relaying it for as long as answering it leads on
|
|
@@ -378,13 +743,15 @@ export function blockingModal(screenText) {
|
|
|
378
743
|
* it alone", so the person answering decides when it ends.
|
|
379
744
|
*/
|
|
380
745
|
export async function relayDialog(pty, sessionKey, ctx, cwd, stage, timing) {
|
|
746
|
+
const steps = [];
|
|
381
747
|
for (;;) {
|
|
382
748
|
const outcome = await relayModal(pty, sessionKey, ctx, cwd, stage);
|
|
383
749
|
if (outcome.kind !== 'answered')
|
|
384
750
|
return outcome;
|
|
751
|
+
steps.push({ dialog: outcome.dialog, label: outcome.label, ...(outcome.option ? { option: outcome.option } : {}) });
|
|
385
752
|
const next = await afterPress(pty, outcome.dialog, timing);
|
|
386
753
|
if (next === 'closed')
|
|
387
|
-
return { kind: 'closed', label: outcome.label };
|
|
754
|
+
return { kind: 'closed', label: outcome.label, steps };
|
|
388
755
|
if (next === 'unchanged')
|
|
389
756
|
return { kind: 'still-open', label: outcome.label };
|
|
390
757
|
}
|
|
@@ -413,7 +780,7 @@ export async function afterPress(pty, pressed, timing) {
|
|
|
413
780
|
stillSince = Date.now();
|
|
414
781
|
}
|
|
415
782
|
else if (Date.now() - stillSince >= timing.settleMs) {
|
|
416
|
-
const modal =
|
|
783
|
+
const modal = read(pty, screen);
|
|
417
784
|
if (modal && !drawnAlike(modal, pressed))
|
|
418
785
|
return 'moved';
|
|
419
786
|
}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* The `--model` aliases Claude Code accepts, shared by every provider that
|
|
3
3
|
* ultimately spawns the CLI.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* The alias is handed to a `claude` binary as it is (`--model <alias>`), so
|
|
6
|
+
* the list belongs to the CLI, not to us — mirror `claude --help` here when
|
|
7
7
|
* upstream adds one. Aliases outside the CLI's own set are treated as literal
|
|
8
8
|
* API model names, which means a wrong entry fails at request time rather than
|
|
9
9
|
* at spawn.
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
import { getClaudeVersion, isAtLeast } from '../utils/claude-version.js';
|
|
12
12
|
export const CLAUDE_MODELS = [
|
|
13
13
|
{ id: 'fable', label: 'fable', description: 'Most capable — hardest, longest-running tasks' },
|
|
14
|
-
{ id: 'opus', label: 'opus', description: 'Most capable of the Opus tier
|
|
14
|
+
{ id: 'opus', label: 'opus', description: 'Most capable of the Opus tier' },
|
|
15
15
|
{ id: 'sonnet', label: 'sonnet', description: 'Balanced' },
|
|
16
16
|
{ id: 'haiku', label: 'haiku', description: 'Fast & light' },
|
|
17
17
|
{ id: 'opusplan', label: 'opusplan', description: 'Opus while planning, Sonnet otherwise' },
|
|
@@ -82,4 +82,21 @@ export function findModelUsageKey(modelUsage, model) {
|
|
|
82
82
|
?? keys.find((k) => k.startsWith(model) || model.startsWith(k.replace(/\[.*\]$/, '')))
|
|
83
83
|
?? keys[0];
|
|
84
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* The name a model id reads as in a sentence: `claude-fable-5-1` is
|
|
87
|
+
* "Fable 5.1", `anthropic/claude-opus-4-5@20251101` is "Opus 4.5" and
|
|
88
|
+
* `claude-3-5-haiku-20241022` is "Haiku 3.5". Anything that isn't a Claude id
|
|
89
|
+
* — a CCR backend such as `deepseek-reasoner` — comes back as it was, since
|
|
90
|
+
* that string is the one its vendor documents.
|
|
91
|
+
*/
|
|
92
|
+
export function describeModelId(model) {
|
|
93
|
+
const bare = model.slice(model.lastIndexOf('/') + 1).replace(/@\d{8}$/, '');
|
|
94
|
+
const m = /^claude-(?:(\d+)-(\d+)-)?([a-z]+)(?:-(\d+)(?:-(\d+))?)?(?:-\d{8})?$/.exec(bare);
|
|
95
|
+
if (!m)
|
|
96
|
+
return model;
|
|
97
|
+
const [, oldMajor, oldMinor, family, major, minor] = m;
|
|
98
|
+
const name = family.charAt(0).toUpperCase() + family.slice(1);
|
|
99
|
+
const version = [oldMajor ?? major, oldMinor ?? minor].filter(Boolean).join('.');
|
|
100
|
+
return version ? `${name} ${version}` : name;
|
|
101
|
+
}
|
|
85
102
|
//# sourceMappingURL=model-catalog.js.map
|