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
|
@@ -6,24 +6,17 @@
|
|
|
6
6
|
* status block. They live here so the domain modules depend on one small
|
|
7
7
|
* shared surface instead of on each other.
|
|
8
8
|
*/
|
|
9
|
-
import * as fs from 'fs';
|
|
10
|
-
import * as path from 'path';
|
|
11
9
|
import { sessionManager } from '../../../claude/session-manager.js';
|
|
12
|
-
import {
|
|
10
|
+
import { envFilePath } from '../../../config.js';
|
|
11
|
+
import { getModel, getEffort, getActiveProviderName, } from '../../../providers/provider-router.js';
|
|
13
12
|
import { EntityText } from '../../../telegram/entities.js';
|
|
14
13
|
import { replyMarkdown } from '../../../telegram/send.js';
|
|
15
14
|
import { fitsOnButton } from '../../../telegram/button-text.js';
|
|
16
|
-
import {
|
|
17
|
-
import { getPtyProvider } from '../../../providers/claude-provider.js';
|
|
18
|
-
import { getSessionKeyFromCtx, parseSessionKey } from '../../../utils/session-key.js';
|
|
15
|
+
import { getSessionKeyFromCtx } from '../../../utils/session-key.js';
|
|
19
16
|
import { formatTimeAgo } from '../../../utils/format.js';
|
|
20
17
|
import { PACKAGE_ROOT } from '../../../utils/install-mode.js';
|
|
21
18
|
/** Repo root (the package root, in an npm install). */
|
|
22
19
|
export const PROJECT_ROOT = PACKAGE_ROOT;
|
|
23
|
-
export const BOTCTL_PATH = path.join(PROJECT_ROOT, 'scripts', 'telecoder-botctl.sh');
|
|
24
|
-
export function botctlExists() {
|
|
25
|
-
return fs.existsSync(BOTCTL_PATH);
|
|
26
|
-
}
|
|
27
20
|
/**
|
|
28
21
|
* Reply with standard markdown, sent as entities. For static text only: a
|
|
29
22
|
* dynamic part (a path, a name, an error) goes through an {@link EntityText}
|
|
@@ -54,6 +47,24 @@ export function buildFeatureDisabledMessage(feature) {
|
|
|
54
47
|
export async function replyFeatureDisabled(ctx, feature) {
|
|
55
48
|
await ctx.reply(buildFeatureDisabledMessage(feature));
|
|
56
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* What a voice note gets when no Groq key is set: how to turn
|
|
52
|
+
* transcription on, instead of a "Transcribing..." ack followed by a raw
|
|
53
|
+
* "GROQ_API_KEY not configured" error. Declining voice in `telecoder init` is
|
|
54
|
+
* the common case, so this is where most people learn how to add it later.
|
|
55
|
+
*/
|
|
56
|
+
export function buildVoiceNotSetUpMessage() {
|
|
57
|
+
return [
|
|
58
|
+
'🎤 Voice transcription is off: no Groq API key is set.',
|
|
59
|
+
'',
|
|
60
|
+
'To turn it on, get a key at https://console.groq.com/keys (Groq has a free tier), then either:',
|
|
61
|
+
'• run `telecoder init` again — it keeps your other answers and asks for the key, or',
|
|
62
|
+
`• add GROQ_API_KEY=gsk_... to ${envFilePath} and /botrestart.`,
|
|
63
|
+
].join('\n');
|
|
64
|
+
}
|
|
65
|
+
export async function replyVoiceNotSetUp(ctx) {
|
|
66
|
+
await ctx.reply(buildVoiceNotSetUpMessage());
|
|
67
|
+
}
|
|
57
68
|
export const EFFORT_LEVELS = [
|
|
58
69
|
{ id: 'low', label: '🐇 Low', description: 'Minimal thinking, fastest' },
|
|
59
70
|
{ id: 'medium', label: '⚖️ Medium', description: 'Balanced speed/quality' },
|
|
@@ -66,14 +77,22 @@ export function getEffortLabel(scope) {
|
|
|
66
77
|
const effort = getEffort(scope);
|
|
67
78
|
if (!effort)
|
|
68
79
|
return undefined;
|
|
69
|
-
return
|
|
80
|
+
return effortLevelLabel(effort);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The label for an effort level by name, for the one the session log reports
|
|
84
|
+
* when the chat set none itself. The CLI logs the API's four levels, so
|
|
85
|
+
* 'xhigh' never comes from there; a level this list doesn't know is shown as
|
|
86
|
+
* it was logged rather than dropped.
|
|
87
|
+
*/
|
|
88
|
+
export function effortLevelLabel(effort) {
|
|
89
|
+
return EFFORT_LEVELS.find((l) => l.id === effort)?.label
|
|
90
|
+
?? `🧠 ${effort.charAt(0).toUpperCase()}${effort.slice(1)}`;
|
|
70
91
|
}
|
|
71
92
|
/** Build status lines appended to project confirmation messages. */
|
|
72
93
|
export function projectStatusSuffix(sessionKey) {
|
|
73
|
-
const { chatId } = parseSessionKey(sessionKey);
|
|
74
94
|
const model = getModel(sessionKey);
|
|
75
95
|
const provider = getActiveProviderName(sessionKey);
|
|
76
|
-
const dangerous = isDangerousMode() ? '⚠️ ENABLED' : 'Disabled';
|
|
77
96
|
const session = sessionManager.getSession(sessionKey);
|
|
78
97
|
const created = session?.createdAt
|
|
79
98
|
? new Date(session.createdAt).toLocaleString()
|
|
@@ -85,7 +104,6 @@ export function projectStatusSuffix(sessionKey) {
|
|
|
85
104
|
.add('\n• ').bold('Model:').add(` ${model}`)
|
|
86
105
|
.add('\n• ').bold('Effort:').add(` ${effortLabel}`)
|
|
87
106
|
.add('\n• ').bold('Created:').add(` ${created}`)
|
|
88
|
-
.add('\n• ').bold('Dangerous Mode:').add(` ${dangerous}`)
|
|
89
107
|
.add('\n• ').bold('Session ID:').add(' ');
|
|
90
108
|
if (sessionId) {
|
|
91
109
|
suffix.code(sessionId);
|
|
@@ -181,27 +199,6 @@ export function withBackToPrevious(text, sessionKey, excludeConversationId) {
|
|
|
181
199
|
},
|
|
182
200
|
};
|
|
183
201
|
}
|
|
184
|
-
/**
|
|
185
|
-
* Settings that are read at PTY spawn time only take effect on a fresh spawn.
|
|
186
|
-
* Clearing the conversation makes the next message respawn with the new value,
|
|
187
|
-
* keeping the conversation itself intact. No-op for non-PTY providers.
|
|
188
|
-
*/
|
|
189
|
-
export function restartPtyForSettingChange(sessionKey) {
|
|
190
|
-
if (!needsPtyRestart(sessionKey))
|
|
191
|
-
return false;
|
|
192
|
-
getPtyProvider().clearConversation(sessionKey);
|
|
193
|
-
return true;
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Whether a spawn-time setting change would need a pty restart here —
|
|
197
|
-
* the same test restartPtyForSettingChange makes, without doing it. For
|
|
198
|
-
* rebuilding a confirmation whose restart already happened.
|
|
199
|
-
*/
|
|
200
|
-
export function needsPtyRestart(scope) {
|
|
201
|
-
if (getActiveProviderName(scope) !== 'claude')
|
|
202
|
-
return false;
|
|
203
|
-
return userPreferences.getMethod(scope) === 'pty';
|
|
204
|
-
}
|
|
205
202
|
/** Note appended when a pty restart is pending. */
|
|
206
203
|
export const PTY_RESTART_NOTE = new EntityText()
|
|
207
204
|
.add('\n\n')
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
* /tasks and /shells — inspecting what the agent is running.
|
|
3
3
|
*
|
|
4
4
|
* Grouped because both are read-only views over live process state with the
|
|
5
|
-
* same list/detail inline-keyboard shape: /tasks over the
|
|
5
|
+
* same list/detail inline-keyboard shape: /tasks over the task tracker,
|
|
6
6
|
* /shells over the pty's real child processes.
|
|
7
7
|
*/
|
|
8
8
|
import { EntityText } from '../../../telegram/entities.js';
|
|
9
9
|
import { replyFormatted, editCallbackMessage } from '../../../telegram/send.js';
|
|
10
10
|
import { taskTracker } from '../../../telegram/task-tracker.js';
|
|
11
11
|
import { getPtyProvider } from '../../../providers/claude-provider.js';
|
|
12
|
-
import { scrapeTasksOverlay } from '../../../claude/tasks-overlay-scraper.js';
|
|
12
|
+
import { scrapeTasksOverlay, parseTaskRows, parseTaskDetail, } from '../../../claude/tasks-overlay-scraper.js';
|
|
13
13
|
import { bringCardDown, hasRunningTasks } from '../../../telegram/background-activity-card.js';
|
|
14
14
|
import { getDirectChildren, describeProcess, isDescendantOf, killTree, } from '../../../utils/proc-children.js';
|
|
15
15
|
import { getSessionKeyFromCtx } from '../../../utils/session-key.js';
|
|
@@ -60,16 +60,16 @@ function formatDuration(ms) {
|
|
|
60
60
|
return `${minutes}m ${seconds % 60}s`;
|
|
61
61
|
}
|
|
62
62
|
function formatTaskElapsed(task) {
|
|
63
|
-
return formatDuration(
|
|
63
|
+
return formatDuration(Date.now() - task.startedAt);
|
|
64
64
|
}
|
|
65
65
|
function formatTaskSilence(task) {
|
|
66
66
|
return formatDuration(Date.now() - task.lastActivityAt);
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
69
|
-
* How long a task may go
|
|
70
|
-
* probably-finished.
|
|
71
|
-
* so an entry still listed after a long silence usually means that
|
|
72
|
-
* never arrived (restart mid-task, dropped notification).
|
|
69
|
+
* How long a task may go unheard from before /tasks flags it as
|
|
70
|
+
* probably-finished. The notification that ends a task removes the entry
|
|
71
|
+
* outright, so an entry still listed after a long silence usually means that
|
|
72
|
+
* notification never arrived (restart mid-task, dropped notification).
|
|
73
73
|
*
|
|
74
74
|
* Deliberately generous: this only annotates, never hides, but a false
|
|
75
75
|
* positive on a slow-but-live agent is still noise.
|
|
@@ -85,13 +85,10 @@ function isPossiblyStale(task) {
|
|
|
85
85
|
return false;
|
|
86
86
|
return Date.now() - task.lastActivityAt > STALE_AFTER_MS;
|
|
87
87
|
}
|
|
88
|
-
function getActiveTasks(sessionKey) {
|
|
89
|
-
return taskTracker.getTasks(sessionKey).filter(t => t.status === 'running' || t.status === 'pending');
|
|
90
|
-
}
|
|
91
88
|
function renderTasksList(sessionKey, tasks) {
|
|
92
89
|
if (tasks.length === 0) {
|
|
93
|
-
// Cross-pointer: a `Bash(run_in_background=true)` shell can outlive its
|
|
94
|
-
// task entry (npm release scripts, deploys), so the
|
|
90
|
+
// Cross-pointer: a `Bash(run_in_background=true)` shell can outlive its
|
|
91
|
+
// task entry (npm release scripts, deploys), so the status line's 🔍 counter
|
|
95
92
|
// may show > 0 while /tasks is empty. Surface that here so users know
|
|
96
93
|
// where to look next.
|
|
97
94
|
const claudePid = getPtyProvider().getSessionPid(sessionKey);
|
|
@@ -150,13 +147,18 @@ function renderTasksList(sessionKey, tasks) {
|
|
|
150
147
|
{ text: '🔄 Refresh', callback_data: 'tasks:refresh' },
|
|
151
148
|
{ text: '🔎 Ask claude', callback_data: 'tasks:ask' },
|
|
152
149
|
]);
|
|
153
|
-
//
|
|
150
|
+
// The live card is where background work shows as it runs.
|
|
154
151
|
if (hasRunningTasks(sessionKey)) {
|
|
155
152
|
keyboard.push([{ text: '📍 Show live card here', callback_data: 'tasks:card' }]);
|
|
156
153
|
}
|
|
157
154
|
return { message: b.build(), keyboard };
|
|
158
155
|
}
|
|
159
|
-
|
|
156
|
+
/**
|
|
157
|
+
* `canShowOutput`: there is a live pty to ask, so the detail offers the task's
|
|
158
|
+
* output (see "📄 Output" below). Without one, the output only arrives with
|
|
159
|
+
* the task's notification, which the relay posts when it lands.
|
|
160
|
+
*/
|
|
161
|
+
function renderTaskDetail(task, canShowOutput = false) {
|
|
160
162
|
const groupHint = (() => {
|
|
161
163
|
switch (task.taskType) {
|
|
162
164
|
case 'monitor_mcp': return '📡 Monitor';
|
|
@@ -171,8 +173,6 @@ function renderTaskDetail(task) {
|
|
|
171
173
|
const b = new EntityText().add(`${groupHint}: `).bold(task.description).newline();
|
|
172
174
|
/** A `• Label: ` bullet on a line of its own; the caller appends the value. */
|
|
173
175
|
const field = (label) => b.newline().add('• ').bold(`${label}:`).add(' ');
|
|
174
|
-
field('Status').add(task.status);
|
|
175
|
-
field('Backgrounded').add(task.isBackgrounded ? 'yes' : 'no');
|
|
176
176
|
field('Started').add(`${formatTaskElapsed(task)} ago`);
|
|
177
177
|
if (isPossiblyStale(task)) {
|
|
178
178
|
field('Last update').add(`${formatTaskSilence(task)} ago ⚠️`);
|
|
@@ -180,31 +180,23 @@ function renderTaskDetail(task) {
|
|
|
180
180
|
if (task.taskType) {
|
|
181
181
|
field('Type').code(task.taskType);
|
|
182
182
|
}
|
|
183
|
-
if (task.
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
if (task.lastProgress?.summary) {
|
|
191
|
-
const summary = task.lastProgress.summary.length > 300
|
|
192
|
-
? task.lastProgress.summary.substring(0, 297) + '...'
|
|
193
|
-
: task.lastProgress.summary;
|
|
194
|
-
b.newline(2).bold('Latest progress:').newline().quote(summary);
|
|
195
|
-
}
|
|
196
|
-
if (task.error) {
|
|
197
|
-
b.newline(2).add(`⚠️ ${task.error}`);
|
|
198
|
-
}
|
|
199
|
-
return {
|
|
200
|
-
message: b.build(),
|
|
201
|
-
keyboard: [
|
|
202
|
-
[
|
|
203
|
-
{ text: '← Back to list', callback_data: 'tasks:back' },
|
|
204
|
-
{ text: '🔄 Refresh', callback_data: `tasks:view:${task.id}` },
|
|
205
|
-
],
|
|
183
|
+
if (!canShowOutput && task.taskType !== 'monitor_mcp') {
|
|
184
|
+
b.newline(2).italic('Its output arrives with the result when it finishes.');
|
|
185
|
+
}
|
|
186
|
+
const keyboard = [
|
|
187
|
+
[
|
|
188
|
+
{ text: '← Back to list', callback_data: 'tasks:back' },
|
|
189
|
+
{ text: '🔄 Refresh', callback_data: `tasks:view:${task.id}` },
|
|
206
190
|
],
|
|
207
|
-
|
|
191
|
+
];
|
|
192
|
+
if (canShowOutput) {
|
|
193
|
+
keyboard.push([{ text: '📄 Output', callback_data: `tasks:out:${task.id}` }]);
|
|
194
|
+
}
|
|
195
|
+
return { message: b.build(), keyboard };
|
|
196
|
+
}
|
|
197
|
+
/** Whether this chat has a live pty whose `/tasks` overlay can be driven. */
|
|
198
|
+
function hasLivePty(sessionKey) {
|
|
199
|
+
return getPtyProvider().getSessionPid(sessionKey) !== undefined;
|
|
208
200
|
}
|
|
209
201
|
export async function handleTasks(ctx) {
|
|
210
202
|
const keyInfo = getSessionKeyFromCtx(ctx);
|
|
@@ -212,7 +204,7 @@ export async function handleTasks(ctx) {
|
|
|
212
204
|
await ctx.reply('❌ Could not determine chat context for /tasks.');
|
|
213
205
|
return;
|
|
214
206
|
}
|
|
215
|
-
const tasks =
|
|
207
|
+
const tasks = taskTracker.getTasks(keyInfo.sessionKey);
|
|
216
208
|
const { message, keyboard } = renderTasksList(keyInfo.sessionKey, tasks);
|
|
217
209
|
await replyFormatted(ctx, message, { reply_markup: { inline_keyboard: keyboard } });
|
|
218
210
|
}
|
|
@@ -225,7 +217,7 @@ export async function handleTasksCallback(ctx) {
|
|
|
225
217
|
}
|
|
226
218
|
const { sessionKey } = keyInfo;
|
|
227
219
|
if (data === 'tasks:refresh' || data === 'tasks:back') {
|
|
228
|
-
const tasks =
|
|
220
|
+
const tasks = taskTracker.getTasks(sessionKey);
|
|
229
221
|
const { message, keyboard } = renderTasksList(sessionKey, tasks);
|
|
230
222
|
await ctx.answerCallbackQuery().catch(() => { });
|
|
231
223
|
try {
|
|
@@ -250,12 +242,44 @@ export async function handleTasksCallback(ctx) {
|
|
|
250
242
|
await handleAskClaude(ctx, sessionKey);
|
|
251
243
|
return;
|
|
252
244
|
}
|
|
245
|
+
if (data === 'tasks:claude') {
|
|
246
|
+
await showClaudeView(ctx, sessionKey, { edit: true });
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
if (data.startsWith('tasks:claude:')) {
|
|
250
|
+
const row = Number.parseInt(data.substring('tasks:claude:'.length), 10);
|
|
251
|
+
if (!Number.isFinite(row) || row < 1) {
|
|
252
|
+
await ctx.answerCallbackQuery().catch(() => { });
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
await showClaudeView(ctx, sessionKey, {
|
|
256
|
+
edit: true,
|
|
257
|
+
pick: (rows) => (row <= rows.length ? row - 1 : undefined),
|
|
258
|
+
refresh: data,
|
|
259
|
+
back: 'tasks:claude',
|
|
260
|
+
});
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
if (data.startsWith('tasks:out:')) {
|
|
264
|
+
const taskId = data.substring('tasks:out:'.length);
|
|
265
|
+
const task = taskTracker.getTask(sessionKey, taskId);
|
|
266
|
+
await showClaudeView(ctx, sessionKey, {
|
|
267
|
+
edit: true,
|
|
268
|
+
pick: (rows) => (task ? matchTaskRow(task, rows) : undefined),
|
|
269
|
+
unmatchedNote: task
|
|
270
|
+
? "Couldn't tell which of these is that task — tap the one it is."
|
|
271
|
+
: undefined,
|
|
272
|
+
refresh: data,
|
|
273
|
+
back: task ? `tasks:view:${taskId}` : 'tasks:back',
|
|
274
|
+
});
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
253
277
|
if (data.startsWith('tasks:view:')) {
|
|
254
278
|
const taskId = data.substring('tasks:view:'.length);
|
|
255
279
|
const task = taskTracker.getTask(sessionKey, taskId);
|
|
256
280
|
if (!task) {
|
|
257
281
|
// Task finished or was cleared between renders — go back to the list.
|
|
258
|
-
const tasks =
|
|
282
|
+
const tasks = taskTracker.getTasks(sessionKey);
|
|
259
283
|
const { message, keyboard } = renderTasksList(sessionKey, tasks);
|
|
260
284
|
await ctx.answerCallbackQuery({ text: 'Task no longer active.' }).catch(() => { });
|
|
261
285
|
try {
|
|
@@ -264,7 +288,7 @@ export async function handleTasksCallback(ctx) {
|
|
|
264
288
|
catch { /* ignore */ }
|
|
265
289
|
return;
|
|
266
290
|
}
|
|
267
|
-
const { message, keyboard } = renderTaskDetail(task);
|
|
291
|
+
const { message, keyboard } = renderTaskDetail(task, hasLivePty(sessionKey));
|
|
268
292
|
await ctx.answerCallbackQuery().catch(() => { });
|
|
269
293
|
try {
|
|
270
294
|
await editCallbackMessage(ctx, message, { reply_markup: { inline_keyboard: keyboard } });
|
|
@@ -287,62 +311,208 @@ export async function handleTasksCallback(ctx) {
|
|
|
287
311
|
export const _isPossiblyStale = isPossiblyStale;
|
|
288
312
|
export const _renderTasksList = renderTasksList;
|
|
289
313
|
export const _renderTaskDetail = renderTaskDetail;
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
314
|
+
export const _matchTaskRow = matchTaskRow;
|
|
315
|
+
export const _renderClaudeList = renderClaudeList;
|
|
316
|
+
export const _renderClaudeDetail = renderClaudeDetail;
|
|
317
|
+
const DOWN = '\x1b[B';
|
|
318
|
+
const ENTER = '\r';
|
|
293
319
|
/**
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
*
|
|
297
|
-
* backgrounded on its own initiative, and everything armed before the last bot
|
|
298
|
-
* restart (relay state doesn't persist). This button asks it directly.
|
|
299
|
-
*
|
|
300
|
-
* PTY-only — there is no TUI to drive in SDK mode, where the tracker is fed
|
|
301
|
-
* from the event stream and is already authoritative.
|
|
320
|
+
* Open the overlay and, if `pick` names a row of the list it opens on, press
|
|
321
|
+
* ↓ that many times and Enter. The overlay opens straight on the detail when
|
|
322
|
+
* only one task runs, in which case there is nothing to pick.
|
|
302
323
|
*/
|
|
303
|
-
async function
|
|
324
|
+
async function readClaudeTasks(sessionKey, pick) {
|
|
325
|
+
const result = await getPtyProvider().runOverlayCommand(sessionKey, '/tasks', (screen) => {
|
|
326
|
+
if (!pick)
|
|
327
|
+
return undefined;
|
|
328
|
+
const overlay = scrapeTasksOverlay(screen);
|
|
329
|
+
if (!overlay)
|
|
330
|
+
return undefined;
|
|
331
|
+
const rows = parseTaskRows(overlay.text);
|
|
332
|
+
const index = rows.length > 0 ? pick(rows) : undefined;
|
|
333
|
+
if (index === undefined)
|
|
334
|
+
return undefined;
|
|
335
|
+
return [...Array(index).fill(DOWN), ENTER];
|
|
336
|
+
});
|
|
337
|
+
if (!result.ok)
|
|
338
|
+
return { kind: 'miss', reason: result.reason };
|
|
339
|
+
const overlay = scrapeTasksOverlay(result.screen);
|
|
340
|
+
if (!overlay)
|
|
341
|
+
return { kind: 'unreadable' };
|
|
342
|
+
if (overlay.empty)
|
|
343
|
+
return { kind: 'empty' };
|
|
344
|
+
const detail = parseTaskDetail(overlay.text);
|
|
345
|
+
if (detail)
|
|
346
|
+
return { kind: 'detail', detail };
|
|
347
|
+
return { kind: 'list', rows: parseTaskRows(overlay.text), text: overlay.text };
|
|
348
|
+
}
|
|
349
|
+
/** Collapse whitespace so a command wrapped by the TUI compares as typed. */
|
|
350
|
+
function squash(text) {
|
|
351
|
+
return text.replace(/\s+/g, ' ').trim();
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* The index of the one row in claude's list that is this task, or undefined
|
|
355
|
+
* when none or several are. A row shows the shell's command, or a description
|
|
356
|
+
* for other kinds, cut short with `…` when long; the task has both, so either
|
|
357
|
+
* may match. Two shells running the same command stay ambiguous on purpose:
|
|
358
|
+
* opening the wrong one's output would read as the right one's.
|
|
359
|
+
*/
|
|
360
|
+
function matchTaskRow(task, rows) {
|
|
361
|
+
const candidates = [task.command, task.description]
|
|
362
|
+
.filter((c) => typeof c === 'string' && c.trim().length > 0)
|
|
363
|
+
.map(squash);
|
|
364
|
+
const hits = [];
|
|
365
|
+
rows.forEach((row, i) => {
|
|
366
|
+
const label = squash(row.label);
|
|
367
|
+
if (!label)
|
|
368
|
+
return;
|
|
369
|
+
const hit = candidates.some((c) => (row.truncated ? c.startsWith(label) : c === label));
|
|
370
|
+
if (hit)
|
|
371
|
+
hits.push(i);
|
|
372
|
+
});
|
|
373
|
+
return hits.length === 1 ? hits[0] : undefined;
|
|
374
|
+
}
|
|
375
|
+
function explainOverlayMiss(reason) {
|
|
376
|
+
switch (reason) {
|
|
377
|
+
case 'turn-active':
|
|
378
|
+
return 'Claude is mid-turn — the TUI keyboard is busy. Try again once it finishes.';
|
|
379
|
+
case 'not-ready':
|
|
380
|
+
return 'The Claude TUI is not at a prompt right now. Try again in a moment.';
|
|
381
|
+
case 'no-session':
|
|
382
|
+
return 'No live Claude session for this chat.';
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
/** Every answer below opens with the same heading. */
|
|
386
|
+
function claudeHeading() {
|
|
387
|
+
return new EntityText().add('🔎 ').bold("Claude's background view").newline(2);
|
|
388
|
+
}
|
|
389
|
+
function renderClaudeList(view, nav, note) {
|
|
390
|
+
const b = claudeHeading();
|
|
391
|
+
if (note)
|
|
392
|
+
b.italic(note).newline(2);
|
|
393
|
+
const body = view.text.length > 3000 ? view.text.slice(0, 2997) + '...' : view.text;
|
|
394
|
+
b.pre(body);
|
|
395
|
+
const keyboard = [];
|
|
396
|
+
if (view.rows.length > 0) {
|
|
397
|
+
b.newline().italic('Tap a row number to see its output.');
|
|
398
|
+
let row = [];
|
|
399
|
+
view.rows.forEach((_, i) => {
|
|
400
|
+
row.push({ text: String(i + 1), callback_data: `tasks:claude:${i + 1}` });
|
|
401
|
+
if (row.length === 5 || i === view.rows.length - 1) {
|
|
402
|
+
keyboard.push(row);
|
|
403
|
+
row = [];
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
const last = [{ text: '🔄 Refresh', callback_data: nav.refresh }];
|
|
408
|
+
if (nav.back)
|
|
409
|
+
last.unshift({ text: '← Back', callback_data: nav.back });
|
|
410
|
+
keyboard.push(last);
|
|
411
|
+
return { message: b.build(), keyboard };
|
|
412
|
+
}
|
|
413
|
+
/** The output pane is the point; keep its tail when the whole won't fit. */
|
|
414
|
+
const OUTPUT_MAX_CHARS = 3000;
|
|
415
|
+
function renderClaudeDetail(detail, nav) {
|
|
416
|
+
const b = claudeHeading().bold(detail.title);
|
|
417
|
+
for (const f of detail.fields) {
|
|
418
|
+
b.newline().add('• ').bold(`${f.label}:`).add(' ');
|
|
419
|
+
if (f.label === 'Command')
|
|
420
|
+
b.code(f.value);
|
|
421
|
+
else
|
|
422
|
+
b.add(f.value);
|
|
423
|
+
}
|
|
424
|
+
b.newline(2).bold('Output:').newline();
|
|
425
|
+
if (detail.output === null) {
|
|
426
|
+
b.italic('No output yet.');
|
|
427
|
+
}
|
|
428
|
+
else {
|
|
429
|
+
const out = detail.output.length > OUTPUT_MAX_CHARS
|
|
430
|
+
? '…' + detail.output.slice(-(OUTPUT_MAX_CHARS - 1))
|
|
431
|
+
: detail.output;
|
|
432
|
+
b.pre(out);
|
|
433
|
+
if (detail.note)
|
|
434
|
+
b.newline().italic(detail.note);
|
|
435
|
+
}
|
|
436
|
+
const last = [{ text: '🔄 Refresh', callback_data: nav.refresh }];
|
|
437
|
+
if (nav.back)
|
|
438
|
+
last.unshift({ text: '← Back', callback_data: nav.back });
|
|
439
|
+
return { message: b.build(), keyboard: [last] };
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Read claude's overlay and show what it says — the list with row buttons, a
|
|
443
|
+
* task's detail with its output, or why it couldn't be read. One function so
|
|
444
|
+
* that every entry point (the button under the tracker list, a row number,
|
|
445
|
+
* 📄 Output on a tracked task) renders the same way.
|
|
446
|
+
*/
|
|
447
|
+
async function showClaudeView(ctx, sessionKey, opts) {
|
|
304
448
|
await ctx.answerCallbackQuery({ text: 'Asking claude…' }).catch(() => { });
|
|
305
|
-
|
|
306
|
-
const view =
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
449
|
+
const nav = { refresh: opts.refresh ?? 'tasks:claude', back: opts.back };
|
|
450
|
+
const view = await readClaudeTasks(sessionKey, opts.pick);
|
|
451
|
+
let rendered;
|
|
452
|
+
switch (view.kind) {
|
|
453
|
+
case 'detail':
|
|
454
|
+
rendered = renderClaudeDetail(view.detail, nav);
|
|
455
|
+
break;
|
|
456
|
+
case 'list':
|
|
457
|
+
rendered = renderClaudeList(view, nav, opts.pick ? opts.unmatchedNote : undefined);
|
|
458
|
+
break;
|
|
459
|
+
case 'empty': {
|
|
460
|
+
// A code block for one line of "nothing running" is noise. Worth saying
|
|
461
|
+
// out loud though: claude reporting empty while the tracker shows tasks
|
|
462
|
+
// means it is holding entries claude no longer knows about.
|
|
463
|
+
const tracked = taskTracker.getTasks(sessionKey).length;
|
|
464
|
+
const b = claudeHeading().add('Nothing running.');
|
|
465
|
+
if (tracked > 0) {
|
|
466
|
+
b.newline(2).italic(`The ${tracked} tracked task(s) are unknown to claude — likely finished already.`);
|
|
467
|
+
}
|
|
468
|
+
rendered = { message: b.build(), keyboard: [[{ text: '🔄 Refresh', callback_data: nav.refresh }]] };
|
|
469
|
+
break;
|
|
470
|
+
}
|
|
471
|
+
case 'unreadable':
|
|
472
|
+
// The overlay's layout is a Claude Code implementation detail and can
|
|
473
|
+
// move between releases — say so plainly rather than showing a mangled
|
|
474
|
+
// guess.
|
|
475
|
+
rendered = {
|
|
476
|
+
message: claudeHeading()
|
|
477
|
+
.add("Couldn't read the ")
|
|
478
|
+
.code('/tasks')
|
|
479
|
+
.add(' overlay — Claude Code may have changed its layout. The tracked list still works.')
|
|
480
|
+
.build(),
|
|
481
|
+
keyboard: [[{ text: '🔄 Refresh', callback_data: nav.refresh }]],
|
|
482
|
+
};
|
|
483
|
+
break;
|
|
484
|
+
case 'miss':
|
|
485
|
+
rendered = {
|
|
486
|
+
message: claudeHeading().add(explainOverlayMiss(view.reason)).build(),
|
|
487
|
+
keyboard: [[{ text: '🔄 Refresh', callback_data: nav.refresh }]],
|
|
488
|
+
};
|
|
489
|
+
break;
|
|
316
490
|
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
.code('/tasks')
|
|
324
|
-
.add(' overlay — Claude Code may have changed its layout. The list above still works.')
|
|
325
|
-
.build());
|
|
491
|
+
if (nav.back && view.kind !== 'detail' && view.kind !== 'list') {
|
|
492
|
+
rendered.keyboard[0].unshift({ text: '← Back', callback_data: nav.back });
|
|
493
|
+
}
|
|
494
|
+
const markup = { reply_markup: { inline_keyboard: rendered.keyboard } };
|
|
495
|
+
if (!opts.edit) {
|
|
496
|
+
await replyFormatted(ctx, rendered.message, markup);
|
|
326
497
|
return;
|
|
327
498
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
const
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
b.newline(2).italic(`The ${tracked} task(s) listed above are unknown to claude — likely finished already.`);
|
|
499
|
+
try {
|
|
500
|
+
await editCallbackMessage(ctx, rendered.message, markup);
|
|
501
|
+
}
|
|
502
|
+
catch (err) {
|
|
503
|
+
const msg = err instanceof Error ? err.message.toLowerCase() : '';
|
|
504
|
+
if (!msg.includes('message is not modified')) {
|
|
505
|
+
console.error("[Tasks] Failed to render claude's view:", err);
|
|
336
506
|
}
|
|
337
|
-
await replyFormatted(ctx, b.build());
|
|
338
|
-
return;
|
|
339
507
|
}
|
|
340
|
-
|
|
341
|
-
|
|
508
|
+
}
|
|
509
|
+
/** The button under the tracker's list: claude's view as a message of its own. */
|
|
510
|
+
async function handleAskClaude(ctx, sessionKey) {
|
|
511
|
+
await showClaudeView(ctx, sessionKey, { edit: false });
|
|
342
512
|
}
|
|
343
513
|
// ── /shells ─────────────────────────────────────────────────────
|
|
344
514
|
// List OS-level child processes of the chat's PTY claude session and offer
|
|
345
|
-
// a one-tap SIGTERM. Complements /tasks (which only sees
|
|
515
|
+
// a one-tap SIGTERM. Complements /tasks (which only sees tracked tasks)
|
|
346
516
|
// and rescues `Bash(run_in_background=true)` shells whose stop condition
|
|
347
517
|
// will never fire.
|
|
348
518
|
const BG_MCP_SERVER_MARKER = 'mcp-server.js';
|
|
@@ -396,21 +566,19 @@ function renderBgList(sessionKey, claudePid, procs) {
|
|
|
396
566
|
return {
|
|
397
567
|
message: heading()
|
|
398
568
|
.newline(2)
|
|
399
|
-
.italic('No
|
|
400
|
-
.newline(2)
|
|
401
|
-
.add('In SDK mode, use /tasks to inspect tracked background tasks.')
|
|
569
|
+
.italic('No live Claude session for this chat.')
|
|
402
570
|
.build(),
|
|
403
571
|
keyboard: [],
|
|
404
572
|
};
|
|
405
573
|
}
|
|
406
574
|
if (procs.length === 0) {
|
|
407
|
-
// Cross-pointer to /tasks when
|
|
575
|
+
// Cross-pointer to /tasks when tracked tasks (agents, monitors) are
|
|
408
576
|
// running but no OS shells are.
|
|
409
|
-
const taskCount =
|
|
577
|
+
const taskCount = taskTracker.getTasks(sessionKey).length;
|
|
410
578
|
const b = heading().newline(2).add('None running.');
|
|
411
579
|
if (taskCount > 0) {
|
|
412
580
|
const noun = taskCount === 1 ? 'task' : 'tasks';
|
|
413
|
-
b.newline(2).italic(`🔄 ${taskCount}
|
|
581
|
+
b.newline(2).italic(`🔄 ${taskCount} ${noun} still running — see /tasks.`);
|
|
414
582
|
}
|
|
415
583
|
return {
|
|
416
584
|
message: b.build(),
|